1
0
mirror of https://github.com/donaldzou/WGDashboard.git synced 2024-11-22 07:10:09 +01:00

Update wgd.sh

This commit is contained in:
Donald Zou 2024-08-03 14:01:04 -04:00
parent 52989c8f5c
commit 61473877a4

View File

@ -4,6 +4,9 @@
# Under Apache-2.0 License # Under Apache-2.0 License
app_name="dashboard.py" app_name="dashboard.py"
app_official_name="WGDashboard" app_official_name="WGDashboard"
venv_python="./venv/bin/python3"
venv_gunicorn="./venv/bin/gunicorn"
PID_FILE=./gunicorn.pid PID_FILE=./gunicorn.pid
environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi) environment=$(if [[ $ENVIRONMENT ]]; then echo $ENVIRONMENT; else echo 'develop'; fi)
if [[ $CONFIGURATION_PATH ]]; then if [[ $CONFIGURATION_PATH ]]; then
@ -178,21 +181,7 @@ install_wgd(){
fi fi
_installPythonVenv _installPythonVenv
_installPythonPip _installPythonPip
# if ! python3 -m venv -h > /dev/null 2>&1
# then
# printf "[WGDashboard] Python Virtual Environment is not installed, trying to install now\n"
# _installPythonVenv
# else
# printf "[WGDashboard] \xE2\x9C\x94 Python Virtual Environment is installed\n"
# fi
# if ! python3 -m pip -h > /dev/null 2>&1
# then
# printf "[WGDashboard] Python Package Manager (PIP) is not installed, trying to install now\n"
# _installPythonPip
# else
# printf "[WGDashboard] \xE2\x9C\x94 Python Package Manager (PIP) is installed\n"
# fi
version_pass=$(python3 -c 'import sys; print("1") if (sys.version_info.major == 3 and sys.version_info.minor >= 7) else print("0");') version_pass=$(python3 -c 'import sys; print("1") if (sys.version_info.major == 3 and sys.version_info.minor >= 7) else print("0");')
if [ $version_pass == "0" ] if [ $version_pass == "0" ]
@ -247,7 +236,7 @@ gunicorn_start () {
export PATH=$PATH:/usr/local/bin:$HOME/.local/bin export PATH=$PATH:/usr/local/bin:$HOME/.local/bin
fi fi
_check_and_set_venv _check_and_set_venv
sudo ./venv/bin/gunicorn --access-logfile log/access_"$d".log \ sudo "$venv_gunicorn" --access-logfile log/access_"$d".log \
--log-level 'debug' --capture-output \ --log-level 'debug' --capture-output \
--error-logfile log/error_"$d".log 'dashboard:app' --error-logfile log/error_"$d".log 'dashboard:app'
printf "[WGDashboard] Log files is under ./log\n" printf "[WGDashboard] Log files is under ./log\n"
@ -255,7 +244,7 @@ gunicorn_start () {
} }
gunicorn_stop () { gunicorn_stop () {
kill $(cat ./gunicorn.pid) sudo kill $(cat ./gunicorn.pid)
} }
start_wgd () { start_wgd () {
@ -274,30 +263,27 @@ stop_wgd() {
start_wgd_debug() { start_wgd_debug() {
printf "%s\n" "$dashes" printf "%s\n" "$dashes"
_checkWireguard _checkWireguard
printf "| Starting WGDashboard in the foreground. |\n" printf "[WGDashboard] Starting WGDashboard in the foreground.\n"
sudo ./venv/bin/python3 "$app_name" sudo "$venv_python" "$app_name"
printf "%s\n" "$dashes" printf "%s\n" "$dashes"
} }
update_wgd() { update_wgd() {
new_ver=$(python3 -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'])") new_ver=$(python3 -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" printf "%s\n" "$dashes"
printf "| Are you sure you want to update to the %s? (Y/N): " "$new_ver" printf "[WGDashboard] Are you sure you want to update to the %s? (Y/N): " "$new_ver"
read up read up
if [ "$up" = "Y" ]; then if [ "$up" = "Y" ] || [ "$up" = "y" ]; then
printf "| Shutting down WGDashboard... |\n" printf "[WGDashboard] Shutting down WGDashboard\n"
if check_wgd_status; then if check_wgd_status; then
stop_wgd stop_wgd
fi fi
mv wgd.sh wgd.sh.old mv wgd.sh wgd.sh.old
printf "| Downloading %s from GitHub... |\n" "$new_ver" printf "[WGDashboard] Downloading %s from GitHub..." "$new_ver"
git stash > /dev/null 2>&1 { date; git stash; git pull https://github.com/donaldzou/WGDashboard.git $new_ver --force; } >> ./log/update.txt
git pull https://github.com/donaldzou/WGDashboard.git $new_ver --force > /dev/null 2>&1 chmod +x ./wgd.sh
printf "| Upgrading pip |\n" sudo ./wgd.sh install
python3 -m pip install -U pip --root-user-action > /dev/null 2>&1 printf "[WGDashboard] Update completed!\n"
printf "| Installing latest Python dependencies |\n"
python3 -m pip install -U -r requirements.txt --root-user-action > /dev/null 2>&1
printf "| Update Successfully! |\n"
printf "%s\n" "$dashes" printf "%s\n" "$dashes"
rm wgd.sh.old rm wgd.sh.old
else else
@ -315,7 +301,7 @@ if [ "$#" != 1 ];
if [ "$1" = "start" ]; then if [ "$1" = "start" ]; then
if check_wgd_status; then if check_wgd_status; then
printf "%s\n" "$dashes" printf "%s\n" "$dashes"
printf "| WGDashboard is already running. |\n" printf "[WGDashboard] WGDashboard is already running.\n"
printf "%s\n" "$dashes" printf "%s\n" "$dashes"
else else
start_wgd start_wgd
@ -324,11 +310,11 @@ if [ "$#" != 1 ];
if check_wgd_status; then if check_wgd_status; then
printf "%s\n" "$dashes" printf "%s\n" "$dashes"
stop_wgd stop_wgd
printf "| WGDashboard is stopped. |\n" printf "[WGDashboard] WGDashboard is stopped.\n"
printf "%s\n" "$dashes" printf "%s\n" "$dashes"
else else
printf "%s\n" "$dashes" printf "%s\n" "$dashes"
printf "| WGDashboard is not running. |\n" printf "[WGDashboard] WGDashboard is not running.\n"
printf "%s\n" "$dashes" printf "%s\n" "$dashes"
fi fi
elif [ "$1" = "update" ]; then elif [ "$1" = "update" ]; then