Skip to content

Commit

Permalink
nc-automount: fixed persistence of links and more
Browse files Browse the repository at this point in the history
  • Loading branch information
nacho committed Aug 15, 2017
1 parent ddceff7 commit fb1fb9e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
19 changes: 11 additions & 8 deletions etc/nextcloudpi-config.d/nc-automount.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,22 @@ EOF
cat > /usr/local/etc/blknum <<'EOF'
#!/bin/bash
test -e /dev/USBdrive || exit 0
# we perform a cleanup with the first one
ls -d /dev/USBdrive* &>/dev/null || {
rmdir /media/USBdrive*
for f in `ls /media/`; do
test -L $f && rm $f
done
exit 0
}
for i in `seq 1 1 8`; do
test -e /dev/USBdrive$i && continue
test -e /media/USBdrive$i && continue
echo $i
exit 0
done
exit 1
EOF
chmod +x /usr/local/etc/blknum

Expand All @@ -74,7 +80,7 @@ configure()
{
cat > /etc/udev/rules.d/50-automount.rules <<'EOF'
# Need to be a block device
KERNEL!="sd[a-z]*", GOTO="exit"
KERNEL!="sd[a-z][0-9]", GOTO="exit"
# Import some useful filesystem info as variables
IMPORT{program}="/sbin/blkid -o udev -p %N"
Expand All @@ -89,10 +95,7 @@ ACTION!="remove", PROGRAM="/usr/local/etc/blknum", RUN+="/bin/mkdir -p /media/US
ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
# Link with label name if exists
ACTION!="remove", ENV{ID_FS_LABEL}!="", ENV{ID_FS_LABEL}!="USBdrive*", RUN+="/bin/ln -sT /media/USBdrive%c /media/%E{ID_FS_LABEL}"
# Cleanup created link
ACTION=="remove", ENV{ID_FS_LABEL}, ENV{ID_FS_LABEL}!="USBdrive*"!="", RUN+="/bin/rm /media/%E{ID_FS_LABEL}"
ACTION=="add", ENV{ID_FS_LABEL}!="", ENV{ID_FS_LABEL}!="USBdrive*", RUN+="/bin/rm /media/%E{ID_FS_LABEL}", RUN+="/bin/ln -sT /media/USBdrive%c /media/%E{ID_FS_LABEL}"
# Exit
LABEL="exit"
Expand Down
24 changes: 24 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ test -f /root/.my.cnf || echo -e "[client]\npassword=ownyourbits" > /root/.my.cn
chown www-data /var/www/nextcloud/.htaccess
rm -rf /var/www/nextcloud/.well-known

# fix automount
cat > /usr/local/etc/blknum <<'EOF'
#!/bin/bash
# we perform a cleanup with the first one
ls -d /dev/USBdrive* &>/dev/null || {
rmdir /media/USBdrive*
for f in `ls /media/`; do
test -L $f && rm $f
done
exit 0
}
for i in `seq 1 1 8`; do
test -e /media/USBdrive$i && continue
echo $i
exit 0
done
exit 1
EOF
chmod +x /usr/local/etc/blknum


# License
#
# This script is free software; you can redistribute it and/or modify it
Expand Down

0 comments on commit fb1fb9e

Please sign in to comment.