Skip to content

Commit

Permalink
nc-automount: improve links more
Browse files Browse the repository at this point in the history
  • Loading branch information
nachoparker committed Sep 3, 2017
1 parent 5f943ac commit 88a7d5e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 5 deletions.
31 changes: 27 additions & 4 deletions etc/nextcloudpi-config.d/nc-automount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
}

Expand Down
6 changes: 5 additions & 1 deletion update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88a7d5e

Please sign in to comment.