Skip to content

Commit

Permalink
added install and uninstall to wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
Barakudum committed Jan 31, 2024
1 parent b881fbd commit 658f230
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 11 deletions.
93 changes: 82 additions & 11 deletions build-files/wizard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ fi

ROOT="$(realpath "$(dirname "$(realpath "$0")")/")"


function info() {
echo -e "\e[33m" "$@" "\e[39m"
}


# shellcheck disable=SC2120
function wiz_ask_directory {
function wiz_ask_directory() {
SELECTED="."
TITLE="Jarklin-Wizard"
TEXT="Select a directory"

Expand All @@ -30,13 +37,17 @@ function wiz_ask_directory {
shift; shift;
;;
*)
echo "unknown parameter '$1'"
exit 1
if [ "$SELECTED" = "." ]; then
SELECTED="$1"
else
echo "unknown parameter '$1'"
exit 1
fi
;;
esac
done

SELECTED=$(realpath ".")
SELECTED=$(realpath "$SELECTED")
while true; do
OPTIONS=("." "." ".." "..")
for entry in "$SELECTED"/*/; do
Expand All @@ -58,26 +69,84 @@ function wiz_ask_directory {


function wiz_download_jarklin() {
wget -q "https://github.com/jarklin/jarklin/releases/download/latest/jarklin.tgz" -O "$1"
wget "https://github.com/jarklin/jarklin/releases/download/latest/jarklin.tgz" -O "$1"
}

function wiz_download_web_ui() {
wget -q "https://github.com/jarklin/jarklin-web/releases/download/latest/web-ui.tgz" -O "$1"
wget "https://github.com/jarklin/jarklin-web/releases/download/latest/web-ui.tgz" -O "$1"
}

function wizard_install() {
whiptail --title "Jarklin-Wizard - Install" --msgbox "Install" 20 60
FEATURES=$(
whiptail --title "Jarklin-Wizard - Install" --checklist "Which features do you want to install?" 20 60 10 --notags --separate-output \
"jarklin" "Jarklin server/backend" ON \
"web-ui" "Default WEB-UI" ON \
3>&2 2>&1 1>&3
# "web.service" "jarklin-server.service" OFF \
# "cache.service" "jarklin-cache.service" OFF \
)
JARKLIN=false
WEB_UI=false
# WEB_SERVICE=false
# CACHE_SERVICE=false
for FEATURE in $FEATURES; do
case $FEATURE in
"jarklin") JARKLIN=true ;;
"web-ui") WEB_UI=true ;;
# "web.service") WEB_SERVICE=true ;;
# "cache.service") CACHE_SERVICE=true ;;
esac
done

if [ $JARKLIN = true ] && [ -d "./jarklin/" ] && ! whiptail --yesno "./jarklin/ seems to exist. It will be overwritten." 20 60 --yes-button "Continue" --no-button "Cancel"; then
return 0;
fi

if [ $JARKLIN = true ]; then
JARKLIN_ARCHIVE="./jarklin.tgz"
info "Downloading Jarklin..."
wiz_download_jarklin "$JARKLIN_ARCHIVE"
info "Extracting Jarklin..."
tar -xf "$JARKLIN_ARCHIVE" -C .
rm "$JARKLIN_ARCHIVE"

info "Installing dependencies..."
rm -rf "jarklin/_deps/"
mkdir -p "jarklin/_deps/"
python3 -m pip install -r "jarklin/requirements.txt" -t "jarklin/_deps/" --disable-pip-version-check
fi

if [ $WEB_UI = true ]; then
WEB_UI_ARCHIVE="./jarklin.tgz"
WEB_UI_DIR="./jarklin/web/web-ui/"
info "Downloading Web-UI..."
wiz_download_web_ui "$WEB_UI_ARCHIVE"
mkdir -p "$WEB_UI_DIR"
info "Extracting Web-UI..."
tar -xf "$WEB_UI_ARCHIVE" -C "$WEB_UI_DIR"
rm "$WEB_UI_ARCHIVE"
fi

whiptail --title "Jarklin-Wizard - Install" --msgbox "Jarklin was successfully installed" 20 60
}

function wizard_update() {
CWD=$(pwd)
cd "$ROOT"
whiptail --title "Jarklin-Wizard - Update" --msgbox "Update" 20 60
cd "$CWD"
whiptail --title "Jarklin-Wizard - Update" --msgbox "Update is currently not available.\nReinstalling should do the job." 20 60
}

function wizard_uninstall() {
whiptail --title "Jarklin-Wizard - Uninstall" --msgbox "Uninstall" 20 60
# whiptail --title "Jarklin-Wizard - Uninstall" --msgbox "Uninstall" 20 60
cd "$ROOT/../" # folder above jarklin
# cant find jarklin-executable which means was started via `wget wizard.sh | bash` or so
if [ ! -f "./jarklin/jarklin" ] || [ "$("./jarklin/jarklin" --verify-jarklin)" != "jarklin" ]; then
whiptail --title "Jarklin-Wizard - Uninstall" --msgbox "Could not find Jarklin installation\n($(pwd))" 20 60
return 0
fi
if whiptail --title "$TITLE - Auth" --yesno "Are you sure want to uninstall Jarklin?\n$ROOT" 20 60; then
rm -rf "./jarklin"
whiptail --title "Jarklin-Wizard - Uninstall" --msgbox "Jarklin was uninstalled" 20 60
fi
}

function wizard_create_config() {
Expand Down Expand Up @@ -165,7 +234,9 @@ Blacklist: directories or files are disabled/hidden" --yes-button "Whitelist" --
}

function wizard_main() {
CWD="$(pwd)"
while true; do
cd "$CWD"
CHOICE=$(whiptail --title "Jarklin-Wizard" --menu "What do you want to do?" 20 60 10 --nocancel --notags \
"install" "Install Jarklin" \
"update" "Update Jarklin" \
Expand Down
9 changes: 9 additions & 0 deletions src/jarklin/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import sys
import argparse
import argparse as ap
from . import __version__
from . import _commands as commands
Expand All @@ -12,11 +13,19 @@
except ModuleNotFoundError:
pass


class VerifyJarklinAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
sys.stdout.write("jarklin")
parser.exit()


# ==================================================================================================================== #

parser = ap.ArgumentParser('jarklin', description=__doc__, formatter_class=ap.ArgumentDefaultsHelpFormatter)
parser.set_defaults(fn=parser.print_help)
parser.add_argument('-v', '--version', action='version', version=__version__)
parser.add_argument('--verify-jarklin', action=VerifyJarklinAction)
subparsers = parser.add_subparsers()

# ==================================================================================================================== #
Expand Down

0 comments on commit 658f230

Please sign in to comment.