filebrowser.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. function header_info {
  7. clear
  8. cat <<"EOF"
  9. _______ __ ____
  10. / ____(_) /__ / __ )_________ _ __________ _____
  11. / /_ / / / _ \/ __ / ___/ __ \ | /| / / ___/ _ \/ ___/
  12. / __/ / / / __/ /_/ / / / /_/ / |/ |/ (__ ) __/ /
  13. /_/ /_/_/\___/_____/_/ \____/|__/|__/____/\___/_/
  14. EOF
  15. }
  16. IP=$(hostname -I | awk '{print $1}')
  17. YW=$(echo "\033[33m")
  18. BL=$(echo "\033[36m")
  19. RD=$(echo "\033[01;31m")
  20. BGN=$(echo "\033[4;92m")
  21. GN=$(echo "\033[1;92m")
  22. DGN=$(echo "\033[32m")
  23. CL=$(echo "\033[m")
  24. BFR="\\r\\033[K"
  25. HOLD="-"
  26. CM="${GN}✓${CL}"
  27. APP="FileBrowser"
  28. hostname="$(hostname)"
  29. header_info
  30. if [ -f /root/filebrowser.db ]; then
  31. read -r -p "Would you like to uninstall ${APP} on $hostname.? <y/N> " prompt
  32. if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
  33. systemctl disable -q --now filebrowser.service
  34. rm -rf /usr/local/bin/filebrowser /root/filebrowser.db /etc/systemd/system/filebrowser.service
  35. echo "$APP Removed"
  36. sleep 2
  37. clear
  38. exit
  39. else
  40. clear
  41. exit
  42. fi
  43. fi
  44. while true; do
  45. read -p "This will Install ${APP} on $hostname. Proceed(y/n)?" yn
  46. case $yn in
  47. [Yy]*) break ;;
  48. [Nn]*) exit ;;
  49. *) echo "Please answer yes or no." ;;
  50. esac
  51. done
  52. header_info
  53. function msg_info() {
  54. local msg="$1"
  55. echo -ne " ${HOLD} ${YW}${msg}..."
  56. }
  57. function msg_ok() {
  58. local msg="$1"
  59. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  60. }
  61. read -r -p "Would you like to use No Authentication? <y/N> " prompt
  62. msg_info "Installing ${APP}"
  63. RELEASE=$(curl -fsSL https://api.github.com/repos/filebrowser/filebrowser/releases/latest | grep -o '"tag_name": ".*"' | sed 's/"//g' | sed 's/tag_name: //g')
  64. curl -fsSL https://github.com/filebrowser/filebrowser/releases/download/$RELEASE/linux-amd64-filebrowser.tar.gz | tar -xzv -C /usr/local/bin &>/dev/null
  65. if [[ "${prompt,,}" =~ ^(y|yes)$ ]]; then
  66. filebrowser config init -a '0.0.0.0' &>/dev/null
  67. filebrowser config set -a '0.0.0.0' &>/dev/null
  68. filebrowser config init --auth.method=noauth &>/dev/null
  69. filebrowser config set --auth.method=noauth &>/dev/null
  70. filebrowser users add ID 1 --perm.admin &>/dev/null
  71. else
  72. filebrowser config init -a '0.0.0.0' &>/dev/null
  73. filebrowser config set -a '0.0.0.0' &>/dev/null
  74. filebrowser users add admin changeme --perm.admin &>/dev/null
  75. fi
  76. msg_ok "Installed ${APP} on $hostname"
  77. msg_info "Creating Service"
  78. cat <<EOF >/etc/systemd/system/filebrowser.service
  79. [Unit]
  80. Description=Filebrowser
  81. After=network-online.target
  82. [Service]
  83. User=root
  84. WorkingDirectory=/root/
  85. ExecStart=/usr/local/bin/filebrowser -r /
  86. [Install]
  87. WantedBy=default.target
  88. EOF
  89. systemctl enable -q --now filebrowser.service
  90. msg_ok "Created Service"
  91. msg_ok "Completed Successfully!\n"
  92. echo -e "${APP} should be reachable by going to the following URL.
  93. ${BL}http://$IP:8080${CL} \n"