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 | |
parent | 5f943aca5b905cc6188a5128d46adec384cd7796 (diff) |
nc-automount: improve links morev0.26.2
-rw-r--r-- | etc/nextcloudpi-config.d/nc-automount.sh | 31 | ||||
-rwxr-xr-x | update.sh | 6 |
2 files changed, 32 insertions, 5 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" } @@ -14,7 +14,7 @@ source /usr/local/etc/library.sh # fix automount, reinstall if its old version AMFILE=/usr/local/etc/nextcloudpi-config.d/nc-automount.sh -grep -q nc-automount.service $AMFILE || rm $AMFILE +grep -q nc-automount-links.service $AMFILE || rm $AMFILE # copy all files in bin and etc for file in bin/* etc/*; do @@ -103,6 +103,10 @@ EOF # adjust max PHP processes so Apps don't overload the board (#146) sed -i 's|pm.max_children =.*|pm.max_children = 3|' /etc/php/7.0/fpm/pool.d/www.conf + # automount remove old fstab lines + sed -i '/\/dev\/USBdrive/d' /etc/fstab + rm -f /etc/udev/rules.d/50-automount.rules /usr/local/etc/blknum + # restart PHP sleep 3 systemctl stop php7.0-fpm |