From 8b0f6b27fe74922614bd7607c82950f4aa6fe91f Mon Sep 17 00:00:00 2001 From: tteckster Date: Sun, 8 Oct 2023 21:19:40 -0400 Subject: [PATCH] Update filebrowser.sh - Uninstall by re-executing the script - Option to use No Authentication --- misc/filebrowser.sh | 67 +++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/misc/filebrowser.sh b/misc/filebrowser.sh index b4e40fd1..6a7325b4 100644 --- a/misc/filebrowser.sh +++ b/misc/filebrowser.sh @@ -6,13 +6,14 @@ # https://github.com/tteck/Proxmox/raw/main/LICENSE function header_info { + clear cat <<"EOF" - _______ __ ____ + _______ __ ____ / ____(_) /__ / __ )_________ _ __________ _____ / /_ / / / _ \/ __ / ___/ __ \ | /| / / ___/ _ \/ ___/ - / __/ / / / __/ /_/ / / / /_/ / |/ |/ (__ ) __/ / -/_/ /_/_/\___/_____/_/ \____/|__/|__/____/\___/_/ - + / __/ / / / __/ /_/ / / / /_/ / |/ |/ (__ ) __/ / +/_/ /_/_/\___/_____/_/ \____/|__/|__/____/\___/_/ + EOF } IP=$(hostname -I | awk '{print $1}') @@ -28,24 +29,21 @@ HOLD="-" CM="${GN}✓${CL}" APP="FileBrowser" hostname="$(hostname)" -set -o errexit -set -o errtrace -set -o nounset -set -o pipefail -shopt -s expand_aliases -alias die='EXIT=$? LINE=$LINENO error_exit' -trap die ERR - -function error_exit() { - trap - ERR - local reason="Unknown failure occured." - local msg="${1:-$reason}" - local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE" - echo -e "$flag $msg" 1>&2 - exit $EXIT -} -clear header_info +if [ -f /root/filebrowser.db ]; then + read -r -p "Would you like to uninstall ${APP} on $hostname.? " prompt + if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then + systemctl disable -q --now filebrowser.service + rm -rf /usr/local/bin/filebrowser /root/filebrowser.db /etc/systemd/system/filebrowser.service + echo "$APP Removed" + sleep 2 + clear + exit + else + clear + exit + fi +fi while true; do read -p "This will Install ${APP} on $hostname. Proceed(y/n)?" yn case $yn in @@ -54,7 +52,6 @@ while true; do *) echo "Please answer yes or no." ;; esac done -clear header_info function msg_info() { local msg="$1" @@ -66,17 +63,27 @@ function msg_ok() { echo -e "${BFR} ${CM} ${GN}${msg}${CL}" } +read -r -p "Would you like to use No Authentication? " prompt msg_info "Installing ${APP}" RELEASE=$(curl -fsSL https://api.github.com/repos/filebrowser/filebrowser/releases/latest | grep -o '"tag_name": ".*"' | sed 's/"//g' | sed 's/tag_name: //g') curl -fsSL https://github.com/filebrowser/filebrowser/releases/download/$RELEASE/linux-amd64-filebrowser.tar.gz | tar -xzv -C /usr/local/bin &>/dev/null -filebrowser config init -a '0.0.0.0' &>/dev/null -filebrowser config set -a '0.0.0.0' &>/dev/null -filebrowser users add admin changeme --perm.admin &>/dev/null + +if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then + filebrowser config init -a '0.0.0.0' &>/dev/null + filebrowser config set -a '0.0.0.0' &>/dev/null + filebrowser config init --auth.method=noauth &>/dev/null + filebrowser config set --auth.method=noauth &>/dev/null + filebrowser users add ID 1 --perm.admin &>/dev/null +else + filebrowser config init -a '0.0.0.0' &>/dev/null + filebrowser config set -a '0.0.0.0' &>/dev/null + filebrowser users add admin changeme --perm.admin &>/dev/null +fi msg_ok "Installed ${APP} on $hostname" msg_info "Creating Service" -service_path="/etc/systemd/system/filebrowser.service" -echo "[Unit] +cat </etc/systemd/system/filebrowser.service +[Unit] Description=Filebrowser After=network-online.target @@ -86,9 +93,9 @@ WorkingDirectory=/root/ ExecStart=/usr/local/bin/filebrowser -r / [Install] -WantedBy=default.target" >$service_path - -systemctl enable --now filebrowser.service &>/dev/null +WantedBy=default.target +EOF +systemctl enable -q --now filebrowser.service msg_ok "Created Service" msg_ok "Completed Successfully!\n"