filebrowser.sh 2.2 KB

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