Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add optional Port for Filebrowser #2224

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions misc/filebrowser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ INSTALL_PATH="/usr/local/bin/filebrowser"
SERVICE_PATH="/etc/systemd/system/filebrowser.service"
DB_PATH="/var/lib/filebrowser/filebrowser.db"
IP=$(hostname -I | awk '{print $1}')
DEFAULT_PORT=8080

header_info

function msg_info() {
Expand All @@ -52,7 +54,6 @@ if [ -f "$INSTALL_PATH" ]; then
msg_info "Uninstalling ${APP}"
systemctl disable -q --now filebrowser.service
rm -f "$INSTALL_PATH" "$DB_PATH" "$SERVICE_PATH"

msg_ok "${APP} has been uninstalled."
exit 0
fi
Expand All @@ -70,6 +71,9 @@ if [ -f "$INSTALL_PATH" ]; then
fi

echo -e "${YW}⚠️ ${APP} is not installed.${CL}"
read -r -p "Enter port number (Default: ${DEFAULT_PORT}): " PORT
PORT=${PORT:-$DEFAULT_PORT}

read -r -p "Would you like to install ${APP}? (y/n): " install_prompt
if [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then
msg_info "Installing ${APP}"
Expand All @@ -86,27 +90,27 @@ if [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then
read -r -p "Would you like to use No Authentication? (y/N): " auth_prompt
if [[ "${auth_prompt,,}" =~ ^(y|yes)$ ]]; then
msg_info "Configuring No Authentication"
filebrowser config init -a '0.0.0.0' --database /var/lib/filebrowser/filebrowser.db &>/dev/null
filebrowser config set -a '0.0.0.0' --auth.method=noauth --database /var/lib/filebrowser/filebrowser.db &>/dev/null
filebrowser config init -a '0.0.0.0' -p "$PORT" --database "$DB_PATH" &>/dev/null
filebrowser config set -a '0.0.0.0' -p "$PORT" --auth.method=noauth --database "$DB_PATH" &>/dev/null
msg_ok "No Authentication configured"
else
msg_info "Setting up default authentication"
filebrowser config init -a '0.0.0.0' --database /var/lib/filebrowser/filebrowser.db &>/dev/null
filebrowser config set -a '0.0.0.0' --database /var/lib/filebrowser/filebrowser.db &>/dev/null
filebrowser users add admin helper-scripts.com --perm.admin --database /var/lib/filebrowser/filebrowser.db &>/dev/null
filebrowser config init -a '0.0.0.0' -p "$PORT" --database "$DB_PATH" &>/dev/null
filebrowser config set -a '0.0.0.0' -p "$PORT" --database "$DB_PATH" &>/dev/null
filebrowser users add admin helper-scripts.com --perm.admin --database "$DB_PATH" &>/dev/null
msg_ok "Default authentication configured (admin:helper-scripts.com)"
fi

msg_info "Creating service"
cat <<EOF >/etc/systemd/system/filebrowser.service
cat <<EOF > "$SERVICE_PATH"
[Unit]
Description=Filebrowser
After=network-online.target

[Service]
User=root
WorkingDirectory=/var/lib/filebrowser/
ExecStart=/usr/local/bin/filebrowser -r / --database /var/lib/filebrowser/filebrowser.db
ExecStart=/usr/local/bin/filebrowser -r / --database "$DB_PATH" -p "$PORT"
Restart=always

[Install]
Expand All @@ -115,7 +119,7 @@ EOF
systemctl enable -q --now filebrowser.service
msg_ok "Service created successfully"

echo -e "${CM} ${GN}${APP} is reachable at: ${BL}http://$IP:8080${CL}"
echo -e "${CM} ${GN}${APP} is reachable at: ${BL}http://$IP:$PORT${CL}"
else
echo -e "${YW}⚠️ Installation skipped. Exiting.${CL}"
exit 0
Expand Down