websoft9/scripts/update-bk.sh

323 lines
12 KiB
Bash
Raw Permalink 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
2024-09-05 01:04:28 +00:00
urls="https://artifact.websoft9.com/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
2023-08-03 02:06:35 +00:00
compare_versions() {
local old_version="$1"
local new_version="$2"
IFS='.' read -ra old_parts <<< "$old_version"
IFS='.' read -ra new_parts <<< "$new_version"
for i in "${!old_parts[@]}"; do
if [[ ${old_parts[i]} -lt ${new_parts[i]} ]]; then
return 0
elif [[ ${old_parts[i]} -gt ${new_parts[i]} ]]; then
return 1
fi
done
return 1
}
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 '"')
2023-08-03 02:06:35 +00:00
compare_versions $old_version $release_version
if [[ $? -eq 0 ]]; 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"
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 '"')
2023-08-10 08:51:07 +00:00
## update navigator
if [ -f "/usr/share/cockpit/navigator/navigator.json" ]; then
old_navigator_version=$(cat /usr/share/cockpit/navigator/navigator.json | jq .Version | tr -d '"')
else
old_navigator_version="0.0.0"
fi
new_navigator_version=$(cat /data/apps/websoft9/version.json | jq .PLUGINS |jq .NAVIGATOR | tr -d '"')
2023-07-27 07:03:59 +00:00
## 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-08-03 02:06:35 +00:00
compare_versions $old_appstore_version $new_appstore_version
if [[ $? -eq 0 ]]; 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-08-10 08:51:07 +00:00
compare_versions $old_navigator_version $new_navigator_version
if [[ $? -eq 0 ]]; then
echo "navigator plugin need to update"
cd /usr/share/cockpit
wget $urls/plugin/navigator/navigator-$new_navigator_version.zip
rm -rf navigator
unzip navigator-$navigator_version.zip
rm -f navigator-$navigator_version.zip
else
echo "navigator is not need to update"
fi
2023-08-03 02:06:35 +00:00
compare_versions $old_settings_version $new_settings_version
if [[ $? -eq 0 ]]; then
2023-07-29 07:21:46 +00:00
echo "settings plugin need to update"
cd /usr/share/cockpit
wget $urls/plugin/settings/settings-$new_settings_version.zip
rm -rf settings
2023-08-01 03:58:39 +00:00
unzip settings-$new_settings_version.zip
rm -f settings-$new_settings_version.zip
2023-07-29 07:21:46 +00:00
else
echo "settings is not need to update"
fi
2023-07-27 07:03:59 +00:00
2023-08-03 02:06:35 +00:00
compare_versions $old_myapps_version $new_myapps_version
if [[ $? -eq 0 ]]; 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
2023-08-03 02:06:35 +00:00
compare_versions $old_container_version $new_container_version
if [[ $? -eq 0 ]]; then
2023-06-21 08:22:53 +00:00
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
2023-08-23 02:30:01 +00:00
rm -rf container
2023-07-27 07:03:59 +00:00
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
2023-08-03 02:06:35 +00:00
compare_versions $old_nginx_version $new_nginx_version
if [[ $? -eq 0 ]]; then
2023-06-21 08:22:53 +00:00
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
2023-08-03 02:06:35 +00:00
compare_versions $old_library_version $new_library_version
if [[ $? -eq 0 ]]; then
2023-07-27 07:03:59 +00:00
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-08-03 02:06:35 +00:00
compare_versions $old_appmanage $new_appmanage
if [[ $? -eq 0 ]]; then
2023-06-03 07:22:46 +00:00
echo "start to update w9appmanage..."
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-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-08-03 02:06:35 +00:00
compare_versions $old_redis $new_redis
if [[ $? -eq 0 ]]; 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-08-03 02:06:35 +00:00
compare_versions $old_portainer $new_portainer
if [[ $? -eq 0 ]]; 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-08-03 02:06:35 +00:00
compare_versions $old_nginx $new_nginx
if [[ $? -eq 0 ]]; 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
2023-08-01 09:26:39 +00:00
current_version=$(dpkg-query --showformat='${Version}' --show cockpit | cut -c 1-3)
available_version=$(apt-cache policy cockpit | grep Candidate | awk '{print $2}' | cut -c 1-3)
elif command -v yum > /dev/null;then
2023-08-01 09:26:39 +00:00
current_version=$(rpm -q --queryformat '%{VERSION}' cockpit | cut -c 1-3)
available_version=$(yum list available cockpit --showduplicates | awk '/cockpit/ {print $2}' | sort -V | tail -n 1 | cut -c 1-3)
fi
2023-08-01 09:26:39 +00:00
if [ "$current_version" \< "$available_version" ]; 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