filebrowser.sh 2.2 KB

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