filebrowser.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. RELEASE=$(curl -fsSL https://api.github.com/repos/filebrowser/filebrowser/releases/latest | grep -o '"tag_name": ".*"' | sed 's/"//g' | sed 's/tag_name: //g')
  65. curl -fsSL https://github.com/filebrowser/filebrowser/releases/download/v2.23.0/linux-amd64-filebrowser.tar.gz | tar -xzv -C /usr/local/bin &>/dev/null
  66. filebrowser config init -a '0.0.0.0' &>/dev/null
  67. filebrowser config set -a '0.0.0.0' &>/dev/null
  68. filebrowser users add admin changeme --perm.admin &>/dev/null
  69. msg_ok "Installed ${APP} on $hostname"
  70. msg_info "Creating Service"
  71. service_path="/etc/systemd/system/filebrowser.service"
  72. echo "[Unit]
  73. Description=Filebrowser
  74. After=network-online.target
  75. [Service]
  76. User=root
  77. WorkingDirectory=/root/
  78. ExecStart=/usr/local/bin/filebrowser -r /
  79. [Install]
  80. WantedBy=default.target" >$service_path
  81. systemctl enable --now filebrowser.service &>/dev/null
  82. msg_ok "Created Service"
  83. msg_ok "Completed Successfully!\n"
  84. echo -e "${APP} should be reachable by going to the following URL.
  85. ${BL}http://$IP:8080${CL} \n"