You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
264 lines
6.4 KiB
Bash
264 lines
6.4 KiB
Bash
#!/usr/bin/env sh
|
|
set -f
|
|
#set -x
|
|
|
|
MainMenu="Install/Tools/Download/Test/Dump"
|
|
|
|
Install="Back/Install_this_script_to_disk/Docker/multilib"
|
|
Docker="Back/Install_docker/Change_storage_driver"
|
|
Install_docker() { $dlcmd - -q https://get.docker.com | $rootcmd sh; }
|
|
|
|
Tools="Back/File_browser"
|
|
File_browser() {
|
|
MODE="File_browser"
|
|
FILE_PATH="$FILE_PATH/$1"
|
|
list=$(ls -ha "$FILE_PATH")
|
|
logprint "$list"
|
|
newlist=$(split_ls "$list")
|
|
newlist=$(split_ls2 "$newlist")
|
|
logprint "$newlist"
|
|
drawmenu $newlist
|
|
|
|
}
|
|
Download="Back/Utilities/ISOs/Configs/NAS_Browser"
|
|
Utilities="Back/Proxmox_post_install_script"
|
|
Proxmox_post_install_script() { $dlcmd - -q deck.sh/p; $rootcmd bash; }
|
|
NAS_Browser() { curl -k "sftp://$SFTP_HOST:$SFTP_PORT/$SFTP_START/$1" --user "$SFTP_USER:$SFTP_PASS"; }
|
|
#MODE="Nas_Browser";
|
|
Test="Back/Network_connectivity"
|
|
Network_connectivity() { (ping 1.1.1.1 -c3 || (echo "No network access!" && sleep 1.5)) && (ping deck.sh -c3 || (echo "No DNS!" && sleep 1.5)) && echo "Looks good!" && sleep 1; }
|
|
|
|
|
|
|
|
STARTINGMENU=$MainMenu # note: cannot be a child unless it specifies the parent name instead of "Back"
|
|
SFTP_HOST=git.deck.sh
|
|
SFTP_PORT=32850
|
|
SFTP_USER=cole
|
|
SFTP_PASS=
|
|
SFTP_START=/mnt/dalek
|
|
FILE_PATH=$(pwd)
|
|
|
|
#SIZE=$(stty size)
|
|
#WIDTH=$(printf "$SIZE" | cut -d' ' -f2)
|
|
#if [ "$WIDTH" = "" ]; then
|
|
WIDTH=1000
|
|
#HEIGHT=$(printf "$SIZE" | cut -d' ' -f1)
|
|
#if [ "$HEIGHT" = "" ]; then
|
|
HEIGHT=1000
|
|
# echo $WIDTH $HEIGHT
|
|
oldifs=$IFS
|
|
Back="Back" # Internal use, do not change
|
|
MENUSTACK="$STARTINGMENU" # initialize stack
|
|
CURRENTMENU="$STARTINGMENU" # initialize current menu
|
|
MENUSIZE=0
|
|
MODE=""
|
|
logprint() {
|
|
echo "$@" >> log.txt
|
|
}
|
|
getNth() { shift "$(( $1 + 1 ))"; printf '%s\n' "$1"; }
|
|
getLast() { getNth "$(( $(length "$@") - 1 ))" "$@"; }
|
|
length() { echo "$#"; }
|
|
deleteFirst() {
|
|
shift
|
|
MENUSTACK=""
|
|
for menu in $@; do
|
|
if [ "$MENUSTACK" = "" ]; then
|
|
MENUSTACK="$menu"
|
|
else
|
|
MENUSTACK="$MENUSTACK|$menu"
|
|
fi
|
|
done
|
|
logprint "Deleted entry. State: $MENUSTACK"
|
|
}
|
|
addFirst() { MENUSTACK="$1|$MENUSTACK"; }
|
|
|
|
clrline() {
|
|
printf "\33[2K\r"
|
|
}
|
|
|
|
relamove() {
|
|
# relamove 1 -2 = move right 1 and down 2
|
|
if [ "$2" -gt 0 ]; then
|
|
printf "\033["$2"A"
|
|
elif [ "$2" -lt 0 ]; then
|
|
invert=$(echo $2 | cut -d'-' -f 2)
|
|
printf "\033["$invert"B"
|
|
fi
|
|
if [ "$1" -gt 0 ]; then
|
|
printf "\033["$1"C"
|
|
elif [ "$1" -lt 0 ]; then
|
|
invert=$(echo $1 | cut -d'-' -f 2)
|
|
printf "\033["$invert"D"
|
|
fi
|
|
}
|
|
|
|
menumove() {
|
|
if [ "$1" -lt 0 ] && [ $(($MENUPOS - $1)) -lt $MENUSIZE ]; then
|
|
printf " "
|
|
relamove -1 $1
|
|
printf "*"
|
|
relamove -1 0
|
|
MENUPOS=$(($MENUPOS - $1))
|
|
elif [ "$1" -gt 0 ] && [ $(($MENUPOS - $1)) -ge 0 ]; then
|
|
printf " "
|
|
relamove -1 $1
|
|
printf "*"
|
|
relamove -1 0
|
|
MENUPOS=$(($MENUPOS - $1))
|
|
fi
|
|
}
|
|
|
|
split() {
|
|
old_ifs=$IFS
|
|
IFS=$2
|
|
set -- $1
|
|
printf '%s ' "$@"
|
|
IFS=$old_ifs
|
|
}
|
|
|
|
split_ls() {
|
|
old_ifs=$IFS
|
|
IFS=$'\n'
|
|
set -- $1
|
|
printf '%s/' "$@"
|
|
IFS=$old_ifs
|
|
}
|
|
split_ls2() {
|
|
old_ifs=$IFS
|
|
IFS=' '
|
|
set -- $1
|
|
printf '%s_' "$@"
|
|
IFS=$old_ifs
|
|
}
|
|
|
|
# Initial values
|
|
|
|
|
|
drawmenu() {
|
|
# initialize menu only. too expensize to do each time
|
|
IFS="|"
|
|
if [ "$1" = "Back" ] && [ "$(length $MENUSTACK)" -gt 1 ]; then
|
|
deleteFirst $MENUSTACK
|
|
elif [ "$(getNth 0 \"$MENUSTACK\")" != "$1" ] && [ "$1" != "Back" ] && [ "$MODE" = "" ]; then
|
|
addFirst $1
|
|
logprint "Adding $1"
|
|
logprint "State: $MENUSTACK"
|
|
fi
|
|
if [ "$MODE" != "" ]; then
|
|
CURRENTMENU="$1" # when not using the stack, pull directly from the arg list
|
|
else
|
|
CURRENTMENU="$(getNth 0 $MENUSTACK)"
|
|
fi
|
|
logprint "Drawing $CURRENTMENU"
|
|
OLDMENUSIZE=$MENUSIZE
|
|
MENUSIZE=0
|
|
MENUPOS=0
|
|
relamove -$WIDTH $HEIGHT
|
|
IFS="/"
|
|
for line in $CURRENTMENU; do
|
|
MENUSIZE=$(($MENUSIZE + 1))
|
|
relamove -$WIDTH -1
|
|
clrline
|
|
relamove 5 0
|
|
IFS=$oldifs
|
|
split "$line" _
|
|
IFS="/"
|
|
#printf "$line"
|
|
done
|
|
logprint "Old size: $OLDMENUSIZE, New size $MENUSIZE"
|
|
IFS=$oldifs
|
|
if [ "$OLDMENUSIZE" -gt "$MENUSIZE" ]; then
|
|
for line in $(seq $(($OLDMENUSIZE - $MENUSIZE))); do
|
|
relamove 0 -1
|
|
clrline
|
|
done
|
|
relamove 0 $(($OLDMENUSIZE - $MENUSIZE + 1))
|
|
fi
|
|
relamove -$WIDTH $MENUSIZE
|
|
relamove 4 -1
|
|
printf "*"
|
|
relamove -1 0
|
|
}
|
|
|
|
|
|
selected() {
|
|
IFS="/"
|
|
temp_pos_count=0
|
|
for line in $CURRENTMENU; do
|
|
if [ "$temp_pos_count" = "$MENUPOS" ]; then
|
|
IFS=$oldifs
|
|
logprint "Got: $(eval echo \"\$$line\")"
|
|
if [ "$MODE" != "" ]; then
|
|
$MODE "$line"
|
|
elif [ "$(eval echo \"\$$line\")" = "" ]; then
|
|
clear
|
|
"$line" # execute function
|
|
sleep 0.5
|
|
clear
|
|
IFS="|"
|
|
deleteFirst $MENUSTACK
|
|
IFS=$oldifs
|
|
drawmenu "$CURRENTMENU"
|
|
else
|
|
drawmenu "$(eval echo \"\$$line\")"
|
|
fi
|
|
break
|
|
fi
|
|
temp_pos_count=$(($temp_pos_count + 1))
|
|
done
|
|
IFS=$oldifs
|
|
}
|
|
|
|
# check for downloader to use
|
|
if which curl; then
|
|
dlcmd="curl -fsSL -o"
|
|
elif which wget; then
|
|
dlcmd="wget -O"
|
|
else
|
|
dlcmd="echo No downloader found!"
|
|
fi
|
|
|
|
# check for root util
|
|
if [ "$USER" = "root" ]; then
|
|
rootcmd=""
|
|
elif which sudo; then
|
|
rootcmd="sudo"
|
|
elif which doas; then
|
|
rootcmd="doas"
|
|
else
|
|
dlcmd="echo No root access possible!"
|
|
fi
|
|
|
|
# Startup: clear screen and load main menu
|
|
clear
|
|
drawmenu "$STARTINGMENU"
|
|
|
|
|
|
|
|
# input loop
|
|
while read -rsn1 ui </dev/tty; do
|
|
case "$ui" in
|
|
$'\x1b') # Handle ESC sequence.
|
|
# Flush read. We account for sequences for Fx keys as
|
|
# well. 6 should suffice far more then enough.
|
|
read -rsn1 -t 0.01 tmp </dev/tty
|
|
if [ "$tmp" == "[" ]; then
|
|
read -rsn1 -t 0.01 tmp </dev/tty
|
|
case "$tmp" in
|
|
"A") menumove 1;; # up
|
|
"B") menumove -1;; # down
|
|
"C") selected;; # right
|
|
"D") drawmenu "Back" ;; # left
|
|
esac
|
|
fi
|
|
# Flush "stdin"
|
|
read -rsn5 -t 0.01 </dev/tty
|
|
;;
|
|
# Other one byte (char) cases. Here only quit.
|
|
q) break;;
|
|
"") selected
|
|
esac
|
|
done
|
|
|
|
clear
|