Skip to content

Commit 865e6fd

Browse files
authored
Feature: Add optional Port for Filebrowser (#2224)
1 parent a1dd57d commit 865e6fd

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

misc/filebrowser.sh

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ INSTALL_PATH="/usr/local/bin/filebrowser"
2828
SERVICE_PATH="/etc/systemd/system/filebrowser.service"
2929
DB_PATH="/var/lib/filebrowser/filebrowser.db"
3030
IP=$(hostname -I | awk '{print $1}')
31+
DEFAULT_PORT=8080
32+
3133
header_info
3234

3335
function msg_info() {
@@ -52,7 +54,6 @@ if [ -f "$INSTALL_PATH" ]; then
5254
msg_info "Uninstalling ${APP}"
5355
systemctl disable -q --now filebrowser.service
5456
rm -f "$INSTALL_PATH" "$DB_PATH" "$SERVICE_PATH"
55-
5657
msg_ok "${APP} has been uninstalled."
5758
exit 0
5859
fi
@@ -70,6 +71,9 @@ if [ -f "$INSTALL_PATH" ]; then
7071
fi
7172

7273
echo -e "${YW}⚠️ ${APP} is not installed.${CL}"
74+
read -r -p "Enter port number (Default: ${DEFAULT_PORT}): " PORT
75+
PORT=${PORT:-$DEFAULT_PORT}
76+
7377
read -r -p "Would you like to install ${APP}? (y/n): " install_prompt
7478
if [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then
7579
msg_info "Installing ${APP}"
@@ -86,27 +90,27 @@ if [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then
8690
read -r -p "Would you like to use No Authentication? (y/N): " auth_prompt
8791
if [[ "${auth_prompt,,}" =~ ^(y|yes)$ ]]; then
8892
msg_info "Configuring No Authentication"
89-
filebrowser config init -a '0.0.0.0' --database /var/lib/filebrowser/filebrowser.db &>/dev/null
90-
filebrowser config set -a '0.0.0.0' --auth.method=noauth --database /var/lib/filebrowser/filebrowser.db &>/dev/null
93+
filebrowser config init -a '0.0.0.0' -p "$PORT" --database "$DB_PATH" &>/dev/null
94+
filebrowser config set -a '0.0.0.0' -p "$PORT" --auth.method=noauth --database "$DB_PATH" &>/dev/null
9195
msg_ok "No Authentication configured"
9296
else
9397
msg_info "Setting up default authentication"
94-
filebrowser config init -a '0.0.0.0' --database /var/lib/filebrowser/filebrowser.db &>/dev/null
95-
filebrowser config set -a '0.0.0.0' --database /var/lib/filebrowser/filebrowser.db &>/dev/null
96-
filebrowser users add admin helper-scripts.com --perm.admin --database /var/lib/filebrowser/filebrowser.db &>/dev/null
98+
filebrowser config init -a '0.0.0.0' -p "$PORT" --database "$DB_PATH" &>/dev/null
99+
filebrowser config set -a '0.0.0.0' -p "$PORT" --database "$DB_PATH" &>/dev/null
100+
filebrowser users add admin helper-scripts.com --perm.admin --database "$DB_PATH" &>/dev/null
97101
msg_ok "Default authentication configured (admin:helper-scripts.com)"
98102
fi
99103

100104
msg_info "Creating service"
101-
cat <<EOF >/etc/systemd/system/filebrowser.service
105+
cat <<EOF > "$SERVICE_PATH"
102106
[Unit]
103107
Description=Filebrowser
104108
After=network-online.target
105109
106110
[Service]
107111
User=root
108112
WorkingDirectory=/var/lib/filebrowser/
109-
ExecStart=/usr/local/bin/filebrowser -r / --database /var/lib/filebrowser/filebrowser.db
113+
ExecStart=/usr/local/bin/filebrowser -r / --database "$DB_PATH" -p "$PORT"
110114
Restart=always
111115
112116
[Install]
@@ -115,7 +119,7 @@ EOF
115119
systemctl enable -q --now filebrowser.service
116120
msg_ok "Service created successfully"
117121

118-
echo -e "${CM} ${GN}${APP} is reachable at: ${BL}http://$IP:8080${CL}"
122+
echo -e "${CM} ${GN}${APP} is reachable at: ${BL}http://$IP:$PORT${CL}"
119123
else
120124
echo -e "${YW}⚠️ Installation skipped. Exiting.${CL}"
121125
exit 0

0 commit comments

Comments
 (0)