Skip to content

Commit 6de4a81

Browse files
authored
Feature: Filebrowser: support now alpine (#2997)
* Feature: Filebrowser LXC: support now alpine * add alpine bash path to website
1 parent f6a6ca5 commit 6de4a81

File tree

2 files changed

+85
-20
lines changed

2 files changed

+85
-20
lines changed

json/filebrowser.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@
2424
"os": null,
2525
"version": null
2626
}
27+
},
28+
{
29+
"type": "alpine",
30+
"script": "misc/filebrowser.sh",
31+
"resources": {
32+
"cpu": null,
33+
"ram": null,
34+
"hdd": null,
35+
"os": null,
36+
"version": null
37+
}
2738
}
2839
],
2940
"default_credentials": {
@@ -36,4 +47,4 @@
3647
"type": "warning"
3748
}
3849
]
39-
}
50+
}

misc/filebrowser.sh

Lines changed: 73 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ function header_info {
1010
_______ __ ____
1111
/ ____(_) /__ / __ )_________ _ __________ _____
1212
/ /_ / / / _ \/ __ / ___/ __ \ | /| / / ___/ _ \/ ___/
13-
/ __/ / / / __/ /_/ / / / /_/ / |/ |/ (__ ) __/ /
14-
/_/ /_/_/\___/_____/_/ \____/|__/|__/____/\___/_/
13+
/ __/ / / / __/ /_/ / / / /_/ / |/ |/ (__ ) __/ /
14+
/_/ /_/_/\___/_____/_/ \____/|__/|__/____/\___/_/
1515
EOF
1616
}
17+
1718
YW=$(echo "\033[33m")
1819
GN=$(echo "\033[1;92m")
1920
RD=$(echo "\033[01;31m")
@@ -25,11 +26,31 @@ INFO="${BL}ℹ️${CL}"
2526

2627
APP="FileBrowser"
2728
INSTALL_PATH="/usr/local/bin/filebrowser"
28-
SERVICE_PATH="/etc/systemd/system/filebrowser.service"
2929
DB_PATH="/usr/local/community-scripts/filebrowser.db"
30-
IP=$(hostname -I | awk '{print $1}')
3130
DEFAULT_PORT=8080
3231

32+
# Get first non-loopback IP & Detect primary network interface dynamically
33+
IFACE=$(ip -4 route | awk '/default/ {print $5; exit}')
34+
IP=$(ip -4 addr show "$IFACE" | awk '/inet / {print $2}' | cut -d/ -f1 | head -n 1)
35+
36+
[[ -z "$IP" ]] && IP=$(hostname -I | awk '{print $1}')
37+
[[ -z "$IP" ]] && IP="127.0.0.1"
38+
39+
40+
# Detect OS
41+
if [[ -f "/etc/alpine-release" ]]; then
42+
OS="Alpine"
43+
SERVICE_PATH="/etc/init.d/filebrowser"
44+
PKG_MANAGER="apk add --no-cache"
45+
elif [[ -f "/etc/debian_version" ]]; then
46+
OS="Debian"
47+
SERVICE_PATH="/etc/systemd/system/filebrowser.service"
48+
PKG_MANAGER="apt-get install -y"
49+
else
50+
echo -e "${CROSS} Unsupported OS detected. Exiting."
51+
exit 1
52+
fi
53+
3354
header_info
3455

