filebrowser-v3.sh 2.1 KB

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