Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/nextcloudpi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornachoparker <nacho@ownyourbits.com>2017-08-31 21:57:51 +0300
committernachoparker <nacho@ownyourbits.com>2017-09-02 00:32:19 +0300
commitc4d2e41c1c5c0c887724a0c33e5b682bb12e47a3 (patch)
tree2947a31f38a814dcf923895096c65a825232d6dc
parentb25fd331dfb35e79b8a62b0c479c3ca0640cfe05 (diff)
nc-automount: complete overhaulv0.24.16
-rw-r--r--etc/nextcloudpi-config.d/nc-automount.sh121
-rwxr-xr-xupdate.sh31
2 files changed, 62 insertions, 90 deletions
diff --git a/etc/nextcloudpi-config.d/nc-automount.sh b/etc/nextcloudpi-config.d/nc-automount.sh
index b44c2e28..18fba5b9 100644
--- a/etc/nextcloudpi-config.d/nc-automount.sh
+++ b/etc/nextcloudpi-config.d/nc-automount.sh
@@ -36,87 +36,78 @@ IMPORTANT: halt or umount the drive before extracting" \
install()
{
- 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
+ apt-get update
+ apt-get install -y --no-install-recommends udiskie
-exit 1
+ cat > /etc/udev/rules.d/99-udisks2.rules <<'EOF'
+ENV{ID_FS_USAGE}=="filesystem|other|crypto", ENV{UDISKS_FILESYSTEM_SHARED}="1"
EOF
- chmod +x /usr/local/etc/blknum
- systemctl daemon-reload
-}
+ cat > /usr/lib/systemd/system/nc-automount.service <<'EOF'
+[Unit]
+Description=Automount USB drives
+Before=mysqld.service
-cleanup() { :; }
+[Service]
+Restart=always
+ExecStart=/usr/bin/udiskie -NTF
+ExecStartPost=/bin/sleep 8
+ExecStartPost=/usr/local/etc/nc-automount-links
-configure()
-{
- # FSTAB
- [[ "$ACTIVE_" == "yes" ]] && {
- grep -q /media/USBdrive8 /etc/fstab || cat >> /etc/fstab <<EOF
-# Rules for automounting both at boot and upon USB plugin. Rely on udev rules
-# Don't delete manually. Instead deactivate nc-automount
-/dev/USBdrive /media/USBdrive auto defaults,noatime,auto,nofail 0 2
-/dev/USBdrive1 /media/USBdrive1 auto defaults,noatime,auto,nofail 0 2
-/dev/USBdrive2 /media/USBdrive2 auto defaults,noatime,auto,nofail 0 2
-/dev/USBdrive3 /media/USBdrive3 auto defaults,noatime,auto,nofail 0 2
-/dev/USBdrive4 /media/USBdrive4 auto defaults,noatime,auto,nofail 0 2
-/dev/USBdrive5 /media/USBdrive5 auto defaults,noatime,auto,nofail 0 2
-/dev/USBdrive6 /media/USBdrive6 auto defaults,noatime,auto,nofail 0 2
-/dev/USBdrive7 /media/USBdrive7 auto defaults,noatime,auto,nofail 0 2
-/dev/USBdrive8 /media/USBdrive8 auto defaults,noatime,auto,nofail 0 2
+[Install]
+WantedBy=multi-user.target
EOF
-}
-
- # UDEV
- cat > /etc/udev/rules.d/50-automount.rules <<'EOF'
-# Need to be a block device
-KERNEL!="sd[a-z][0-9]", GOTO="exit"
-
-# Import some useful filesystem info as variables
-IMPORT{program}="/sbin/blkid -o udev -p %N"
-
-# Need to be a filesystem
-ENV{ID_FS_TYPE}!="vfat|ntfs|ext4|iso9660", GOTO="exit"
-# Create symlink that will be understood by fstab, and a directory in /media
-ACTION!="remove", PROGRAM="/usr/local/etc/blknum", RUN+="/bin/mkdir -p /media/USBdrive%c", SYMLINK+="USBdrive%c"
+ cat > /usr/local/etc/nc-automount-links <<'EOF'
+#!/bin/bash
-# Get a label if present, otherwise specify one
-ENV{ID_FS_LABEL}!="", ENV{dir_name}="%E{ID_FS_LABEL}"
+ls -d /media/* &>/dev/null && {
-# Link with label name if exists
-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}"
+ # remove old links
+ for l in `ls /media/`; do
+ test -L /media/"$l" && rm /media/"$l"
+ done
-# Exit
-LABEL="exit"
+ # create links
+ i=0
+ for d in `ls -d /media/*`; do
+ [ $i -eq 0 ] && \
+ ln -sT "$d" /media/USBdrive || \
+ ln -sT "$d" /media/USBdrive$i
+ i=$(( i + 1 ))
+ done
+}
EOF
+ chmod +x /usr/local/etc/nc-automount-links
- [[ "$ACTIVE_" != "yes" ]] && {
- rm -f /etc/udev/rules.d/50-automount.rules
- sed -i '/# Rules for automounting both/,+11d' /etc/fstab
- }
+ # adjust when mariaDB starts
+ local DBUNIT=/lib/systemd/system/mariadb.service
+ grep -q sleep $DBUNIT || sed -i "/^ExecStart=/iExecStartPre=/bin/sleep 10" $DBUNIT
+}
- # mount whatever is currently plugged in
- udevadm control --reload-rules && udevadm trigger
+configure()
+{
+ [[ $ACTIVE_ != "yes" ]] && {
+ systemctl stop nc-automount
+ systemctl disable nc-automount
+ echo "automount disabled"
+ return 0
+ }
+ systemctl enable nc-automount
+ systemctl start nc-automount
+ echo "automount enabled"
+}
- [[ "$ACTIVE_" != "yes" ]] && echo "automount is now inactive" || echo "automount is now active"
+cleanup()
+{
+ apt-get autoremove -y
+ apt-get clean
+ rm /var/lib/apt/lists/* -r
+ rm -f /home/pi/.bash_history
+ systemctl disable ssh
}
+
# License
#
# This script is free software; you can redistribute it and/or modify it
diff --git a/update.sh b/update.sh
index d48996b0..3ac3365f 100755
--- a/update.sh
+++ b/update.sh
@@ -12,6 +12,10 @@ cp etc/library.sh /usr/local/etc/
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
+
# copy all files in bin and etc
for file in bin/* etc/*; do
[ -f "$file" ] || continue;
@@ -62,31 +66,8 @@ 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
-
- # fix ncp-notify-update
- cat > /usr/local/bin/ncp-notify-update <<'EOF'
+# fix ncp-notify-update
+cat > /usr/local/bin/ncp-notify-update <<'EOF'
#!/bin/bash
VERFILE=/usr/local/etc/ncp-version
LATEST=/var/run/.ncp-latest-version