3556
function msg_info() {
@@ -52,16 +73,24 @@ if [ -f "$INSTALL_PATH" ]; then
5273
read -r -p "Would you like to uninstall ${APP}? (y/N): " uninstall_prompt
5374
if [[ "${uninstall_prompt,,}" =~ ^(y|yes)$ ]]; then
5475
msg_info "Uninstalling ${APP}"
55-
systemctl disable -q --now filebrowser.service
56-
rm -f "$INSTALL_PATH" "$DB_PATH" "$SERVICE_PATH"
76+
if [[ "$OS" == "Debian" ]]; then
77+
systemctl disable --now filebrowser.service &>/dev/null
78+
rm -f "$SERVICE_PATH"
79+
else
80+
rc-service filebrowser stop &>/dev/null
81+
rc-update del filebrowser &>/dev/null
82+
rm -f "$SERVICE_PATH"
83+
fi
84+
rm -f "$INSTALL_PATH" "$DB_PATH"
5785
msg_ok "${APP} has been uninstalled."
5886
exit 0
5987
fi
6088

6189
read -r -p "Would you like to update ${APP}? (y/N): " update_prompt
6290
if [[ "${update_prompt,,}" =~ ^(y|yes)$ ]]; then
6391
msg_info "Updating ${APP}"
64-
curl -fsSL https://github.com/filebrowser/filebrowser/releases/latest/download/linux-amd64-filebrowser.tar.gz | tar -xzv -C /usr/local/bin &>/dev/null
92+
wget -qO- https://github.com/filebrowser/filebrowser/releases/latest/download/linux-amd64-filebrowser.tar.gz | tar -xzv -C /usr/local/bin &>/dev/null
93+
chmod +x "$INSTALL_PATH"
6594
msg_ok "Updated ${APP}"
6695
exit 0
6796
else
@@ -76,26 +105,30 @@ PORT=${PORT:-$DEFAULT_PORT}
76105

77106
read -r -p "Would you like to install ${APP}? (y/n): " install_prompt
78107
if [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then
79-
msg_info "Installing ${APP}"
80-
apt-get install -y curl &>/dev/null
81-
curl -fsSL https://github.com/filebrowser/filebrowser/releases/latest/download/linux-amd64-filebrowser.tar.gz | tar -xzv -C /usr/local/bin &>/dev/null
108+
msg_info "Installing ${APP} on ${OS}"
109+
$PKG_MANAGER wget tar curl &>/dev/null
110+
wget -qO- https://github.com/filebrowser/filebrowser/releases/latest/download/linux-amd64-filebrowser.tar.gz | tar -xzv -C /usr/local/bin &>/dev/null
111+
chmod +x "$INSTALL_PATH"
82112
msg_ok "Installed ${APP}"
83113

84114
msg_info "Creating FileBrowser directory"
85115
mkdir -p /usr/local/community-scripts
86116
chown root:root /usr/local/community-scripts
87117
chmod 755 /usr/local/community-scripts
118+
touch "$DB_PATH"
119+
chown root:root "$DB_PATH"
120+
chmod 644 "$DB_PATH"
88121
msg_ok "Directory created successfully"
89122

90123
read -r -p "Would you like to use No Authentication? (y/N): " auth_prompt
91124
if [[ "${auth_prompt,,}" =~ ^(y|yes)$ ]]; then
92125
msg_info "Configuring No Authentication"
93-
cd /usr/local/community-scripts
94-
filebrowser config init -a '0.0.0.0' -p "$PORT" -d "$DB_PATH" &>/dev/null
95-
filebrowser config set -a '0.0.0.0' -p "$PORT" -d "$DB_PATH" &>/dev/null
96-
filebrowser config init --auth.method=noauth &>/dev/null
97-
filebrowser config set --auth.method=noauth &>/dev/null
98-
filebrowser users add ID 1 --perm.admin &>/dev/null
126+
cd /usr/local/community-scripts
127+
filebrowser config init -a '0.0.0.0' -p "$PORT" -d "$DB_PATH" &>/dev/null
128+
filebrowser config set -a '0.0.0.0' -p "$PORT" -d "$DB_PATH" &>/dev/null
129+
filebrowser config init --auth.method=noauth &>/dev/null
130+
filebrowser config set --auth.method=noauth &>/dev/null
131+
filebrowser users add ID 1 --perm.admin &>/dev/null
99132
msg_ok "No Authentication configured"
100133
else
101134
msg_info "Setting up default authentication"
@@ -107,21 +140,42 @@ if [[ "${install_prompt,,}" =~ ^(y|yes)$ ]]; then
107140
fi
108141

109142
msg_info "Creating service"
110-
cat <<EOF > "$SERVICE_PATH"
143+
if [[ "$OS" == "Debian" ]]; then
144+
cat <<EOF > "$SERVICE_PATH"
111145
[Unit]
112146
Description=Filebrowser
113147
After=network-online.target
114148
115149
[Service]
116150
User=root
117151
WorkingDirectory=/usr/local/community-scripts
118-
ExecStart=/usr/local/bin/filebrowser -r / -d "$DB_PATH" -p "$PORT"
152+
ExecStartPre=/bin/touch /usr/local/community-scripts/filebrowser.db
153+
ExecStartPre=/usr/local/bin/filebrowser config set -a "0.0.0.0" -p 9000 -d /usr/local/community-scripts/filebrowser.db
154+
ExecStart=/usr/local/bin/filebrowser -r / -d /usr/local/community-scripts/filebrowser.db -p 9000
119155
Restart=always
120156
121157
[Install]
122158
WantedBy=multi-user.target
123159
EOF
124-
systemctl enable -q --now filebrowser.service
160+
systemctl enable -q --now filebrowser
161+
else
162+
cat <<EOF > "$SERVICE_PATH"
163+
#!/sbin/openrc-run
164+
165+
command="/usr/local/bin/filebrowser"
166+
command_args="-r / -d $DB_PATH -p $PORT"
167+
command_background=true
168+
pidfile="/var/run/filebrowser.pid"
169+
directory="/usr/local/community-scripts"
170+
171+
depend() {
172+
need net
173+
}
174+
EOF
175+
chmod +x "$SERVICE_PATH"
176+
rc-update add filebrowser default &>/dev/null
177+
rc-service filebrowser start &>/dev/null
178+
fi
125179
msg_ok "Service created successfully"
126180

127181
echo -e "${CM} ${GN}${APP} is reachable at: ${BL}http://$IP:$PORT${CL}"

0 commit comments

Comments
 (0)