2021-05-04 01:32:34 -04:00
#!/bin/bash
2024-06-19 17:09:58 +08:00
# wgd.sh - Copyright(C) 2024 Donald Zou [https://github.com/donaldzou]
2022-01-12 19:53:36 -05:00
# Under Apache-2.0 License
2024-08-19 19:17:07 -04:00
#trap "kill $TOP_PID"
2024-08-16 03:06:31 -04:00
export TOP_PID = $$
2021-05-04 01:32:34 -04:00
app_name = "dashboard.py"
2021-09-08 21:56:31 -04:00
app_official_name = "WGDashboard"
2024-08-03 14:01:04 -04:00
venv_python = "./venv/bin/python3"
venv_gunicorn = "./venv/bin/gunicorn"
2024-08-16 01:47:44 -04:00
pythonExecutable = "python3"
2024-08-03 14:01:04 -04:00
2024-08-16 02:19:30 -04:00
heavy_checkmark = $( printf "\xE2\x9C\x94" )
heavy_crossmark = $( printf "\xE2\x9C\x97" )
2024-08-16 02:15:10 -04:00
2022-01-18 10:42:23 -05:00
PID_FILE = ./gunicorn.pid
2021-10-18 02:40:08 +03:00
environment = $( if [ [ $ENVIRONMENT ] ] ; then echo $ENVIRONMENT ; else echo 'develop' ; fi )
2021-10-25 01:16:02 +03:00
if [ [ $CONFIGURATION_PATH ] ] ; then
cb_work_dir = $CONFIGURATION_PATH /letsencrypt/work-dir
cb_config_dir = $CONFIGURATION_PATH /letsencrypt/config-dir
else
cb_work_dir = /etc/letsencrypt
cb_config_dir = /var/lib/letsencrypt
fi
2021-05-05 14:38:10 -04:00
dashes = '------------------------------------------------------------'
2021-09-03 14:40:57 -04:00
equals = '============================================================'
2024-08-02 17:27:28 -04:00
helpMsg = "[WGDashboard] Please check ./log/install.txt for more details. For further assistance, please open a ticket on https://github.com/donaldzou/WGDashboard/issues/new/choose, I'm more than happy to help :)"
2021-05-04 01:32:34 -04:00
help ( ) {
2021-09-08 12:39:25 -04:00
printf "=================================================================================\n"
2021-12-25 17:13:21 -05:00
printf "+ <WGDashboard> by Donald Zou - https://github.com/donaldzou +\n"
2021-09-08 12:39:25 -04:00
printf "=================================================================================\n"
printf "| Usage: ./wgd.sh <option> |\n"
printf "| |\n"
printf "| Available options: |\n"
2021-09-08 21:56:31 -04:00
printf "| start: To start WGDashboard. |\n"
printf "| stop: To stop WGDashboard. |\n"
printf "| debug: To start WGDashboard in debug mode (i.e run in foreground). |\n"
printf "| update: To update WGDashboard to the newest version from GitHub. |\n"
printf "| install: To install WGDashboard. |\n"
2021-09-08 12:39:25 -04:00
printf "| Thank you for using! Your support is my motivation ;) |\n"
printf "=================================================================================\n"
2021-05-04 01:32:34 -04:00
}
2021-11-25 15:55:56 +01:00
_check_and_set_venv( ) {
2024-08-02 17:27:28 -04:00
VIRTUAL_ENV = "./venv"
2021-11-25 15:55:56 +01:00
if [ ! -d $VIRTUAL_ENV ] ; then
2024-08-02 17:27:28 -04:00
printf "[WGDashboard] Creating Python Virtual Environment under ./venv\n"
2024-08-16 01:47:44 -04:00
{ $pythonExecutable -m venv $VIRTUAL_ENV ; } >> ./log/install.txt
2021-11-25 15:55:56 +01:00
fi
2024-08-16 01:47:44 -04:00
2024-08-16 02:53:45 -04:00
if ! $venv_python --version > /dev/null 2>& 1
2024-08-16 01:47:44 -04:00
then
2024-08-16 02:15:10 -04:00
printf "[WGDashboard] %s Python Virtual Environment under ./venv failed to create. Halting now.\n" " $heavy_crossmark "
2024-08-16 17:13:18 -04:00
kill $TOP_PID
2024-08-16 03:25:25 -04:00
fi
. ${ VIRTUAL_ENV } /bin/activate
2021-11-25 15:55:56 +01:00
}
2024-08-02 17:27:28 -04:00
_determineOS( ) {
if [ -f /etc/os-release ] ; then
. /etc/os-release
OS = $ID
elif [ -f /etc/redhat-release ] ; then
OS = "redhat"
2024-11-12 00:12:10 +08:00
elif [ " $( uname) " = "OpenBSD" ] ; then
OS = "openbsd"
2024-08-02 17:27:28 -04:00
else
2024-08-23 07:46:41 -05:00
printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" " $heavy_crossmark "
2024-08-02 17:27:28 -04:00
printf "%s\n" " $helpMsg "
2024-08-16 17:13:18 -04:00
kill $TOP_PID
2024-08-02 17:27:28 -04:00
fi
2024-08-16 17:24:50 -04:00
printf "[WGDashboard] OS: %s\n" " $OS "
2024-08-02 17:27:28 -04:00
}
_installPython( ) {
case " $OS " in
ubuntu| debian)
2024-08-14 22:45:36 -04:00
{ sudo apt update ; sudo apt-get install -y python3 net-tools; printf "\n\n" ; } & >> ./log/install.txt
2024-08-02 17:27:28 -04:00
; ;
2024-10-29 23:02:59 -04:00
centos| fedora| redhat| rhel| almalinux| rocky)
2024-08-02 17:27:28 -04:00
if command -v dnf & > /dev/null; then
2024-08-14 22:45:36 -04:00
{ sudo dnf install -y python3 net-tools; printf "\n\n" ; } >> ./log/install.txt
2024-08-02 17:27:28 -04:00
else
2024-08-14 22:45:36 -04:00
{ sudo yum install -y python3 net-tools ; printf "\n\n" ; } >> ./log/install.txt
2024-08-02 17:27:28 -04:00
fi
; ;
2024-08-24 06:45:13 -05:00
alpine)
2024-08-26 15:28:27 -05:00
{ sudo apk update; sudo apk add python3 net-tools --no-cache; printf "\n\n" ; } >> ./log/install.txt
2024-08-23 07:46:41 -05:00
; ;
2024-08-02 17:27:28 -04:00
esac
if ! python3 --version > /dev/null 2>& 1
then
2024-08-16 02:15:10 -04:00
printf "[WGDashboard] %s Python is still not installed, halting script now.\n" " $heavy_crossmark "
2024-08-02 17:27:28 -04:00
printf "%s\n" " $helpMsg "
2024-08-16 17:13:18 -04:00
kill $TOP_PID
2024-08-02 17:27:28 -04:00
else
2024-08-16 02:15:10 -04:00
printf "[WGDashboard] %s Python is installed\n" " $heavy_checkmark "
2024-08-02 17:27:28 -04:00
fi
}
_installPythonVenv( ) {
2024-08-16 03:18:08 -04:00
if [ " $pythonExecutable " = "python3" ] ; then
2024-08-16 03:32:28 -04:00
case " $OS " in
ubuntu| debian)
{ sudo apt update ; sudo apt-get install -y python3-venv; printf "\n\n" ; } & >> ./log/install.txt
; ;
2024-10-29 23:02:59 -04:00
centos| fedora| redhat| rhel| almalinux| rocky)
2024-08-16 03:32:28 -04:00
if command -v dnf & > /dev/null; then
{ sudo dnf install -y python3-virtualenv; printf "\n\n" ; } >> ./log/install.txt
else
{ sudo yum install -y python3-virtualenv; printf "\n\n" ; } >> ./log/install.txt
fi
; ;
2024-08-24 06:45:13 -05:00
alpine)
2024-08-23 07:46:41 -05:00
{ sudo apk update; sudo apk add py3-virtualenv ; printf "\n\n" ; } >> ./log/install.txt
2024-08-24 06:45:13 -05:00
; ;
2024-08-16 03:32:28 -04:00
*)
2024-08-23 07:46:41 -05:00
printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" " $heavy_crossmark "
2024-08-16 03:32:28 -04:00
printf "%s\n" " $helpMsg "
2024-08-16 17:13:18 -04:00
kill $TOP_PID
2024-08-16 03:32:28 -04:00
; ;
esac
2024-08-16 03:18:08 -04:00
else
2024-08-16 17:21:42 -04:00
case " $OS " in
ubuntu| debian)
{ sudo apt-get update; sudo apt-get install ${ pythonExecutable } -venv; } & >> ./log/install.txt
; ;
esac
2024-08-16 01:47:44 -04:00
fi
2024-08-02 17:27:28 -04:00
2024-08-16 01:47:44 -04:00
if ! $pythonExecutable -m venv -h > /dev/null 2>& 1
2024-08-02 17:27:28 -04:00
then
2024-08-16 03:18:08 -04:00
printf "[WGDashboard] %s Python Virtual Environment is still not installed, halting script now.\n" " $heavy_crossmark "
2024-08-02 17:27:28 -04:00
printf "%s\n" " $helpMsg "
else
2024-08-16 02:15:10 -04:00
printf "[WGDashboard] %s Python Virtual Environment is installed\n" " $heavy_checkmark "
2024-08-02 17:27:28 -04:00
fi
}
_installPythonPip( ) {
2024-08-16 01:47:44 -04:00
if ! $pythonExecutable -m pip -h > /dev/null 2>& 1
then
2024-08-16 02:40:25 -04:00
case " $OS " in
ubuntu| debian)
2024-08-16 03:14:03 -04:00
if [ " $pythonExecutable " = "python3" ] ; then
2024-08-16 03:02:45 -04:00
{ sudo apt update ; sudo apt-get install -y python3-pip; printf "\n\n" ; } & >> ./log/install.txt
else
2024-08-16 03:28:26 -04:00
{ sudo apt update ; sudo apt-get install -y ${ pythonExecutable } -distutil python3-pip; printf "\n\n" ; } & >> ./log/install.txt
2024-08-16 03:02:45 -04:00
fi
2024-08-16 02:40:25 -04:00
; ;
2024-10-29 23:02:59 -04:00
centos| fedora| redhat| rhel| almalinux| rocky)
2024-08-16 17:32:34 -04:00
if [ " $pythonExecutable " = "python3" ] ; then
2024-08-16 02:40:25 -04:00
{ sudo dnf install -y python3-pip; printf "\n\n" ; } >> ./log/install.txt
else
2024-08-16 17:32:34 -04:00
{ sudo dnf install -y ${ pythonExecutable } -pip; printf "\n\n" ; } >> ./log/install.txt
2024-08-16 02:40:25 -04:00
fi
; ;
2024-08-24 06:45:13 -05:00
alpine)
2024-08-26 15:28:27 -05:00
{ sudo apk update; sudo apk add py3-pip --no-cache; printf "\n\n" ; } >> ./log/install.txt
2024-08-24 06:45:13 -05:00
; ;
2024-08-16 02:40:25 -04:00
*)
2024-08-23 07:46:41 -05:00
printf "[WGDashboard] %s Sorry, your OS is not supported. Currently the install script only support Debian-based, Red Hat-based OS. With experimental support for Alpine Linux.\n" " $heavy_crossmark "
2024-08-16 02:40:25 -04:00
printf "%s\n" " $helpMsg "
2024-08-16 17:13:18 -04:00
kill $TOP_PID
2024-08-16 02:40:25 -04:00
; ;
esac
2024-08-16 01:47:44 -04:00
fi
2024-08-02 17:27:28 -04:00
2024-08-16 01:47:44 -04:00
if ! $pythonExecutable -m pip -h > /dev/null 2>& 1
then
2024-08-16 02:15:10 -04:00
printf "[WGDashboard] %s Python Package Manager (PIP) is still not installed, halting script now.\n" " $heavy_crossmark "
2024-08-16 01:47:44 -04:00
printf "%s\n" " $helpMsg "
2024-08-16 17:13:18 -04:00
kill $TOP_PID
2024-08-16 01:47:44 -04:00
else
2024-08-16 02:15:10 -04:00
printf "[WGDashboard] %s Python Package Manager (PIP) is installed\n" " $heavy_checkmark "
2024-08-16 01:47:44 -04:00
fi
2024-08-02 17:27:28 -04:00
}
_checkWireguard( ) {
2024-08-26 13:07:42 -05:00
if ! command -v wg > /dev/null 2>& 1 || ! command -v wg-quick > /dev/null 2>& 1
then
case " $OS " in
ubuntu| debian)
{
sudo apt update && sudo apt-get install -y wireguard;
2024-08-26 15:28:27 -05:00
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" " $OS " ;
2024-08-26 13:07:42 -05:00
} & >> ./log/install.txt
; ;
2024-10-29 23:02:59 -04:00
centos| fedora| redhat| rhel| almalinux| rocky)
2024-08-26 13:07:42 -05:00
{
sudo dnf install -y wireguard-tools;
2024-08-26 15:28:27 -05:00
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" " $OS " ;
2024-08-26 13:07:42 -05:00
} & >> ./log/install.txt
; ;
alpine)
{
2024-08-26 15:28:27 -05:00
sudo apk update && sudo apk add wireguard-tools --no-cache;
printf "\n[WGDashboard] WireGuard installed on %s.\n\n" " $OS " ;
2024-08-26 13:07:42 -05:00
} & >> ./log/install.txt
; ;
*)
printf "[WGDashboard] %s Sorry, your OS is not supported. Currently, the install script only supports Debian-based, Red Hat-based, and Alpine Linux.\n" " $heavy_crossmark "
printf "%s\n" " $helpMsg "
kill $TOP_PID
; ;
esac
else
2024-08-26 15:28:27 -05:00
printf "[WGDashboard] WireGuard is already installed.\n"
2024-08-26 13:07:42 -05:00
fi
2024-08-02 17:27:28 -04:00
}
2024-08-16 01:47:44 -04:00
2024-08-26 13:07:42 -05:00
2024-08-16 01:47:44 -04:00
_checkPythonVersion( ) {
2024-08-16 01:55:53 -04:00
version_pass = $( $pythonExecutable -c 'import sys; print("1") if (sys.version_info.major == 3 and sys.version_info.minor >= 10) else print("0");' )
2024-08-16 02:00:45 -04:00
version = $( $pythonExecutable --version)
2024-08-16 01:58:40 -04:00
if [ $version_pass = = "1" ]
2024-08-16 01:47:44 -04:00
then
2024-08-16 01:58:40 -04:00
return ;
2024-08-16 01:47:44 -04:00
elif python3.10 --version > /dev/null 2>& 1
then
2024-08-16 17:34:54 -04:00
printf "[WGDashboard] %s Found Python 3.10. Will be using [python3.10] to install WGDashboard.\n" " $heavy_checkmark "
2024-08-16 01:47:44 -04:00
pythonExecutable = "python3.10"
elif python3.11 --version > /dev/null 2>& 1
then
2024-08-16 17:34:54 -04:00
printf "[WGDashboard] %s Found Python 3.11. Will be using [python3.11] to install WGDashboard.\n" " $heavy_checkmark "
2024-08-16 01:47:44 -04:00
pythonExecutable = "python3.11"
elif python3.12 --version > /dev/null 2>& 1
then
2024-08-16 17:34:54 -04:00
printf "[WGDashboard] %s Found Python 3.12. Will be using [python3.12] to install WGDashboard.\n" " $heavy_checkmark "
2024-08-16 01:47:44 -04:00
pythonExecutable = "python3.12"
else
2024-08-16 02:15:10 -04:00
printf "[WGDashboard] %s Could not find a compatible version of Python. Current Python is %s.\n" " $heavy_crossmark " " $version "
2024-08-16 02:03:41 -04:00
printf "[WGDashboard] WGDashboard required Python 3.10, 3.11 or 3.12. Halting install now.\n"
2024-08-17 20:19:52 -04:00
kill $TOP_PID
2024-08-16 01:47:44 -04:00
fi
}
2021-09-02 22:09:06 -04:00
install_wgd( ) {
2024-08-02 17:27:28 -04:00
printf "[WGDashboard] Starting to install WGDashboard\n"
2024-10-26 18:09:42 +08:00
if [ ! -d "/etc/wireguard/WGDashboard_Backup" ]
then
printf "[WGDashboard] Creating /etc/wireguard/WGDashboard_Backup folder\n"
2024-11-05 19:46:09 +08:00
sudo mkdir "/etc/wireguard/WGDashboard_Backup"
2024-10-26 18:09:42 +08:00
fi
2024-08-02 17:27:28 -04:00
if [ ! -d "log" ]
then
printf "[WGDashboard] Creating ./log folder\n"
mkdir "log"
fi
_determineOS
if ! python3 --version > /dev/null 2>& 1
then
printf "[WGDashboard] Python is not installed, trying to install now\n"
_installPython
else
2024-08-16 02:15:10 -04:00
printf "[WGDashboard] %s Python is installed\n" " $heavy_checkmark "
2024-08-02 17:27:28 -04:00
fi
2024-08-12 01:19:55 -04:00
2024-08-16 01:47:44 -04:00
_checkPythonVersion
2024-08-02 18:30:16 -04:00
_installPythonVenv
_installPythonPip
2024-09-09 09:01:07 +02:00
_checkWireguard
2024-08-26 13:07:42 -05:00
sudo chmod -R 755 /etc/wireguard/
2024-08-03 14:01:04 -04:00
2024-08-02 17:27:28 -04:00
if [ ! -d "db" ]
2024-08-25 16:26:36 +08:00
then
printf "[WGDashboard] Creating ./db folder\n"
mkdir "db"
2021-09-03 13:52:23 -04:00
fi
2024-08-02 17:27:28 -04:00
_check_and_set_venv
printf "[WGDashboard] Upgrading Python Package Manage (PIP)\n"
2024-08-25 03:01:21 -05:00
{ date; python3 -m ensurepip --upgrade; printf "\n\n" ; } >> ./log/install.txt
2024-08-16 17:36:22 -04:00
{ date; python3 -m pip install --upgrade pip; printf "\n\n" ; } >> ./log/install.txt
2024-08-02 17:27:28 -04:00
printf "[WGDashboard] Installing latest Python dependencies\n"
2024-08-23 12:48:33 -05:00
{ date; python3 -m pip install -r requirements.txt ; printf "\n\n" ; } >> ./log/install.txt #This all works on the default installation.
2024-08-02 17:27:28 -04:00
printf "[WGDashboard] WGDashboard installed successfully!\n"
printf "[WGDashboard] Enter ./wgd.sh start to start the dashboard\n"
2021-09-02 22:09:06 -04:00
}
2021-05-04 01:32:34 -04:00
check_wgd_status( ) {
2022-01-18 10:42:23 -05:00
if test -f " $PID_FILE " ; then
if ps aux | grep -v grep | grep $( cat ./gunicorn.pid) > /dev/null; then
return 0
2021-10-18 03:10:50 +03:00
else
return 1
fi
else
2021-10-18 03:13:01 +03:00
if ps aux | grep -v grep | grep '[p]ython3 ' $app_name > /dev/null; then
2021-05-04 01:32:34 -04:00
return 0
2021-10-18 03:10:50 +03:00
else
return 1
fi
2021-05-04 01:32:34 -04:00
fi
}
2021-10-25 01:16:02 +03:00
certbot_create_ssl ( ) {
2024-08-25 16:26:36 +08:00
certbot certonly --config ./certbot.ini --email " $EMAIL " --work-dir $cb_work_dir --config-dir $cb_config_dir --domain " $SERVERURL "
2021-10-25 01:16:02 +03:00
}
certbot_renew_ssl ( ) {
2024-08-25 16:26:36 +08:00
certbot renew --work-dir $cb_work_dir --config-dir $cb_config_dir
2021-10-25 01:16:02 +03:00
}
2021-10-25 00:24:49 +03:00
gunicorn_start ( ) {
2021-10-25 01:16:02 +03:00
printf "%s\n" " $dashes "
2024-08-02 17:27:28 -04:00
printf "[WGDashboard] Starting WGDashboard with Gunicorn in the background.\n"
2021-10-25 01:16:02 +03:00
d = $( date '+%Y%m%d%H%M%S' )
if [ [ $USER = = root ] ] ; then
export PATH = $PATH :/usr/local/bin:$HOME /.local/bin
fi
2024-08-02 17:27:28 -04:00
_check_and_set_venv
2024-08-04 19:35:59 -04:00
sudo " $venv_gunicorn " --config ./gunicorn.conf.py
2024-08-04 18:45:57 -04:00
sleep 5
2024-08-04 15:29:07 -04:00
checkPIDExist = 0
while [ $checkPIDExist -eq 0 ]
do
2024-08-04 15:44:55 -04:00
if test -f './gunicorn.pid' ; then
2024-08-04 15:29:07 -04:00
checkPIDExist = 1
2024-08-04 20:16:26 -04:00
printf "[WGDashboard] Checking if WGDashboard w/ Gunicorn started successfully\n"
2024-08-04 15:29:07 -04:00
fi
sleep 2
done
2024-08-04 20:16:26 -04:00
printf "[WGDashboard] WGDashboard w/ Gunicorn started successfully\n"
2021-10-25 01:16:02 +03:00
printf "%s\n" " $dashes "
2021-10-25 00:24:49 +03:00
}
gunicorn_stop ( ) {
2024-08-25 16:26:36 +08:00
sudo kill $( cat ./gunicorn.pid)
2021-05-04 01:32:34 -04:00
}
start_wgd ( ) {
2024-08-02 17:27:28 -04:00
_checkWireguard
2022-01-18 10:42:23 -05:00
gunicorn_start
2021-05-04 01:32:34 -04:00
}
stop_wgd( ) {
2024-08-25 16:26:36 +08:00
if test -f " $PID_FILE " ; then
gunicorn_stop
else
kill " $( ps aux | grep " [p]ython3 $app_name " | awk '{print $2}' ) "
fi
2021-05-04 01:32:34 -04:00
}
2024-10-26 18:09:42 +08:00
# ============= Docker Functions =============
2024-08-25 03:01:21 -05:00
startwgd_docker( ) {
_checkWireguard
2024-08-25 16:26:36 +08:00
printf "[WGDashboard][Docker] WireGuard configuration started\n"
2024-08-25 03:01:21 -05:00
{ date; start_core ; printf "\n\n" ; } >> ./log/install.txt
gunicorn_start
}
2024-08-25 16:26:36 +08:00
start_core( ) {
# Re-assign config_files to ensure it includes any newly created configurations
local config_files = $( find /etc/wireguard -type f -name "*.conf" )
# Set file permissions
find /etc/wireguard -type f -name "*.conf" -exec chmod 600 { } \;
find " $iptable_dir " -type f -name "*.sh" -exec chmod +x { } \;
# Start WireGuard for each config file
for file in $config_files ; do
config_name = $( basename " $file " ".conf" )
wg-quick up " $config_name "
done
2024-08-25 03:01:21 -05:00
}
newconf_wgd( ) {
local wg_port_listen = $wg_port
local wg_addr_range = $wg_net
private_key = $( wg genkey)
public_key = $( echo " $private_key " | wg pubkey)
cat <<EOF >"/etc/wireguard/wg0.conf"
[ Interface]
PrivateKey = $private_key
Address = $wg_addr_range
ListenPort = $wg_port_listen
SaveConfig = true
PostUp = /opt/wireguarddashboard/src/iptable-rules/postup.sh
PreDown = /opt/wireguarddashboard/src/iptable-rules/postdown.sh
EOF
}
2024-10-26 18:09:42 +08:00
# ============= Docker Functions =============
2021-05-04 01:32:34 -04:00
start_wgd_debug( ) {
2024-08-25 16:26:36 +08:00
printf "%s\n" " $dashes "
_checkWireguard
printf "[WGDashboard] Starting WGDashboard in the foreground.\n"
sudo " $venv_python " " $app_name "
printf "%s\n" " $dashes "
2021-05-04 01:32:34 -04:00
}
2021-05-04 21:26:40 -04:00
update_wgd( ) {
2024-08-19 21:30:47 -04:00
_determineOS
if ! python3 --version > /dev/null 2>& 1
then
printf "[WGDashboard] Python is not installed, trying to install now\n"
_installPython
else
printf "[WGDashboard] %s Python is installed\n" " $heavy_checkmark "
fi
_checkPythonVersion
_installPythonVenv
_installPythonPip
new_ver = $( $venv_python -c "import json; import urllib.request; data = urllib.request.urlopen('https://api.github.com/repos/donaldzou/WGDashboard/releases/latest').read(); output = json.loads(data);print(output['tag_name'])" )
printf "%s\n" " $dashes "
2024-10-24 23:10:36 +02:00
if [ " $commandConfirmed " = "true" ] ; then
printf "[WGDashboard] Confirmation granted.\n"
up = "Y"
else
printf "[WGDashboard] Are you sure you want to update to the %s? (Y/N): " " $new_ver "
read up
fi
2024-08-19 21:30:47 -04:00
if [ " $up " = "Y" ] || [ " $up " = "y" ] ; then
printf "[WGDashboard] Shutting down WGDashboard\n"
2024-10-24 23:10:36 +02:00
2024-08-19 21:30:47 -04:00
if check_wgd_status; then
stop_wgd
fi
2024-10-24 23:10:36 +02:00
mv wgd.sh wgd.sh.old && \
printf "[WGDashboard] Downloading %s from GitHub..." " $new_ver " && \
{ date; git stash; git pull https://github.com/donaldzou/WGDashboard.git $new_ver --force; } >> ./log/update.txt && \
chmod +x ./wgd.sh && \
sudo ./wgd.sh install && \
printf "[WGDashboard] Update completed!\n" && \
printf "%s\n" " $dashes " ; \
2024-08-19 21:30:47 -04:00
rm wgd.sh.old
else
printf "%s\n" " $dashes "
printf "[WGDashboard] Update Canceled.\n"
printf "%s\n" " $dashes "
fi
2021-05-04 21:26:40 -04:00
}
2024-10-24 23:10:36 +02:00
if [ " $# " -lt 1 ] ; then
help
else
if [ " $2 " = "-y" ] || [ " $2 " = "-Y" ] ; then
commandConfirmed = "true"
fi
if [ " $1 " = "start" ] ; then
if check_wgd_status; then
printf "%s\n" " $dashes "
printf "[WGDashboard] WGDashboard is already running.\n"
printf "%s\n" " $dashes "
else
start_wgd
fi
elif [ " $1 " = "stop" ] ; then
if check_wgd_status; then
printf "%s\n" " $dashes "
stop_wgd
printf "[WGDashboard] WGDashboard is stopped.\n"
printf "%s\n" " $dashes "
2024-08-25 16:26:36 +08:00
else
2024-10-24 23:10:36 +02:00
printf "%s\n" " $dashes "
printf "[WGDashboard] WGDashboard is not running.\n"
printf "%s\n" " $dashes "
fi
elif [ " $1 " = "update" ] ; then
update_wgd
elif [ " $1 " = "install" ] ; then
printf "%s\n" " $dashes "
install_wgd
printf "%s\n" " $dashes "
elif [ " $1 " = "restart" ] ; then
if check_wgd_status; then
printf "%s\n" " $dashes "
stop_wgd
printf "| WGDashboard is stopped. |\n"
sleep 4
start_wgd
else
start_wgd
2024-08-25 16:26:36 +08:00
fi
2024-10-24 23:10:36 +02:00
elif [ " $1 " = "debug" ] ; then
if check_wgd_status; then
printf "| WGDashboard is already running. |\n"
else
start_wgd_debug
fi
2024-11-12 00:12:10 +08:00
elif [ " $1 " = "os" ] ; then
_determineOS
2024-10-24 23:10:36 +02:00
else
help
fi
2021-05-04 01:32:34 -04:00
fi