websoft9/install/update.sh

367 lines
13 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
}
trap 'error_exit "Please push issue to: https://github.com/Websoft9/StackHub/issues"' ERR
urls=(
https://ghproxy.com/https://github.com
2023-06-01 08:43:22 +00:00
https://github.com
https://gitee.com
2023-05-25 07:04:45 +00:00
)
function get_os_type() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
else
OS=$(uname -s)
fi
if [[ "$OS" == "CentOS Linux" ]]; then
echo "CentOS"
elif [[ "$OS" == "Oracle Linux Server" ]]; then
echo "OracleLinux"
elif [[ "$OS" == "Debian GNU/Linux" ]]; then
echo "Debian"
elif [[ "$OS" == "Ubuntu" ]]; then
echo "Ubuntu"
elif [[ "$OS" == "Fedora Linux" ]]; then
echo "Fedora"
elif [[ "$OS" =~ "Red Hat Enterprise Linux" ]]; then
echo "Redhat"
else
echo $OS
fi
}
function get_os_version() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
VERSION=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
VERSION=$(lsb_release -sr)
else
OS=$(uname -s)
VERSION=$(uname -r)
fi
if [[ "$OS" == "CentOS Linux" && "$VERSION" =~ ^7|8$ ]]; then
echo "CentOS"$VERSION
elif [[ "$OS" == "Oracle Linux Server" && "$VERSION" =~ ^7|8$ ]]; then
echo "OracleLinux"$VERSION
elif [[ "$OS" == "Debian GNU/Linux" && "$VERSION" =~ ^9|10|11$ ]]; then
echo "Debian"$VERSION
elif [[ "$OS" == "Ubuntu" && "$VERSION" =~ ^20.04|20.10|21.04|21.10|22.04$ ]]; then
echo "Ubuntu"$VERSION
elif [[ "$OS" =~ "Red Hat Enterprise Linux" && "$VERSION" =~ ^7|8$ ]]; then
echo "Redhat"$VERSION
else
echo $OS $VERSION
fi
}
os_type=$(get_os_type)
os_version=$(get_os_version)
2023-06-01 08:43:22 +00:00
function fastest_url() {
urls=("$@")
fastest_url=""
fastest_time=0
for url in "${urls[@]}"; do
2023-06-13 08:31:21 +00:00
if curl --output /dev/null --silent --head --fail --max-time 3 "$url"; then
2023-06-09 09:56:27 +00:00
data="url is available"
2023-06-09 09:44:38 +00:00
else
continue
fi
time=$(curl --connect-timeout 3 -s -w '%{time_total}\n' -o /dev/null $url)
2023-06-01 08:43:22 +00:00
if (( $(echo "$time < $fastest_time || $fastest_time == 0" | bc -l) )); then
fastest_time=$time
fastest_url=$url
fi
done
echo "$fastest_url"
}
2023-06-09 08:53:43 +00:00
LibraryUpdate(){
2023-06-15 01:40:06 +00:00
old_library_version=$(cat /data/library/install/version.json | jq .VERSION | tr -d '"')
2023-06-09 08:53:43 +00:00
latest_library_version=$(curl https://websoft9.github.io/docker-library/install/version.json | jq .VERSION | tr -d '"')
if [ "$old_library_version" \< "$latest_library_version" ]; then
echo "start to update Library..."
fastest=$(fastest_url "${urls[@]}")
2023-06-09 09:21:25 +00:00
echo "fasturl is: "$fastest
2023-06-09 08:53:43 +00:00
cd /tmp && rm -rf /tmp/library
2023-06-09 09:21:25 +00:00
if [[ $fastest == *gitee.com* ]]; then
2023-06-09 09:05:08 +00:00
echo "update from gitee"
2023-06-09 08:53:43 +00:00
wget $fastest/websoft9/docker-library/repository/archive/$latest_library_version
unzip $latest_library_version
mv docker-library* library
rm -f $latest_library_version
else
2023-06-09 09:05:08 +00:00
echo "update from github"
2023-06-09 08:53:43 +00:00
wget $fastest/websoft9/docker-library/archive/refs/tags/$latest_library_version.zip
unzip $latest_library_version.zip
mv docker-library* library
rm -f $latest_library_version.zip
fi
rm -rf /data/library && cp -r /tmp/library /data
else
echo "Library is not need to update"
fi
}
2023-05-26 07:32:11 +00:00
CheckUpdate(){
2023-06-03 05:02:32 +00:00
echo "------------------ Welcome to update websoft9's appstore, it will take 1-3 minutes -----------------"
2023-06-09 06:35:33 +00:00
echo "Update appstore library..."
2023-06-09 08:53:43 +00:00
LibraryUpdate
2023-06-01 08:43:22 +00:00
cd /tmp && rm -rf version.json && wget https://websoft9.github.io/StackHub/install/version.json
2023-06-03 05:02:32 +00:00
echo "Update stackhub ..."
2023-06-03 06:24:52 +00:00
release_version=$(cat /tmp/version.json | jq .VERSION | tr -d '"')
2023-06-03 05:02:32 +00:00
fasturl=$(fastest_url "${urls[@]}")
2023-06-03 06:56:24 +00:00
echo "fasturl is: "$fasturl
2023-06-03 05:02:32 +00:00
cd /tmp && rm -rf /tmp/stackhub
2023-06-09 09:21:25 +00:00
if [[ $fasturl == *gitee.com* ]]; then
2023-06-03 05:02:32 +00:00
wget $fasturl/websoft9/StackHub/repository/archive/$release_version
unzip $release_version
mv StackHub* stackhub
rm -f $release_version
2023-05-26 07:36:22 +00:00
else
2023-06-03 05:02:32 +00:00
wget $fasturl/websoft9/StackHub/archive/refs/tags/$release_version.zip
unzip $release_version.zip
mv StackHub* stackhub
rm -f $release_version.zip
2023-05-26 07:32:11 +00:00
fi
2023-06-03 05:02:32 +00:00
rm -rf /tmp/config.json
cp /usr/share/cockpit/myapps/config.json /tmp/config.json
rm -rf /data/apps/stackhub
cp -r /tmp/stackhub /data/apps
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
if [ $(getconf WORD_BIT) = '32' ] && [ $(getconf LONG_BIT) = '64' ] ; then
echo "64-bit operating system detected."
else
echo "This script only works on 64-bit operating systems."
exit 1
fi
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$NAME
VERSION=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
VERSION=$(lsb_release -sr)
else
OS=$(uname -s)
VERSION=$(uname -r)
fi
if [[ "$OS" == "CentOS Linux" && "$VERSION" =~ ^[0-6]$ ]]; then
echo "This script only works on CentOS 7 or later."
exit 1
elif [[ "$OS" == "Ubuntu" && "$VERSION" =~ ^1[0-9].*$ ]]; then
echo "This script only works on Ubuntu 20.04 or later."
exit 1
elif [[ "$OS" == "Debian GNU/Linux" && "$VERSION" =~ ^[1-8]$ ]]; then
echo "This script only works on Debian 9 or later."
exit 1
elif [[ "$OS" =~ "Red Hat Enterprise Linux" && "$VERSION" =~ ^[0-6]$ ]]; then
echo "This script only works on Red Hat 7 or later."
exit 1
else
echo "Your server os is supported to install this software."
fi
2023-05-26 03:09:04 +00:00
echo "Update Linux packate to latest ..."
2023-05-25 07:04:45 +00:00
2023-05-26 03:09:04 +00:00
if [ "$os_type" == 'CentOS' ] || [ "$os_type" == 'CentOS Stream' ] || [ "$os_type" == 'Fedora' ] || [ "$os_type" == 'OracleLinux' ] || [ "$os_type" == 'Redhat' ];then
sudo yum update -y 1>/dev/null 2>&1
fi
if [ "$os_type" == 'Ubuntu' ] || [ "$os_type" == 'Debian' ] ;then
while fuser /var/lib/dpkg/lock >/dev/null 2>&1 ; do
echo "Waiting for other software managers to finish..."
sleep 5
done
sudo apt update -y 1>/dev/null 2>&1
fi
}
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
}
UpdateCockpit(){
2023-05-26 03:09:04 +00:00
echo "Parpare to update Cockpit to latest ..."
2023-06-01 08:43:22 +00:00
pkcon refresh /dev/null 2>&1
pkcon get-updates >/dev/null 2>&1
pkcon update -y >/dev/null 2>&1
2023-05-25 07:04:45 +00:00
2023-06-01 08:43:22 +00:00
# update navigator
if command -v apt > /dev/null;then
sudo apt -y install --only-upgrade cockpit-navigator
elif command -v dnf > /dev/null;then
sudo dnf update -y cockpit-navigator
elif command -v yum > /dev/null;then
sudo yum update -y cockpit-navigator
2023-05-25 07:04:45 +00:00
fi
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
old_appstore_version=$(cat /usr/share/cockpit/appstore/manifest.json | jq .version)
2023-06-03 05:02:32 +00:00
new_appstore_version=$(cat /data/apps/stackhub/cockpit/appstore/build/manifest.json |jq .version)
2023-06-01 08:43:22 +00:00
if [ "$old_appstore_version" \< "$new_appstore_version" ]; then
echo "appstore plugin need to update"
2023-06-02 10:11:43 +00:00
rm -rf /usr/share/cockpit/appstore/*
cp -r /data/apps/stackhub/cockpit/appstore/build/* /usr/share/cockpit/appstore
2023-06-01 08:43:22 +00:00
else
echo "appstore is not need to update"
2023-05-25 07:04:45 +00:00
fi
2023-06-02 10:11:43 +00:00
# update myapps
old_myapps_version=$(cat /usr/share/cockpit/myapps/manifest.json | jq .version)
2023-06-03 05:02:32 +00:00
new_myapp_version=$(cat /data/apps/stackhub/cockpit/myapps/build/manifest.json |jq .version)
2023-06-02 10:11:43 +00:00
if [ "$old_myapps_version" \< "$new_myapp_version" ]; then
2023-06-03 07:22:46 +00:00
echo "start to update myapps..."
2023-06-02 10:11:43 +00:00
rm -rf /usr/share/cockpit/myapps/*
cp -r /data/apps/stackhub/cockpit/myapps/build/* /usr/share/cockpit/myapps
rm -f /usr/share/cockpit/myapps/config.json
cp /tmp/config.json /usr/share/cockpit/myapps/config.json
else
echo "myapps is not need to update"
fi
2023-06-01 08:43:22 +00:00
## update container
old_container_version=$(cat /usr/share/cockpit/container/manifest.json | jq .version)
2023-06-03 05:02:32 +00:00
new_container_version=$(cat /data/apps/stackhub/cockpit/portainer/build/manifest.json |jq .version)
2023-05-25 07:04:45 +00:00
2023-06-01 08:43:22 +00:00
if [ "$old_container_version" \< "$new_container_version" ]; then
2023-06-03 07:22:46 +00:00
echo "start to update portainer..."
2023-06-02 10:11:43 +00:00
rm -rf /usr/share/cockpit/container/*
cp -r /data/apps/stackhub/cockpit/portainer/build/* /usr/share/cockpit/container
2023-06-01 08:43:22 +00:00
else
2023-06-03 07:22:46 +00:00
echo "portainer is not need to update"
2023-05-26 03:09:04 +00:00
fi
2023-05-25 07:04:45 +00:00
2023-06-01 08:43:22 +00:00
## update nginx
old_nginx_version=$(cat /usr/share/cockpit/nginx/manifest.json | jq .version)
2023-06-03 05:02:32 +00:00
new_nginx_version=$(cat /data/apps/stackhub/cockpit/nginxproxymanager/build/manifest.json |jq .version)
2023-05-25 07:04:45 +00:00
2023-06-01 08:43:22 +00:00
if [ "$old_nginx_version" \< "$new_nginx_version" ]; then
2023-06-03 07:22:46 +00:00
echo "start to update nginx..."
2023-06-02 10:11:43 +00:00
rm -rf /usr/share/cockpit/nginx/*
cp -r /data/apps/stackhub/cockpit/nginxproxymanager/build/* /usr/share/cockpit/nginx
2023-06-01 08:43:22 +00:00
else
echo "nginx is not need to update"
2023-05-26 03:09:04 +00:00
fi
2023-05-25 07:04:45 +00:00
2023-06-01 08:43:22 +00:00
## update kopia
2023-06-03 05:02:32 +00:00
# old_kopia_version=$(cat /usr/share/cockpit/backup/manifest.json | jq .version)
# new_kopia_version=$(cat /data/apps/stackhub/install/version.json|jq .KOPIA.KOPIA_PLUGIN_VERSION)
# if [ "$old_kopia_version" \< "$new_kopia_version" ]; then
# echo "kopia plugin need to update"
# rm -rf /usr/share/cockpit/backup/*
# cp -r /data/apps/stackhub/cockpit/kopia/build/* /usr/share/cockpit/backup
# else
# echo "kopia is not need to update"
# 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)
new_appmanage=$(cat /data/apps/stackhub/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-06-03 06:24:52 +00:00
cp /data/apps/stackhub/docker/w9appmanage/.env /data/apps/w9services/w9appmanage/.env
cp /data/apps/stackhub/docker/w9appmanage/docker-compose.yml /data/apps/w9services/w9appmanage/docker-compose.yml
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)
new_redis=$(cat /data/apps/stackhub/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-06-03 06:24:52 +00:00
cp /data/apps/stackhub/docker/w9redis/.env /data/apps/w9services/w9redis/.env
cp /data/apps/stackhub/docker/w9redis/docker-compose.yml /data/apps/w9services/w9redis/docker-compose.yml
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)
new_portainer=$(cat /data/apps/stackhub/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-06-03 06:24:52 +00:00
cp /data/apps/stackhub/docker/w9portainer/.env /data/apps/w9services/w9portainer/.env
cp /data/apps/stackhub/docker/w9portainer/docker-compose.yml /data/apps/w9services/w9portainer/docker-compose.yml
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)
new_nginx=$(cat /data/apps/stackhub/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-06-03 06:24:52 +00:00
cp /data/apps/stackhub/docker/w9nginxproxymanager/.env /data/apps/w9services/w9nginxproxymanager/.env
cp /data/apps/stackhub/docker/w9nginxproxymanager/docker-compose.yml /data/apps/w9services/w9nginxproxymanager/docker-compose.yml
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-06-03 06:24:52 +00:00
# old_kopia=$(echo $old_version | jq .KOPIA.KOPIA_IMAGE_VERSION)
# new_kopia=$(cat /data/apps/stackhub/install/version.json | jq .KOPIA.KOPIA_IMAGE_VERSION)
# if [ "$old_kopia" \< "$new_kopia" ]; then
# echo "w9kopia need to update"
# old_password=$(cat /usr/share/cockpit/myapps/config.json | jq -r '.KOPIA.KOPIA_PASSWORD')
# sudo sed -i 's/POWER_PASSWORD=.*/POWER_PASSWORD="'$old_password'"/g' /data/apps/stackhub/docker/w9kopia/.env
# cd /data/apps/stackhub/docker/w9kopia && sudo docker compose down && sudo docker compose pull && sudo docker compose up -d
# else
# echo "w9kopia is not need to update"
# fi
2023-06-01 09:02:25 +00:00
2023-05-25 07:04:45 +00:00
}
2023-05-26 07:32:11 +00:00
CheckUpdate
2023-05-25 07:04:45 +00:00
UpdateDocker
2023-05-26 03:09:04 +00:00
UpdateCockpit
UpdatePlugins
UpdateServices