Update app store registration and unregistration process

This commit is contained in:
Christopher
2024-01-26 16:52:27 -06:00
parent 36324b9f4e
commit 2358f215df

View File

@@ -1,54 +1,47 @@
#!/bin/bash
# Register the new app store
echo "Registering the new app store..."
casaos-cli app-management register app-store https://github.com/IceWhaleTech/CasaOS-AppStore/archive/19b9149ce0bd50ffb8c898e283dc441605a3a369.zip
# URLs for the app stores
NEW_APP_STORE_URL="https://github.com/IceWhaleTech/CasaOS-AppStore/archive/19b9149ce0bd50ffb8c898e283dc441605a3a369.zip"
MAIN_APP_STORE_URL="https://github.com/IceWhaleTech/CasaOS-AppStore/archive/refs/heads/main.zip"
# Initial delay for the registration process
echo "Waiting for the new app store to register..."
sleep 30
# Function to find and unregister an app store based on its URL
unregisterAppStoreByUrl() {
local storeUrl=$1
echo "Searching for the app store with URL: $storeUrl..."
# Function to find and unregister the main app store based on its URL
unregisterMainAppStore() {
echo "Searching for the main app store..."
# Get the list of app stores, search for the URL, and extract the ID
while IFS=' ' read -r id url _; do
if [[ $url == *"https://github.com/IceWhaleTech/CasaOS-AppStore/archive/refs/heads/main.zip"* ]]; then
echo "Main app store found with ID $id. Unregistering..."
if [[ $url == *"$storeUrl"* ]]; then
echo "App store found with ID $id. Unregistering..."
casaos-cli app-management unregister app-store "$id"
echo "Main app store with ID $id unregistered successfully."
echo "App store with ID $id unregistered successfully."
return
fi
done < <(casaos-cli app-management list app-stores | grep -v "ID URL" | awk '{print $1 " " $2}')
echo "Main app store not found."
echo "App store with the specified URL not found."
}
# Function to check if the new app store has been registered
checkAndUnregister() {
while true; do
# List the current app stores to check if the new one has been registered
output=$(casaos-cli app-management list app-stores)
# Check if the new app store is registered
output=$(casaos-cli app-management list app-stores)
echo "$output"
if echo "$output" | grep -q "$NEW_APP_STORE_URL"; then
echo "New app store is already registered."
read -p "Do you want to install the main app store? (y/n): " answer
if [[ $answer =~ ^[Yy]$ ]]; then
casaos-cli app-management register app-store "$MAIN_APP_STORE_URL"
echo "Main app store registered. Waiting for confirmation..."
sleep 15
unregisterAppStoreByUrl "$NEW_APP_STORE_URL"
fi
else
echo "New app store is not registered."
read -p "Do you want to install the new app store? (y/n): " answer
if [[ $answer =~ ^[Yy]$ ]]; then
casaos-cli app-management register app-store "$NEW_APP_STORE_URL"
echo "New app store registered. Unregistering the main app store..."
sleep 15
unregisterAppStoreByUrl "$MAIN_APP_STORE_URL"
fi
fi
# Check if the new app store is listed
if echo "$output" | grep -q "19b9149ce0bd50ffb8c898e283dc441605a3a369"; then
echo "New app store registered successfully."
# Unregister the old app store
echo "Unregistering the old app store..."
unregisterMainAppStore
break
else
echo "New app store not yet registered, waiting..."
sleep 15
fi
done
}
# Call the function to check and unregister the old app store
checkAndUnregister
echo "App store fix completed."
echo "Operation completed."