filebrowser.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. cat <<"EOF"
  8. _______ __ ____
  9. / ____(_) /__ / __ )_________ _ __________ _____
  10. / /_ / / / _ \/ __ / ___/ __ \ | /| / / ___/ _ \/ ___/
  11. / __/ / / / __/ /_/ / / / /_/ / |/ |/ (__ ) __/ /
  12. /_/ /_/_/\___/_____/_/ \____/|__/|__/____/\___/_/
  13. EOF
  14. }
  15. IP=$(hostname -I | awk '{print $1}')
  16. YW=$(echo "\033[33m")
  17. BL=$(echo "\033[36m")
  18. RD=$(echo "\033[01;31m")
  19. BGN=$(echo "\033[4;92m")
  20. GN=$(echo "\033[1;92m")
  21. DGN=$(echo "\033[32m")
  22. CL=$(echo "\033[m")
  23. BFR="\\r\\033[K"
  24. HOLD="-"
  25. CM="${GN}✓${CL}"
  26. APP="FileBrowser"
  27. hostname="$(hostname)"
  28. set -o errexit
  29. set -o errtrace
  30. set -o nounset
  31. set -o pipefail
  32. shopt -s expand_aliases
  33. alias die='EXIT=$? LINE=$LINENO error_exit'
  34. trap die ERR
  35. function error_exit() {
  36. trap - ERR
  37. local reason="Unknown failure occured."
  38. local msg="${1:-$reason}"
  39. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  40. echo -e "$flag $msg" 1>&2
  41. exit $EXIT
  42. }
  43. clear
  44. header_info
  45. while true; do
  46. read -p "This will Install ${APP} on $hostname. Proceed(y/n)?" yn
  47. case $yn in
  48. [Yy]*) break ;;
  49. [Nn]*) exit ;;
  50. *) echo "Please answer yes or no." ;;
  51. esac
  52. done
  53. clear
  54. header_info
  55. function msg_info() {
  56. local msg="$1"
  57. echo -ne " ${HOLD} ${YW}${msg}..."
  58. }
  59. function msg_ok() {
  60. local msg="$1"
  61. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  62. }
  63. msg_info "Installing ${APP}"
  64. bash <(curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh) &>/dev/null
  65. filebrowser config init -a '0.0.0.0' &>/dev/null
  66. filebrowser config set -a '0.0.0.0' &>/dev/null
  67. filebrowser users add admin changeme --perm.admin &>/dev/null
  68. msg_ok "Installed ${APP} on $hostname"
  69. msg_info "Creating Service"
  70. service_path="/etc/systemd/system/filebrowser.service"
  71. echo "[Unit]
  72. Description=Filebrowser
  73. After=network-online.target
  74. [Service]
  75. User=root
  76. WorkingDirectory=/root/
  77. ExecStart=/usr/local/bin/filebrowser -r /
  78. [Install]
  79. WantedBy=default.target" >$service_path
  80. systemctl enable --now filebrowser.service &>/dev/null
  81. msg_ok "Created Service"
  82. msg_ok "Completed Successfully!\n"
  83. echo -e "${APP} should be reachable by going to the following URL.
  84. ${BL}http://$IP:8080${CL} \n"