websoft9/install/update.sh

278 lines
11 KiB
Bash
Raw Normal View History

2023-05-25 07:04:45 +00:00
#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
function error_exit {
echo "$1" 1>&2
exit 1
}
2023-07-27 07:03:59 +00:00
trap 'error_exit "Please push issue to: https://github.com/Websoft9/websoft9/issues"' ERR
2023-05-25 07:04:45 +00:00
2023-08-01 03:17:58 +00:00
urls="https://w9artifact.blob.core.windows.net/release/websoft9"
2023-06-21 01:07:40 +00:00
2023-07-27 07:03:59 +00:00
CheckEnv(){
2023-06-20 06:17:05 +00:00
echo "------------------ Welcome to update websoft9's appstore, it will take 1-3 minutes -----------------"
2023-06-03 05:02:32 +00:00
2023-05-25 07:04:45 +00:00
if [ $(id -u) != "0" ]; then
echo "Please change to root or 'sudo su' to up system privileges, and reinstall the script again ."
exit 1
fi
2023-05-26 03:09:04 +00:00
}
2023-05-25 07:04:45 +00:00
UpdateDocker(){
2023-05-26 03:09:04 +00:00
echo "Parpare to update Docker to latest ..."
2023-05-25 07:04:45 +00:00
2023-05-29 09:45:30 +00:00
if command -v apt > /dev/null;then
sudo apt -y install --only-upgrade docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
2023-06-01 08:43:22 +00:00
elif command -v dnf > /dev/null;then
sudo dnf update -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
2023-05-29 09:45:30 +00:00
elif command -v yum > /dev/null;then
sudo yum update -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
2023-05-25 07:04:45 +00:00
fi
}
2023-07-27 07:03:59 +00:00
UpdateWebsoft9(){
2023-05-25 07:04:45 +00:00
2023-07-27 07:03:59 +00:00
echo "Update websoft9 ..."
2023-05-25 07:04:45 +00:00
2023-07-27 07:03:59 +00:00
if [ ! -f /data/apps/websoft9/version.json ]; then
old_version="0.0.0"
else
old_version=$(cat /data/apps/websoft9/version.json | jq .VERSION | tr -d '"')
fi
release_version=$(curl $urls/version.json | jq .VERSION | tr -d '"')
if [ "$old_version" \< "$release_version" ]; then
echo "start to update websoft9..."
cd /data/apps && rm -rf websoft9
wget $urls/websoft9-latest.zip
unzip websoft9-latest.zip
rm -rf websoft9-latest.zip
else
echo "websoft9 is not need to update"
2023-05-25 07:04:45 +00:00
fi
2023-06-20 06:17:05 +00:00
2023-06-01 08:43:22 +00:00
}
2023-05-25 07:04:45 +00:00
2023-06-01 08:43:22 +00:00
UpdatePlugins(){
2023-05-25 07:04:45 +00:00
2023-06-01 08:43:22 +00:00
echo "Check plugins if have update ..."
# update appstore
2023-08-01 03:12:34 +00:00
if [ -f "/usr/share/cockpit/appstore/appstore.json" ]; then
old_appstore_version=$(cat /usr/share/cockpit/appstore/appstore.json | jq .Version | tr -d '"')
else
old_appstore_version="0.0.0"
fi
2023-07-27 07:03:59 +00:00
new_appstore_version=$(cat /data/apps/websoft9/version.json | jq .PLUGINS |jq .APPSTORE | tr -d '"')
2023-06-01 08:43:22 +00:00
2023-06-20 03:58:43 +00:00
# update settings
2023-08-01 03:12:34 +00:00
if [ -f "/usr/share/cockpit/settings/settings.json" ]; then
old_settings_version=$(cat /usr/share/cockpit/settings/settings.json | jq .Version | tr -d '"')
else
old_settings_version="0.0.0"
fi
2023-07-31 02:22:40 +00:00
new_settings_version=$(cat /data/apps/websoft9/version.json | jq .PLUGINS |jq .SETTINGS | tr -d '"')
2023-06-20 03:58:43 +00:00
2023-06-02 10:11:43 +00:00
# update myapps
2023-08-01 03:12:34 +00:00
if [ -f "/usr/share/cockpit/myapps/myapps.json" ]; then
old_myapps_version=$(cat /usr/share/cockpit/myapps/myapps.json | jq .Version | tr -d '"')
else
old_myapps_version="0.0.0"
fi
2023-07-27 07:03:59 +00:00
new_myapps_version=$(cat /data/apps/websoft9/version.json | jq .PLUGINS |jq .MYAPPS | tr -d '"')
2023-06-02 10:11:43 +00:00
2023-06-01 08:43:22 +00:00
## update container
2023-08-01 03:12:34 +00:00
if [ -f "/usr/share/cockpit/container/portainer.json" ]; then
old_container_version=$(cat /usr/share/cockpit/container/portainer.json | jq .Version | tr -d '"')
else
old_container_version="0.0.0"
fi
2023-07-27 07:03:59 +00:00
new_container_version=$(cat /data/apps/websoft9/version.json | jq .PLUGINS |jq .PORTAINER | tr -d '"')
2023-05-25 07:04:45 +00:00
2023-06-01 08:43:22 +00:00
## update nginx
2023-08-01 03:12:34 +00:00
if [ -f "/usr/share/cockpit/nginx/nginx.json" ]; then
old_nginx_version=$(cat /usr/share/cockpit/nginx/nginx.json | jq .Version | tr -d '"')
else
old_nginx_version="0.0.0"
fi
2023-07-27 07:03:59 +00:00
new_nginx_version=$(cat /data/apps/websoft9/version.json | jq .PLUGINS |jq .NGINX | tr -d '"')
## update library
2023-08-01 03:12:34 +00:00
if [ -f "/data/library/library.json" ]; then
old_library_version=$(cat /data/library/library.json | jq .Version | tr -d '"')
else
old_library_version="0.0.0"
fi
2023-07-27 07:03:59 +00:00
new_library_version=$(cat /data/apps/websoft9/version.json | jq .PLUGINS |jq .LIBRARY | tr -d '"')
2023-05-25 07:04:45 +00:00
2023-06-21 08:22:53 +00:00
if [ "$old_appstore_version" = "$new_appstore_version" ] && [ "$old_settings_version" = "$new_settings_version" ] && [ "$old_myapps_version" = "$new_myapp_version" ] && [ "$old_container_version" = "$new_container_version" ] && [ "$old_nginx_version" \< "$new_nginx_version" ]; then
echo "appstore all plugins is latest"
2023-06-01 08:43:22 +00:00
else
2023-05-25 07:04:45 +00:00
2023-07-27 07:03:59 +00:00
if [ "$old_appstore_version" \< "$new_appstore_version" ]; then
2023-06-21 08:22:53 +00:00
echo "appstore plugin need to update"
2023-07-27 07:03:59 +00:00
cd /usr/share/cockpit
wget $urls/plugin/appstore/appstore-$new_appstore_version.zip
rm -rf appstore
unzip appstore-$new_appstore_version.zip
rm -f appstore-$new_appstore_version.zip
2023-06-21 08:22:53 +00:00
else
echo "appstore is not need to update"
fi
2023-07-29 07:21:46 +00:00
if [ "$old_settings_version" \< "$new_settings_version" ]; then
echo "settings plugin need to update"
cd /usr/share/cockpit
wget $urls/plugin/settings/settings-$new_settings_version.zip
rm -rf settings
unzip settings-$new_appstore_version.zip
rm -f settings-$new_appstore_version.zip
else
echo "settings is not need to update"
fi
2023-07-27 07:03:59 +00:00
if [ "$old_myapps_version" \< "$new_myapps_version" ]; then
2023-06-21 08:22:53 +00:00
echo "start to update myapps..."
2023-07-27 07:03:59 +00:00
cd /usr/share/cockpit
wget $urls/plugin/myapps/myapps-$new_myapps_version.zip
rm -rf myapps
unzip myapps-$new_myapps_version.zip
rm -f myapps-$new_myapps_version.zip
2023-06-21 08:22:53 +00:00
else
echo "myapps is not need to update"
fi
if [ "$old_container_version" \< "$new_container_version" ]; then
echo "start to update portainer..."
2023-07-27 07:03:59 +00:00
cd /usr/share/cockpit
wget $urls/plugin/portainer/portainer-$new_container_version.zip
rm -rf portainer
unzip portainer-$new_container_version.zip
rm -f portainer-$new_container_version.zip
2023-06-21 08:22:53 +00:00
else
echo "portainer is not need to update"
fi
if [ "$old_nginx_version" \< "$new_nginx_version" ]; then
echo "start to update nginx..."
2023-07-27 07:03:59 +00:00
cd /usr/share/cockpit
wget $urls/plugin/nginx/nginx-$new_nginx_version.zip
rm -rf nginx
unzip nginx-$new_nginx_version.zip
rm -f nginx-$new_nginx_version.zip
2023-06-21 08:22:53 +00:00
else
echo "nginx is not need to update"
fi
2023-07-27 07:03:59 +00:00
if [ "$old_library_version" \< "$new_library_version" ]; then
echo "start to update library..."
cd /data
wget $urls/plugin/library/library-$new_library_version.zip
rm -rf library
unzip library-$new_library_version.zip
rm -f library-$new_library_version.zip
else
echo "library is not need to update"
fi
2023-06-21 08:22:53 +00:00
fi
2023-05-26 03:09:04 +00:00
2023-06-03 06:47:43 +00:00
}
2023-05-25 07:04:45 +00:00
2023-05-26 03:09:04 +00:00
UpdateServices(){
echo "Check services if have update ..."
2023-06-03 06:24:52 +00:00
old_appmanage=$(cat /data/apps/w9services/w9appmanage/.env |grep APP_VERSION |cut -d= -f2)
2023-07-27 07:03:59 +00:00
new_appmanage=$(cat /data/apps/websoft9/docker/w9appmanage/.env |grep APP_VERSION |cut -d= -f2)
2023-06-01 09:02:25 +00:00
if [ "$old_appmanage" \< "$new_appmanage" ]; then
2023-06-03 07:22:46 +00:00
echo "start to update w9appmanage..."
2023-07-29 07:13:17 +00:00
rm -rf /tmp/database.sqlite && sudo docker cp websoft9-appmanage:/usr/src/app/database.sqlite /tmp
2023-07-29 07:56:07 +00:00
rm -f /data/apps/w9services/w9appmanage/.env && cp /data/apps/websoft9/docker/w9appmanage/.env /data/apps/w9services/w9appmanage/.env
rm -f /data/apps/w9services/w9appmanage/docker-compose.yml && cp /data/apps/websoft9/docker/w9appmanage/docker-compose.yml /data/apps/w9services/w9appmanage/docker-compose.yml
2023-06-03 06:24:52 +00:00
cd /data/apps/w9services/w9appmanage && sudo docker compose down && sudo docker compose pull && sudo docker compose up -d
2023-07-29 07:13:17 +00:00
sudo docker exec -it websoft9-appmanage rm -f /usr/src/app/database.sqlite && sudo docker cp /tmp/database.sqlite websoft9-appmanage:/usr/src/app
docker restart websoft9-appmanage
2023-06-01 09:02:25 +00:00
else
echo "appmanage is not need to update"
fi
2023-06-03 06:24:52 +00:00
old_redis=$(cat /data/apps/w9services/w9redis/.env |grep APP_VERSION |cut -d= -f2)
2023-07-27 07:03:59 +00:00
new_redis=$(cat /data/apps/websoft9/docker/w9redis/.env |grep APP_VERSION |cut -d= -f2)
2023-06-01 09:02:25 +00:00
if [ "$old_redis" \< "$new_redis" ]; then
2023-06-03 07:22:46 +00:00
echo "start to update w9redis..."
2023-07-29 07:56:07 +00:00
rm -f /data/apps/w9services/w9redis/.env && cp /data/apps/websoft9/docker/w9redis/.env /data/apps/w9services/w9redis/.env
rm -f /data/apps/w9services/w9redis/docker-compose.yml && cp /data/apps/websoft9/docker/w9redis/docker-compose.yml /data/apps/w9services/w9redis/docker-compose.yml
2023-06-03 06:24:52 +00:00
cd /data/apps/w9services/w9redis && sudo docker compose down && sudo docker compose pull && sudo docker compose up -d
2023-06-01 09:02:25 +00:00
else
echo "redis is not need to update"
fi
2023-06-03 06:24:52 +00:00
old_portainer=$(cat /data/apps/w9services/w9portainer/.env |grep APP_VERSION |cut -d= -f2)
2023-07-27 07:03:59 +00:00
new_portainer=$(cat /data/apps/websoft9/docker/w9portainer/.env |grep APP_VERSION |cut -d= -f2)
2023-06-01 08:43:22 +00:00
if [ "$old_portainer" \< "$new_portainer" ]; then
2023-06-03 07:22:46 +00:00
echo "start to update w9portainer..."
2023-07-29 07:56:07 +00:00
rm -f /data/apps/w9services/w9portainer/.env && cp /data/apps/websoft9/docker/w9portainer/.env /data/apps/w9services/w9portainer/.env
rm -f /data/apps/w9services/w9portainer/docker-compose.yml && cp /data/apps/websoft9/docker/w9portainer/docker-compose.yml /data/apps/w9services/w9portainer/docker-compose.yml
2023-06-03 06:24:52 +00:00
cd /data/apps/w9services/w9portainer && sudo docker compose down && sudo docker compose pull && sudo docker compose up -d
2023-06-01 08:43:22 +00:00
else
echo "w9portainer is not need to update"
fi
2023-06-01 09:02:25 +00:00
2023-06-03 06:24:52 +00:00
old_nginx=$(cat /data/apps/w9services/w9nginxproxymanager/.env |grep APP_VERSION |cut -d= -f2)
2023-07-27 07:03:59 +00:00
new_nginx=$(cat /data/apps/websoft9/docker/w9nginxproxymanager/.env |grep APP_VERSION |cut -d= -f2)
2023-06-01 09:02:25 +00:00
if [ "$old_nginx" \< "$new_nginx" ]; then
2023-06-03 07:22:46 +00:00
echo "start to update w9nginx..."
2023-07-29 07:56:07 +00:00
rm -f /data/apps/w9services/w9nginxproxymanager/.env && cp /data/apps/websoft9/docker/w9nginxproxymanager/.env /data/apps/w9services/w9nginxproxymanager/.env
rm -f /data/apps/w9services/w9nginxproxymanager/docker-compose.yml && cp /data/apps/websoft9/docker/w9nginxproxymanager/docker-compose.yml /data/apps/w9services/w9nginxproxymanager/docker-compose.yml
2023-06-03 06:24:52 +00:00
cd /data/apps/w9services/w9nginxproxymanager && sudo docker compose down && sudo docker compose pull && sudo docker compose up -d
2023-06-01 09:02:25 +00:00
else
echo "w9nginx is not need to update"
fi
2023-05-25 07:04:45 +00:00
}
2023-07-29 07:56:07 +00:00
EditMenu(){
echo "Start to Edit Cockpit Menu ..."
# uninstall plugins
rm -rf /usr/share/cockpit/apps /usr/share/cockpit/selinux /usr/share/cockpit/kdump /usr/share/cockpit/sosreport /usr/share/cockpit/packagekit
cp -r /data/apps/websoft9/cockpit/menu_override/* /etc/cockpit
2023-07-29 07:56:07 +00:00
}
2023-07-27 07:03:59 +00:00
UpdateCockpit(){
echo "Parpare to update Cockpit to latest ..."
2023-07-31 09:55:17 +00:00
if command -v apt > /dev/null;then
current_version=$(dpkg-query --showformat='${Version}' --show cockpit)
available_version=$(apt-cache policy cockpit | grep Candidate | awk '{print $2}')
elif command -v yum > /dev/null;then
current_version=$(rpm -q --queryformat '%{VERSION}' cockpit)
available_version=$(yum list available cockpit --quiet | grep cockpit | awk '{print $2}')
fi
if [[ $(echo -e "$current_version\n$available_version" | awk -F. '{ for(i=1; i<=NF; i++) { if($i != v2[i]) { if($i < v2[i]) exit 0; else exit 1; } } exit 0; }') == 0 ]]; then
echo "There is newer version on cockpit."
pkcon refresh
pkcon get-updates
pkcon update -y 'cockpit' 'cockpit-bridge' 'cockpit-packagekit' 'cockpit-storaged' 'cockpit-system' 'cockpit-ws'
EditMenu
sudo sed -i 's/ListenStream=9090/ListenStream=9000/' /lib/systemd/system/cockpit.socket
sudo systemctl daemon-reload
sudo systemctl restart cockpit.socket
echo "cockpit update finished."
2023-07-31 09:55:17 +00:00
else
echo "cockpit is latest, not need to upadate."
2023-07-31 09:55:17 +00:00
fi
2023-07-27 07:03:59 +00:00
}
CheckEnv
2023-05-25 07:04:45 +00:00
UpdateDocker
2023-07-27 07:03:59 +00:00
UpdateWebsoft9
2023-05-26 03:09:04 +00:00
UpdatePlugins
UpdateServices
2023-06-20 04:15:23 +00:00
UpdateCockpit