16th November 2023 / 04:30 PM
I wrote a bash script which performs an automated installation of FileBrowser, which makes it possible to access files on a machine through a webbrowser. My script simplifies the process of installing filebrowser. The user only has to change one thing in a config file and then execute install.sh.
First I created a config file named filebrowser.json. This is where the user needs to change one thing: The IP-Address.
{
"port": 8080,
"baseURL": "",
"address": "000.000.000.000",
"log": "stdout",
"database": "/etc/filebrowser.db",
"root": "/var/www"
}
After that, I created a system service file named filebrowser.service. This file is responsible for systemd starting the Filebrowser instance when the server it is running on is being turned on, or rebooted. The system service file looks like this:
[Unit]
Description=File Browser
After=network.target
[Service]
ExecStart=/usr/local/bin/filebrowser -c /etc/filebrowser.json
[Install]
WantedBy=multi-user.target
Finally, I wrote the bash script: It has to install FileBrowser, copy the system service and config files to the right direction, start FileBrowser for the first time and enable the system service. I also added some "sleep" instructions, so that the user can read what is happening. The script looks like this:
#!/bin/bash
echo "This script will perform an automatic installation of FileBrowser!"
sleep 1
echo "Updating repositories..."
sleep 0.5
apt update && apt full-upgrade -y && apt install curl -y
sleep 1
echo "Updates done."
sleep 0.5
echo "Downloading and installing FileBrowser..."
sleep 0.5
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
sleep 0.5
echo "Copying config file to /etc/filebrowser.json ..."
sleep 0.5
cp filebrowser.json /etc/filebrowser.json
echo "Copying system service file to /etc/systemd/system/filebrowser.service ..."
sleep 0.5
cp filebrowser.service /etc/systemd/system/filebrowser.service
echo "Enabling and starting the filebrowser system service..."
sleep 0.5
systemctl enable filebrowser.service
systemctl start filebrowser.service
sleep 0.5
echo "DONE! Congratulations, you now have a running FileBrowser instance!"
sleep 0.5
echo "After updating any settings in /etc/filebrowser.json make sure to run "systemctl restart filebrowser.service""
echo "Default Login:"
echo "User: admin"
echo "Pass: admin"
echo "Please make sure to change the password on your first login!"