Skip to content

Instantly share code, notes, and snippets.

@driversti
Last active February 24, 2024 12:26
Show Gist options
  • Save driversti/6d2815e72e9494ae50969701acdc41c3 to your computer and use it in GitHub Desktop.
Save driversti/6d2815e72e9494ae50969701acdc41c3 to your computer and use it in GitHub Desktop.
Installs, enables and runs FileBrowser on a server. Since all my servers are accessible via VPN only I want to be able to choose to which IP bind FileBrowser
#!/bin/sh
# Install FileBrowser
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
# Get all IP addresses using ip command and filter out the IP addresses
IPS=$(ip addr show | grep 'inet ' | awk '{print $2}' | cut -d'/' -f1)
# Print them out for the user
echo "Available IPs:"
for ip in $IPS; do
echo $ip
done
# Ask for the user's choice
echo -n "Please enter the IP you want to bind the FileBrowser with: "
read selected_ip
# Create the OpenRC init script
cat << EOF > /etc/init.d/filebrowser
#!/sbin/openrc-run
name="FileBrowser"
description="FileBrowser service"
command="/usr/local/bin/filebrowser"
command_args="-r / -a $selected_ip -p 8082"
command_background="yes"
pidfile="/run/\$name.pid"
start_stop_daemon_args="--user $(whoami)"
depend() {
after network
}
EOF
# Make the script executable
chmod +x /etc/init.d/filebrowser
# Add the service to the default runlevel and start it
rc-update add filebrowser default
rc-service filebrowser start
# Optionally, check the status
rc-service filebrowser status
#!/bin/bash
# Install FileBrowser
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
# Get all IP addresses
IPS=$(hostname -I | tr ' ' '\n')
# Print them out for the user
echo "Available IPs:"
for ip in $IPS; do
echo $ip
done
# Ask for the user's choice
echo -n "Please enter the IP you want to bind the FileBrowser with: "
read selected_ip
# Create the systemd service file
cat << EOF | sudo tee /etc/systemd/system/filebrowser.service
[Unit]
Description=FileBrowser service
After=network.target
[Service]
ExecStart=/usr/local/bin/filebrowser -r / -a $selected_ip -p 8082
Restart=always
Environment=PATH=/usr/bin:/usr/local/bin
Environment=FILEBROWSER_DATABASE=/home/$(whoami)/filebrowser.db
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd, enable and start the service
sudo systemctl daemon-reload
sudo systemctl enable filebrowser
sudo systemctl start filebrowser
# Show the status of the service
sudo systemctl status filebrowser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment