diff options
author | nachoparker <nacho@ownyourbits.com> | 2017-09-03 23:42:34 +0300 |
---|---|---|
committer | nachoparker <nacho@ownyourbits.com> | 2017-09-03 23:47:00 +0300 |
commit | 88a7d5ec10bfc3a3ba6234fe739cb4a4b0ad0b66 (patch) | |
tree | 47bfe280ab0214f4318ed2575401df9f4381fcab /etc/nextcloudpi-config.d/nc-automount.sh | |
parent | 5f943aca5b905cc6188a5128d46adec384cd7796 (diff) |
nc-automount: improve links morev0.26.2
Diffstat (limited to 'etc/nextcloudpi-config.d/nc-automount.sh')
-rw-r--r-- | etc/nextcloudpi-config.d/nc-automount.sh | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/etc/nextcloudpi-config.d/nc-automount.sh b/etc/nextcloudpi-config.d/nc-automount.sh index fb593aed..144e06f9 100644 --- a/etc/nextcloudpi-config.d/nc-automount.sh +++ b/etc/nextcloudpi-config.d/nc-automount.sh @@ -51,8 +51,18 @@ Before=mysqld.service [Service] Restart=always ExecStart=/usr/bin/udiskie -NTF -ExecStartPost=/bin/sleep 8 -ExecStartPost=/usr/local/etc/nc-automount-links + +[Install] +WantedBy=multi-user.target +EOF + + cat > /usr/lib/systemd/system/nc-automount-links.service <<'EOF' +[Unit] +Description=Monitor /media for mountpoints and create USBdrive* symlinks + +[Service] +Restart=always +ExecStart=/usr/local/etc/nc-automount-links-mon [Install] WantedBy=multi-user.target @@ -64,13 +74,13 @@ EOF ls -d /media/* &>/dev/null && { # remove old links - for l in `ls /media/`; do + for l in $( ls /media/ ); do test -L /media/"$l" && rm /media/"$l" done # create links i=0 - for d in `ls -d /media/*`; do + for d in $( ls -d /media/* 2>/dev/null ); do if [ $i -eq 0 ]; then mountpoint -q "$d" && ln -sT "$d" /media/USBdrive else @@ -83,6 +93,15 @@ ls -d /media/* &>/dev/null && { EOF chmod +x /usr/local/etc/nc-automount-links + cat > /usr/local/etc/nc-automount-links-mon <<'EOF' +#!/bin/bash +inotifywait --monitor --event create --event delete --format '%f %e' /media/ | \ + grep --line-buffered ISDIR | while read f; do + /usr/local/etc/nc-automount-links +done +EOF + chmod +x /usr/local/etc/nc-automount-links-mon + # adjust when mariaDB starts local DBUNIT=/lib/systemd/system/mariadb.service grep -q sleep $DBUNIT || sed -i "/^ExecStart=/iExecStartPre=/bin/sleep 10" $DBUNIT @@ -92,12 +111,16 @@ configure() { [[ $ACTIVE_ != "yes" ]] && { systemctl stop nc-automount + systemctl stop nc-automount-links systemctl disable nc-automount + systemctl disable nc-automount-links echo "automount disabled" return 0 } systemctl enable nc-automount + systemctl enable nc-automount-links systemctl start nc-automount + systemctl start nc-automount-links echo "automount enabled" } |