2020-08-06 22:22:05 +00:00
|
|
|
#!/usr/bin/with-contenv bash
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Pictures storage
|
|
|
|
####################
|
|
|
|
if [ ! -d "/opt/pictures" ] ; then
|
|
|
|
mkdir /opt/pictures
|
|
|
|
fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Ansible
|
|
|
|
####################
|
|
|
|
if [ ! -d "/opt/ansible" ] ; then
|
|
|
|
mkdir /opt/ansible
|
|
|
|
fi
|
|
|
|
if [ ! -d "/opt/ansible/.git" ] ; then
|
|
|
|
git clone https://git.kemonine.info/PiFrame/ansible.git /opt/ansible/
|
|
|
|
else
|
|
|
|
cd /opt/ansible
|
|
|
|
git pull
|
|
|
|
fi
|
|
|
|
if [ ! -f "/opt/ansible/ssh.key" ] ; then
|
|
|
|
ssh-keygen -t rsa -b 4096 -f /opt/ansible/ssh.key -N ''
|
|
|
|
echo "
|
|
|
|
-------------------------------------
|
|
|
|
Ansible SSH Key"
|
|
|
|
cat /opt/ansible/ssh.key.pub
|
|
|
|
echo "-------------------------------------
|
|
|
|
"
|
|
|
|
fi
|
|
|
|
|
2020-08-08 04:58:10 +00:00
|
|
|
####################
|
|
|
|
# Monit
|
|
|
|
####################
|
|
|
|
if [ ! -d "/opt/monit/conf.d" ] ; then
|
|
|
|
mkdir /opt/monit/conf.d
|
|
|
|
fi
|
|
|
|
if [ ! -f "/opt/monit/monitrc" ] ; then
|
|
|
|
cat > /opt/monit/monitrc <<EOF
|
|
|
|
set daemon 120
|
|
|
|
set log /opt/monit/monit.log
|
|
|
|
set idfile /opt/monit/id
|
|
|
|
set statefile /opt/monit/state
|
|
|
|
set eventqueue
|
|
|
|
basedir /opt/monit/events # set the base directory where events will be stored
|
|
|
|
slots 100 # optionally limit the queue size
|
|
|
|
|
|
|
|
set httpd port 2812 and
|
|
|
|
use address 0.0.0.0
|
|
|
|
allow ${MONIT_CONFIG_USER}:${MONIT_CONFIG_PASS}
|
|
|
|
|
|
|
|
include /opt/monit/conf.d/*
|
|
|
|
EOF
|
|
|
|
chmod 600 /opt/monit/monitrc
|
|
|
|
if [ ! -f "/opt/monit/conf.d/picturesfs" ] ; then
|
|
|
|
cat > /opt/monit/conf.d/picturesfs <<EOF
|
|
|
|
check filesystem rootfs with path /opt/pictures
|
|
|
|
if space usage > 80% then alert
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# Monit dashboard
|
|
|
|
####################
|
|
|
|
if [ ! -d "/opt/monit-dashboard" ] ; then
|
|
|
|
mkdir /opt/monit-dashboard
|
|
|
|
fi
|
|
|
|
if [ ! -d "/opt/monit-dashboard/.git" ] ; then
|
|
|
|
git clone https://github.com/adriaaah/monit-dashboard /opt/monit-dashboard
|
|
|
|
sed -i 's/app.run(port=8080)/app.run(port=2811)/g' /opt/monit-dashboard/bin/monit-dashboard.py
|
|
|
|
else
|
|
|
|
cd /opt/monit-dashboard
|
|
|
|
git stash
|
|
|
|
git pull
|
|
|
|
sed -i 's/app.run(port=8080)/app.run(port=2811)/g' /opt/monit-dashboard/bin/monit-dashboard.py
|
|
|
|
fi
|
|
|
|
cd /opt/monit-dashboard
|
|
|
|
if [ ! -f "/opt/monit-dashboard/conf/servers.json" ] ; then
|
|
|
|
cat > conf/servers.json <<EOF
|
|
|
|
{
|
|
|
|
"dispatcher": {
|
|
|
|
"url": "http://127.0.0.1:2812",
|
|
|
|
"user": "${MONIT_CONFIG_USER}",
|
|
|
|
"passwd": "${MONIT_CONFIG_PASS}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
|
2020-08-06 22:22:05 +00:00
|
|
|
####################
|
|
|
|
# WireGuard
|
|
|
|
####################
|
|
|
|
if [ "$ENABLE_WIREGUARD" = true ] ; then
|
|
|
|
ip link del dev test 2>/dev/null
|
|
|
|
if ip link add dev test type wireguard; then
|
|
|
|
echo "**** It seems the wireguard module is already active :) ****"
|
|
|
|
ip link del dev test
|
|
|
|
else
|
|
|
|
echo "**** The wireguard module is not active, please install wireguard on the host and activate the 'wg' kernel module ****"
|
|
|
|
fi
|
|
|
|
if [ ! -d "/opt/wireguard" ] ; then
|
|
|
|
mkdir /opt/wireguard
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# syncthing
|
|
|
|
####################
|
|
|
|
if [ "$ENABLE_SYNCTHING" = true ] ; then
|
|
|
|
if [ ! -d "/opt/syncthing" ]; then
|
|
|
|
mkdir /opt/syncthing
|
|
|
|
fi
|
|
|
|
ST_CONF="/opt/syncthing/config.xml"
|
|
|
|
if [ ! -f "$ST_CONF" ]; then
|
|
|
|
echo "**** Initial Syncthing Config ****"
|
|
|
|
/usr/bin/syncthing -generate /opt/syncthing
|
|
|
|
sed -i 's/<address>127.0.0.1:8384<\/address>/<address>0.0.0.0:8384<\/address>/g' /opt/syncthing/config.xml
|
|
|
|
sed -i 's/<folder id="default" label="Default Folder" path="\/root\/Sync" type="sendreceive" rescanIntervalS="3600" fsWatcherEnabled="true" fsWatcherDelayS="10" ignorePerms="false" autoNormalize="true">/<folder id="piframe-pictures" label="PiFrameFleet Pictures" path="\/opt\/pictures" type="sendonly" rescanIntervalS="86400" fsWatcherEnabled="true" fsWatcherDelayS="10" ignorePerms="false" autoNormalize="true">/g' /opt/syncthing/config.xml
|
|
|
|
if [ -d "/root/Sync" ]; then
|
|
|
|
rm -r /root/Sync
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
####################
|
|
|
|
# FileBrowser
|
|
|
|
####################
|
|
|
|
if [ "$ENABLE_FILEBROWSER" = true ] ; then
|
|
|
|
if [ ! -d "/opt/filebrowser" ]; then
|
|
|
|
mkdir /opt/filebrowser
|
|
|
|
fi
|
|
|
|
FB_DB="/opt/filebrowser/pictures.db"
|
|
|
|
if [ ! -f "$FB_DB" ]; then
|
|
|
|
echo "**** Initial FileBrowser Config ****"
|
|
|
|
filebrowser -d $FB_DB \
|
|
|
|
config init 2>&1 > /dev/null
|
|
|
|
filebrowser -d $FB_DB \
|
|
|
|
config set --address 0.0.0.0 2>&1 > /dev/null
|
|
|
|
filebrowser -d $FB_DB \
|
|
|
|
config set --port 9191 2>&1 > /dev/null
|
|
|
|
filebrowser -d $FB_DB \
|
|
|
|
config set --branding.name "PiFrameFleet - Pictures" 2>&1 > /dev/null
|
|
|
|
filebrowser -d $FB_DB \
|
|
|
|
users add admin password 2>&1 > /dev/null
|
|
|
|
fi
|
|
|
|
fi
|