2023-03-21 04:06:44 +00:00
#!/bin/bash
PATH = /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
2023-04-12 09:07:36 +00:00
function error_exit {
echo " $1 " 1>& 2
exit 1
}
2023-07-03 02:36:36 +00:00
trap 'error_exit "Please push issue to: https://github.com/Websoft9/stackhub/issues"' ERR
2023-04-12 09:07:36 +00:00
2023-05-18 09:15:59 +00:00
urls = (
2023-05-25 07:04:45 +00:00
https://github.com
2023-06-07 03:39:48 +00:00
https://ghproxy.com/https://github.com
2023-05-18 09:15:59 +00:00
)
2023-04-12 09:07:36 +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)
CheckEnvironment( ) {
2023-05-22 02:48:58 +00:00
echo "---------------------------------- Welcome to install websoft9's appstore, it will take 3-5 minutes -------------------------------------------------------"
2023-05-20 03:17:35 +00:00
2023-04-12 09:07:36 +00:00
echo "Check environment ..."
echo os_type: $os_type
echo os_version: $os_version
2023-05-22 02:48:58 +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-04-12 09:07:36 +00:00
if [ $( getconf WORD_BIT) = '32' ] && [ $( getconf LONG_BIT) = '64' ] ; then
echo "64-bit operating system detected."
2023-03-21 04:06:44 +00:00
else
2023-04-12 09:07:36 +00:00
echo "This script only works on 64-bit operating systems."
exit 1
2023-03-21 04:06:44 +00:00
fi
2023-04-12 09:07:36 +00:00
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)
2023-03-21 04:06:44 +00:00
fi
2023-04-12 09:07:36 +00:00
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."
2023-03-21 04:06:44 +00:00
fi
2023-04-12 09:07:36 +00:00
# Check port used
if netstat -tuln | grep -qE ':(80|9000|5000)\s' ; then
echo "Port 80 or 9000 or 5000 is already in use."
exit 1
else
echo "Port 80, 9000 and 5000 are free."
2023-03-21 04:06:44 +00:00
fi
2023-04-12 09:07:36 +00:00
}
InstallTools( ) {
2023-03-21 04:06:44 +00:00
2023-05-30 09:42:14 +00:00
echo "Prepare to install Tools ..."
2023-04-12 09:07:36 +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
2023-06-17 03:35:57 +00:00
sudo yum install git curl wget yum-utils jq firewalld bc unzip -y 1>/dev/null 2>& 1
2023-03-21 04:06:44 +00:00
fi
2023-04-12 09:07:36 +00:00
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
2023-06-28 01:06:28 +00:00
if command -v git > /dev/null; then
echo "git installed ..."
else
sudo apt install git -y
fi
if command -v curl > /dev/null; then
echo "jcurlq installed ..."
else
sudo apt install curl -y
fi
if command -v wget > /dev/null; then
echo "wget installed ..."
else
sudo apt install wget -y
fi
if command -v jq > /dev/null; then
echo "jq installed ..."
else
sudo apt install jq -y
fi
if command -v firewalld > /dev/null; then
echo "firewalld installed ..."
else
sudo apt install firewalld -y
fi
if command -v bc > /dev/null; then
echo "bc installed ..."
else
sudo apt install bc -y
fi
if command -v unzip > /dev/null; then
echo "unzip installed ..."
else
sudo apt install unzip -y
fi
2023-04-12 09:07:36 +00:00
fi
2023-03-21 04:06:44 +00:00
}
2023-04-12 09:07:36 +00:00
InstallDocker( ) {
2023-06-25 03:01:50 +00:00
if command -v docker & > /dev/null
then
echo "Docker is installed, update..."
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
elif command -v dnf > /dev/null; then
sudo dnf update -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
elif command -v yum > /dev/null; then
sudo yum update -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
fi
2023-06-27 08:51:11 +00:00
sudo systemctl start docker
sudo systemctl enable docker
if ! docker network inspect websoft9 > /dev/null 2>& 1; then
sudo docker network create websoft9
fi
2023-06-25 03:01:50 +00:00
return
else
echo "Docker is not installed, start to install..."
fi
2023-04-12 09:07:36 +00:00
if [ " $os_type " = = 'CentOS' ] ; then
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
fi
if [ " $os_type " = = 'Ubuntu' ] || [ " $os_type " = = 'Debian' ] ; then
apt-get update
while fuser /var/lib/dpkg/lock >/dev/null 2>& 1 ; do
echo "Waiting for other software managers to finish..."
sleep 5
done
curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh
sleep 30
fi
if [ " $os_type " = = 'OracleLinux' ] ; then
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
fi
if [ " $os_type " = = 'Fedora' ] ; then
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/fedora/docker-ce.repo
sudo yum install device-mapper-persistent-data lvm2 docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-scan-plugin docker-ce-rootless-extras -y
fi
if [ " $os_type " = = 'Redhat' ] ; then
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine podman runc -y 1>/dev/null 2>& 1
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
fi
if [ " $os_type " = = 'CentOS Stream' ] ; then
sudo yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine podman runc -y 1>/dev/null 2>& 1
wget -O /etc/yum.repos.d/docker-ce.repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
fi
sudo systemctl start docker
sudo systemctl enable docker
if ! docker network inspect websoft9 > /dev/null 2>& 1; then
sudo docker network create websoft9
fi
2023-03-21 04:06:44 +00:00
}
2023-04-12 09:07:36 +00:00
InstallCockpit( ) {
2023-05-30 09:42:14 +00:00
echo "Prepare to install Cockpit ..."
2023-03-21 04:06:44 +00:00
2023-04-12 09:07:36 +00:00
if [ " ${ os_type } " = = 'Debian' ] ; then
VERSION_CODENAME = $( cat /etc/os-release | grep VERSION_CODENAME| cut -f2 -d"=" )
sudo echo " deb http://deb.debian.org/debian ${ VERSION_CODENAME } -backports main " >/etc/apt/sources.list.d/backports.list
sudo apt update
sudo apt install -t ${ VERSION_CODENAME } -backports cockpit -y
2023-06-02 09:04:22 +00:00
sudo apt install cockpit-pcp cockpit-packagekit -y 1>/dev/null 2>& 1
2023-03-21 04:06:44 +00:00
fi
2023-04-12 09:07:36 +00:00
if [ " ${ os_type } " = = 'Ubuntu' ] ; then
2023-05-22 09:12:08 +00:00
if grep -q "^#.*deb http://mirrors.tencentyun.com/ubuntu.*backports" /etc/apt/sources.list; then
2023-05-22 08:18:38 +00:00
echo "Add backports deb ..."
2023-05-22 09:12:08 +00:00
sudo sed -i 's/^#\(.*deb http:\/\/mirrors.tencentyun.com\/ubuntu.*backports.*\)/\1/' /etc/apt/sources.list
2023-05-22 08:09:30 +00:00
apt update
fi
2023-04-12 09:07:36 +00:00
VERSION_CODENAME = $( cat /etc/os-release | grep VERSION_CODENAME| cut -f2 -d"=" )
sudo apt install -t ${ VERSION_CODENAME } -backports cockpit -y
2023-06-06 07:11:20 +00:00
sudo apt install cockpit-pcp -y 1>/dev/null 2>& 1
2023-04-12 09:07:36 +00:00
echo "Cockpit allow root user"
echo "" >/etc/cockpit/disallowed-users 1>/dev/null 2>& 1
2023-03-21 04:06:44 +00:00
fi
2023-04-12 09:07:36 +00:00
if [ " ${ os_type } " = = 'CentOS' ] || [ " $os_type " = = 'OracleLinux' ] ; then
sudo yum install cockpit -y
2023-06-02 09:04:22 +00:00
sudo yum install cockpit-pcp cockpit-packagekit -y 1>/dev/null 2>& 1
2023-04-12 09:07:36 +00:00
sudo systemctl enable --now cockpit.socket
sudo firewall-cmd --permanent --zone= public --add-service= cockpit
sudo firewall-cmd --reload
fi
2023-03-21 04:06:44 +00:00
2023-04-12 09:07:36 +00:00
if [ " $os_type " = = 'Fedora' ] ; then
sudo dnf install cockpit -y
2023-06-02 09:04:22 +00:00
sudo dnf install cockpit-pcp cockpit-packagekit -y 1>/dev/null 2>& 1
2023-04-12 09:07:36 +00:00
sudo systemctl enable --now cockpit.socket
sudo firewall-cmd --add-service= cockpit
sudo firewall-cmd --add-service= cockpit --permanent
fi
if [ " $os_type " = = 'Redhat' ] ; then
sudo subscription-manager repos --enable rhel-7-server-extras-rpms 1>/dev/null 2>& 1
sudo yum install cockpit -y
2023-06-02 09:04:22 +00:00
sudo yum install cockpit-pcp cockpit-packagekit -y 1>/dev/null 2>& 1
2023-04-12 09:07:36 +00:00
sudo setenforce 0 1>/dev/null 2>& 1
sudo sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config 1>/dev/null 2>& 1
sudo systemctl enable --now cockpit.socket
sudo firewall-cmd --add-service= cockpit
sudo firewall-cmd --add-service= cockpit --permanent
fi
if [ " $os_type " = = 'CentOS Stream' ] ; then
sudo subscription-manager repos --enable rhel-7-server-extras-rpms 1>/dev/null 2>& 1
sudo yum install cockpit -y
2023-06-01 02:37:17 +00:00
sudo yum install cockpit-pcp -y 1>/dev/null 2>& 1
2023-04-12 09:07:36 +00:00
sudo systemctl enable --now cockpit.socket
sudo firewall-cmd --add-service= cockpit
sudo firewall-cmd --add-service= cockpit --permanent
sudo setenforce 0 1>/dev/null 2>& 1
sudo sed -i 's/SELINUX=.*/SELINUX=disabled/' /etc/selinux/config 1>/dev/null 2>& 1
fi
echo "Set cockpit port to 9000 ..."
sudo sed -i 's/ListenStream=9090/ListenStream=9000/' /lib/systemd/system/cockpit.socket
# install plugins
2023-06-02 08:40:57 +00:00
# install appstore
mkdir /usr/share/cockpit/appstore
2023-06-27 07:06:35 +00:00
cp -r /data/apps/plugin-appstore/build/* /usr/share/cockpit/appstore
cp -r /data/apps/plugin-appstore/data /usr/share/cockpit/appstore/static/
2023-06-02 08:40:57 +00:00
# install portainer
mkdir /usr/share/cockpit/container
2023-06-27 07:06:35 +00:00
cp -r /data/apps/plugin-portainer/build/* /usr/share/cockpit/container
2023-06-02 08:40:57 +00:00
## install nginx
mkdir /usr/share/cockpit/nginx
2023-06-27 07:06:35 +00:00
cp -r /data/apps/plugin-nginx/build/* /usr/share/cockpit/nginx
2023-06-20 03:58:43 +00:00
## install settings
mkdir /usr/share/cockpit/settings
2023-06-27 07:06:35 +00:00
cp -r /data/apps/plugin-settings/build/* /usr/share/cockpit/settings
2023-06-02 08:40:57 +00:00
## install myapps
mkdir /usr/share/cockpit/myapps
2023-06-27 07:06:35 +00:00
cp -r /data/apps/plugin-myapps/build/* /usr/share/cockpit/myapps
2023-06-28 01:06:28 +00:00
cp -r /data/apps/plugin-myapps/logos /usr/share/cockpit/appstore/static/
2023-06-27 07:06:35 +00:00
rm -rf /data/apps/plugin-*
2023-04-12 09:07:36 +00:00
# install navigator
if [ " $os_type " = = 'Ubuntu' ] || [ " $os_type " = = 'Debian' ] ; then
2023-05-18 09:15:59 +00:00
wget -qO - https://repo.45drives.com/key/gpg.asc | sudo gpg --dearmor -o /usr/share/keyrings/45drives-archive-keyring.gpg
cd /etc/apt/sources.list.d
sudo curl -sSL https://repo.45drives.com/lists/45drives.sources -o /etc/apt/sources.list.d/45drives.sources
sudo apt update
sudo apt install cockpit-navigator -y
2023-03-21 04:06:44 +00:00
fi
2023-04-12 09:07:36 +00:00
if [ " $os_type " = = 'Redhat' ] || [ " $os_type " = = 'CentOS Stream' ] || [ " $os_type " = = 'Fedora' ] ; then
2023-05-18 09:15:59 +00:00
curl -sSL https://repo.45drives.com/setup -o setup-repo.sh
sudo bash setup-repo.sh
2023-04-12 09:07:36 +00:00
sudo dnf install cockpit-navigator -y 1>/dev/null 2>& 1
fi
if [ " ${ os_type } " = = 'CentOS' ] || [ " $os_type " = = 'OracleLinux' ] ; then
2023-05-18 09:15:59 +00:00
curl -sSL https://repo.45drives.com/setup -o setup-repo.sh
sudo bash setup-repo.sh
2023-04-12 09:07:36 +00:00
sudo yum install cockpit-navigator -y 1>/dev/null 2>& 1
fi
# uninstall plugins
2023-06-02 09:04:22 +00:00
rm -rf /usr/share/cockpit/apps /usr/share/cockpit/selinux /usr/share/cockpit/kdump /usr/share/cockpit/sosreport /usr/share/cockpit/packagekit
2023-04-12 09:07:36 +00:00
# configure cockpit
2023-06-27 07:06:35 +00:00
cp /data/apps/websoft9/cockpit/cockpit.conf /etc/cockpit/cockpit.conf
2023-04-12 09:07:36 +00:00
sudo systemctl daemon-reload
sudo systemctl enable --now cockpit
sudo systemctl enable --now cockpit.socket
sudo systemctl restart cockpit.socket
sudo systemctl restart cockpit
}
2023-05-18 09:15:59 +00:00
function fastest_url( ) {
2023-05-25 09:55:18 +00:00
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
2023-05-29 07:04:41 +00:00
time = $( curl --connect-timeout 3 -s -w '%{time_total}\n' -o /dev/null $url )
2023-05-25 09:55:18 +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-05-18 09:15:59 +00:00
}
2023-05-25 09:22:31 +00:00
function clone_repo( ) {
2023-04-12 09:07:36 +00:00
url = $1
path = $2
for i in { 1..5}
do
2023-06-07 03:39:48 +00:00
git clone --depth= 1 $url $path
2023-04-12 09:07:36 +00:00
if [ $? -eq 0 ]
then
echo "Clone successful"
break
else
echo " Clone failed, retrying $i /5 "
fi
done
2023-05-25 07:04:45 +00:00
if [ ! -d " $path " ] ; then
echo " $path clone failed. "
exit 1
fi
2023-04-12 09:07:36 +00:00
}
2023-05-30 09:42:14 +00:00
PrepareStaticFiles( ) {
2023-04-12 09:07:36 +00:00
2023-05-30 09:42:14 +00:00
echo "Prepare to install ..."
2023-05-18 09:15:59 +00:00
fasturl = $( fastest_url " ${ urls [@] } " )
2023-05-30 07:10:17 +00:00
echo "fast url is: " $fasturl
2023-06-27 09:54:36 +00:00
if [ -z " $fasturl " ] ; then
fasturl = "https://ghproxy.com/https://github.com"
fi
2023-04-12 09:07:36 +00:00
# download apps
mkdir -p /data/apps
2023-05-18 09:15:59 +00:00
clone_repo $fasturl /Websoft9/docker-library /data/library
2023-06-27 07:06:35 +00:00
clone_repo $fasturl /Websoft9/websoft9 /data/apps/websoft9
clone_repo $fasturl /Websoft9/plugin-appstore /data/apps/plugin-appstore
clone_repo $fasturl /Websoft9/plugin-myapps /data/apps/plugin-myapps
clone_repo $fasturl /Websoft9/plugin-portainer /data/apps/plugin-portainer
clone_repo $fasturl /Websoft9/plugin-settings /data/apps/plugin-settings
clone_repo $fasturl /Websoft9/plugin-nginx /data/apps/plugin-nginx
cp -r /data/apps/websoft9/docker /data/apps/w9services
2023-04-12 09:07:36 +00:00
}
StartAppMng( ) {
echo "Start appmanage API ..."
2023-06-03 02:18:41 +00:00
cd /data/apps/w9services/w9redis && sudo docker compose up -d
cd /data/apps/w9services/w9appmanage && sudo docker compose up -d
2023-05-18 09:15:59 +00:00
2023-06-28 01:06:28 +00:00
public_ip = ` bash /data/apps/websoft9/scripts/get_ip.sh`
2023-06-03 02:18:41 +00:00
echo $public_ip > /data/apps/w9services/w9appmanage/public_ip
2023-06-30 08:02:39 +00:00
appmanage_ip = $( docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' websoft9-appmanage)
2023-04-12 09:07:36 +00:00
}
2023-05-18 09:15:59 +00:00
StartPortainer( ) {
echo "Start Portainer ..."
2023-06-03 02:18:41 +00:00
cd /data/apps/w9services/w9portainer && sudo docker compose up -d
2023-05-18 09:15:59 +00:00
docker pull backplane/pwgen
new_password = $( docker run --name pwgen backplane/pwgen 15) !
docker rm -f pwgen
2023-06-30 08:02:39 +00:00
portainer_ip = $( docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' websoft9-portainer)
2023-06-02 08:40:57 +00:00
sudo sed -i 's/"PORTAINER_USERNAME": ".*"/"PORTAINER_USERNAME": "admin"/g' /usr/share/cockpit/myapps/config.json
sudo sed -i 's/"PORTAINER_PASSWORD": ".*"/"PORTAINER_PASSWORD": "' $new_password '"/g' /usr/share/cockpit/myapps/config.json
2023-06-30 08:02:39 +00:00
curl -X POST -H "Content-Type: application/json" -d '{"username":"admin", "Password":"' $new_password '"}' http://$portainer_ip :9000/api/users/admin/init
curl -X POST -H "Content-Type: application/json" -d '{"user_name":"admin", "password":"' $new_password '"}' http://$appmanage_ip :5000/AppUpdateUser
2023-05-18 09:15:59 +00:00
}
2023-04-12 09:07:36 +00:00
InstallNginx( ) {
echo "Install nginxproxymanager ..."
2023-06-03 02:18:41 +00:00
cd /data/apps/w9services/w9nginxproxymanager && sudo docker compose up -d
2023-05-18 09:15:59 +00:00
sleep 25
echo "edit nginxproxymanager password..."
2023-06-30 08:02:39 +00:00
login_data = $( curl -X POST -H "Content-Type: application/json" -d '{"identity":"admin@example.com","scope":"user", "secret":"changeme"}' http://$nginx_ip :81/api/tokens)
2023-05-18 09:15:59 +00:00
sleep 3
2023-06-30 08:02:39 +00:00
nginx_ip = $( docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' websoft9-nginxproxymanager)
2023-06-28 02:14:15 +00:00
#token=$(echo $login_data | grep -Po '(?<="token":")[^"]*')
token = $( echo $login_data | jq -r '.token' )
2023-05-18 09:15:59 +00:00
new_password = $( docker run --name pwgen backplane/pwgen 15) !
docker rm -f pwgen
2023-06-30 08:02:39 +00:00
curl -X PUT -H "Content-Type: application/json" -H " Authorization: Bearer $token " -d '{"email": "help@websoft9.com", "nickname": "admin", "is_disabled": false, "roles": ["admin"]}' http://$nginx_ip :81/api/users/1
curl -X PUT -H "Content-Type: application/json" -H " Authorization: Bearer $token " -d '{"type":"password","current":"changeme","secret":"' $new_password '"}' http://$nginx_ip :81/api/users/1/auth
2023-05-18 09:15:59 +00:00
sleep 3
2023-06-30 08:02:39 +00:00
curl -X POST -H "Content-Type: application/json" -d '{"user_name":"help@websoft9.com", "password":"' $new_password '"}' http://$appmanage_ip :5000/AppUpdateUser
2023-06-02 08:40:57 +00:00
sudo sed -i 's/"NGINXPROXYMANAGER_USERNAME": ".*"/"NGINXPROXYMANAGER_USERNAME": "help@websoft9.com"/g' /usr/share/cockpit/myapps/config.json
sudo sed -i 's/"NGINXPROXYMANAGER_PASSWORD": ".*"/"NGINXPROXYMANAGER_PASSWORD": "' $new_password '"/g' /usr/share/cockpit/myapps/config.json
sudo sed -i 's/"NGINXPROXYMANAGER_NIKENAME": ".*"/"NGINXPROXYMANAGER_NIKENAME": "admin"/g' /usr/share/cockpit/myapps/config.json
2023-05-18 09:15:59 +00:00
echo "edit password success ..."
while [ ! -d "/var/lib/docker/volumes/w9nginxproxymanager_nginx_data/_data/nginx/proxy_host" ] ; do
2023-04-12 09:07:36 +00:00
sleep 1
done
2023-06-03 02:18:41 +00:00
cp /data/apps/w9services/w9nginxproxymanager/initproxy.conf /var/lib/docker/volumes/w9nginxproxymanager_nginx_data/_data/nginx/proxy_host
2023-06-28 01:06:28 +00:00
public_ip = ` bash /data/apps/websoft9/scripts/get_ip.sh`
2023-05-18 09:15:59 +00:00
sudo sed -i " s/domain.com/ $public_ip /g " /var/lib/docker/volumes/w9nginxproxymanager_nginx_data/_data/nginx/proxy_host/initproxy.conf
2023-05-26 03:09:04 +00:00
echo "Add htpasswd for appmanage ..."
2023-06-17 02:12:44 +00:00
new_password = $( docker run --name pwgen backplane/pwgen 15) !
docker rm -f pwgen
2023-06-02 08:40:57 +00:00
sudo sed -i 's/"APPMANAGE_USERNAME": ".*"/"APPMANAGE_USERNAME": "websoft9"/g' /usr/share/cockpit/myapps/config.json
sudo sed -i 's/"APPMANAGE_PASSWORD": ".*"/"APPMANAGE_PASSWORD": "' $new_password '"/g' /usr/share/cockpit/myapps/config.json
2023-05-26 03:09:04 +00:00
rm -rf /var/lib/docker/volumes/w9nginxproxymanager_nginx_data/_data/nginx/proxy_host/.htpasswd /tmp/.htpasswd
docker run --rm --volume /tmp:/work backplane/htpasswd -c -b .htpasswd websoft9 $new_password
cp /tmp/.htpasswd /var/lib/docker/volumes/w9nginxproxymanager_nginx_data/_data/nginx/proxy_host/.htpasswd
2023-04-12 09:07:36 +00:00
sudo docker restart websoft9-nginxproxymanager
2023-05-18 09:15:59 +00:00
2023-04-12 09:07:36 +00:00
}
2023-05-31 03:32:37 +00:00
EditMenu( ) {
echo "Start to Edit Cockpit Menu ..."
2023-06-17 03:09:41 +00:00
if command -v jq > /dev/null; then
2023-06-17 02:12:44 +00:00
if [ -e /usr/share/cockpit/systemd ] ; then
jq '. | .tools as $menu | .menu as $tools | .tools=$tools | .menu=$menu | del(.tools.services) | del(.menu.preload.services) | .menu.index = .tools.index | del(.tools.index) | .menu.index.order = -2' /usr/share/cockpit/systemd/manifest.json > /usr/share/cockpit/systemd/manifest.json.tmp
rm -rf /usr/share/cockpit/systemd/manifest.json
mv /usr/share/cockpit/systemd/manifest.json.tmp /usr/share/cockpit/systemd/manifest.json
2023-06-28 10:05:02 +00:00
cd /usr/share/cockpit/systemd && rm -rf services.js.gz services.html.gz services.css.gz services.js services.html services.css
2023-06-17 02:12:44 +00:00
fi
if [ -e /usr/share/cockpit/networkmanager ] ; then
sudo sed -i 's/menu/tools/g' /usr/share/cockpit/networkmanager/manifest.json
fi
if [ -e /usr/share/cockpit/storaged ] ; then
sudo sed -i 's/menu/tools/g' /usr/share/cockpit/storaged/manifest.json
fi
if [ -e /usr/share/cockpit/users ] ; then
sudo sed -i 's/menu/tools/g' /usr/share/cockpit/users/manifest.json
fi
2023-06-06 06:54:10 +00:00
2023-06-17 02:12:44 +00:00
jq '. | del(.locales."ca-es") | del(.locales."nb-no") | del(.locales."sk-sk") | del(.locales."tr-tr")| del(.locales."cs-cz") | del(.locales."de-de") | del(.locales."es-es") | del(.locales."fi-fi") | del(.locales."fr-fr") | del(.locales."it-it") | del(.locales."ja-jp") | del(.locales."pl-pl") | del(.locales."pt-br") | del(.locales."ru-ru") | del(.locales."sv-se") | del(.locales."uk-ua") | del(.locales."zh-tw") | del(.locales."he-il") | del(.locales."nl-nl") | del(.locales."ko-kr") | del(.locales."ka-ge")' /usr/share/cockpit/shell/manifest.json > /usr/share/cockpit/shell/manifest.json.tmp
rm -rf /usr/share/cockpit/shell/manifest.json
mv /usr/share/cockpit/shell/manifest.json.tmp /usr/share/cockpit/shell/manifest.json
else
echo "system have no jq, use cockpit menu ..."
2023-06-17 06:06:47 +00:00
if [ " $os_type " = = 'CentOS' ] || [ " $os_type " = = 'CentOS Stream' ] || [ " $os_type " = = 'Fedora' ] || [ " $os_type " = = 'OracleLinux' ] || [ " $os_type " = = 'Redhat' ] ; then
sudo yum install epel-release -y 1>/dev/null 2>& 1
sudo yum install jq -y 1>/dev/null 2>& 1
if [ -e /usr/share/cockpit/systemd ] ; then
jq '. | .tools as $menu | .menu as $tools | .tools=$tools | .menu=$menu | del(.tools.services) | del(.menu.preload.services) | .menu.index = .tools.index | del(.tools.index) | .menu.index.order = -2' /usr/share/cockpit/systemd/manifest.json > /usr/share/cockpit/systemd/manifest.json.tmp
rm -rf /usr/share/cockpit/systemd/manifest.json
mv /usr/share/cockpit/systemd/manifest.json.tmp /usr/share/cockpit/systemd/manifest.json
cd /usr/share/cockpit/systemd && rm -rf services.js.gz services.html.gz services.css.gz
fi
if [ -e /usr/share/cockpit/networkmanager ] ; then
sudo sed -i 's/menu/tools/g' /usr/share/cockpit/networkmanager/manifest.json
fi
if [ -e /usr/share/cockpit/storaged ] ; then
sudo sed -i 's/menu/tools/g' /usr/share/cockpit/storaged/manifest.json
fi
if [ -e /usr/share/cockpit/users ] ; then
sudo sed -i 's/menu/tools/g' /usr/share/cockpit/users/manifest.json
fi
jq '. | del(.locales."ca-es") | del(.locales."nb-no") | del(.locales."sk-sk") | del(.locales."tr-tr")| del(.locales."cs-cz") | del(.locales."de-de") | del(.locales."es-es") | del(.locales."fi-fi") | del(.locales."fr-fr") | del(.locales."it-it") | del(.locales."ja-jp") | del(.locales."pl-pl") | del(.locales."pt-br") | del(.locales."ru-ru") | del(.locales."sv-se") | del(.locales."uk-ua") | del(.locales."zh-tw") | del(.locales."he-il") | del(.locales."nl-nl") | del(.locales."ko-kr") | del(.locales."ka-ge")' /usr/share/cockpit/shell/manifest.json > /usr/share/cockpit/shell/manifest.json.tmp
rm -rf /usr/share/cockpit/shell/manifest.json
mv /usr/share/cockpit/shell/manifest.json.tmp /usr/share/cockpit/shell/manifest.json
fi
2023-06-17 02:12:44 +00:00
fi
2023-06-01 09:46:14 +00:00
echo "---------------------------------- Install success! you can install a app by websoft9's appstore -------------------------------------------------------"
2023-05-31 03:32:37 +00:00
}
2023-04-12 09:07:36 +00:00
CheckEnvironment
InstallTools
InstallDocker
2023-05-30 09:42:14 +00:00
PrepareStaticFiles
2023-04-12 09:07:36 +00:00
InstallCockpit
StartAppMng
2023-05-18 09:15:59 +00:00
StartPortainer
2023-04-12 09:07:36 +00:00
InstallNginx
2023-05-31 03:32:37 +00:00
EditMenu