Skip to content

Commit

Permalink
1.6
Browse files Browse the repository at this point in the history
(import from local svn)
  • Loading branch information
reidemei committed Dec 4, 2020
1 parent 9c525a2 commit a64c6c2
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 121 deletions.
8 changes: 5 additions & 3 deletions source/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
1.5
1.6
- changed: compatibility with DSM 5.1
1.5
- changed: configurable wait times before starting the script
1.4
!!! YOU HAVE TO RECREATE THE SCRIPTS FOR THE LOCAL BACKUP!!!
Expand All @@ -25,13 +27,13 @@
- changed: local backup - 10s sleep added to give the drive some time to be properly mounted
0.9
- new: now supports update
- changed: DSM 3.2
- changed: requires DSM 3.2
0.8
- fixed: don't log passwords
0.7
- new: local backup - option for encryption added
0.6
- changed: DSM 3.1
- changed: requires DSM 3.1
- fixed: local backup - wait till backup is finished
0.5
- fixed: incorrect handling of DS restarts
Expand Down
4 changes: 2 additions & 2 deletions source/INFO
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package="autorun"
version="1.5"
version="1.6"
maintainer="Jan Reidemeister"
description="Execute scripts when connecting external drives (USB / eSATA). Includes GUI to create such scripts for the build-in local backup and allows to encrypt the backups."
description_ger="Erlaubt das automatische Ausführen von Skripten beim Anschluss von externen Geräten (USB / eSATA). Inklusive Oberfläche zum Erstellen passender Skripte für die Datensicherung, auch mit Verschlüsselung."
arch="noarch"
firmware="5.0-4378"
reloadui="yes"
install_dep_packages="Perl"
helpurl="http://www.synology-forum.de/showthread.html?53183-autorun"
helpurl="http://www.synology-forum.de/showthread.html?18360-Autorun-für-ext.-Datenträger"
7 changes: 4 additions & 3 deletions source/build
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
rm package.tgz
rm autorun-1.5.spk
tar -czvf package.tgz -C package/ autorun hotplug localbackup encryptbackup config web -X tarexclude
tar -cvvf autorun-1.5.spk INFO CHANGELOG LICENSE PACKAGE_ICON.PNG WIZARD_UIFILES scripts package.tgz -X tarexclude
rm autorun-1.6.spk
tar -czvf package.tgz -C package/ autorun common config encryptbackup hotplug localbackup rules udev web -X tarexclude
tar -cvvf autorun-1.6.spk INFO CHANGELOG LICENSE PACKAGE_ICON.PNG WIZARD_UIFILES scripts package.tgz -X tarexclude
rm package.tgz
chmod 777 autorun-1.6.spk
57 changes: 36 additions & 21 deletions source/package/autorun
Original file line number Diff line number Diff line change
@@ -1,87 +1,102 @@
#!/bin/sh

source /var/packages/autorun/target/common

if [ -z "$1" ]
then
echo "incorrect '\$1' - aborting ..."
exit 1
fi

# default settings
TRIES=20
WAIT=0
# import our config
source /var/packages/autorun/target/config
LOGDIR="/var/packages/autorun/target"
MOUNTPATH=""
COUNT=0

echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$1' - inserted, trying to find mount point<br/>" >> $LOGDIR/log

# try to get the mount path
logInfo "device '$1' - inserted, trying to find mount point"
while ([ -z "$MOUNTPATH" ] && [ $COUNT -lt $TRIES ])
do
MOUNTPATH=`/bin/mount 2>&1 | /bin/grep "/dev/$1" | /usr/bin/cut -d ' ' -f3`
COUNT=$(($COUNT+1))
/bin/sleep 1s
done

# abort when nothing is found
if [ -z "$MOUNTPATH" ]
then
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$1' - unable to find mount point, aborting<br/>" >> $LOGDIR/log
logInfo "device '$1' - unable to find mount point, aborting"
exit 1
fi
logInfo "device '$1' - mount point '$MOUNTPATH' found"

echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$1' - mount point '$MOUNTPATH' found<br/>" >> $LOGDIR/log

# sleep some time because Synology does some crazy stuff like un- and remounting on SATA
/bin/sleep $WAIT

# is there a script on our drive?
if [ -x "$MOUNTPATH/$SCRIPT" ]
then
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$1' - script '$MOUNTPATH/$SCRIPT' found, executing<br/>" >> $LOGDIR/log
# yes
logInfo "device '$1' - script '$MOUNTPATH/$SCRIPT' found, executing"
if [ $BEEP = "1" ]
then
echo 2 > /dev/ttyS1
beep 2
fi
if [ $LED = "1" ]
then
echo : > /dev/ttyS1
beep :
fi

# execute the script
# $1 - mount path
# $2 - device
$MOUNTPATH/$SCRIPT $MOUNTPATH $1

# save the result for later
RESULT=$?

# get the free space
FREE=`/bin/df -h "$MOUNTPATH" | /bin/grep "$MOUNTPATH" | /usr/bin/awk '{ print $4 }'`

# unmount when the result is 100
if [ $RESULT = "100" ]
then
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$1' - script '$MOUNTPATH/$SCRIPT' finished ($FREE left on device), starting unmount<br/>" >> $LOGDIR/log
logInfo "device '$1' - script '$MOUNTPATH/$SCRIPT' finished ($FREE left on device), starting unmount"
sleep 5
sync
umount $MOUNTPATH
if [ $? -eq 0 ]
then
# and eject the drive
echo 1 > /sys/block/$1/device/delete
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$1' - unmounted and ejected<br/>" >> $LOGDIR/log
logInfo "device '$1' - unmounted and ejected"
else
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$1' - <span style=\"color:red;\">error while unmounting '$MOUNTPATH', aborting</span><br/>" >> $LOGDIR/log
echo 3 > /dev/ttyS1
sleep 1s
echo 3 > /dev/ttyS1
sleep 1s
echo 3 > /dev/ttyS1
# abort on error
logError "device '$1' - error while unmounting '$MOUNTPATH', aborting"
beepError
exit 1
fi
else
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$1' - script '$MOUNTPATH/$SCRIPT' finished ($FREE left on device), no further actions<br/>" >> $LOGDIR/log
logInfo "device '$1' - script '$MOUNTPATH/$SCRIPT' finished ($FREE left on device), no further actions"
fi
if [ $BEEP = "1" ]
then
echo 2 > /dev/ttyS1
beep 2
fi
if [ $LED = "1" ]
then
echo 8 > /dev/ttyS1
beep 8
fi
if [ $NOTIFY = "1" ]
then
/usr/syno/bin/synodsmnotify $NOTIFYTARGET "autorun" "script finished, $FREE left on $MOUNTPATH"
fi
else
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$1' - no script '$MOUNTPATH/$SCRIPT' found, no further actions<br/>" >> $LOGDIR/log
# no
logInfo "device '$1' - no script '$MOUNTPATH/$SCRIPT' found, no further actions"
fi

exit 0
30 changes: 30 additions & 0 deletions source/package/common
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh

LOGDIR="/var/packages/autorun/target"

# write an info entry to out log file
# $1 - log entry
logInfo() {
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: $1<br/>" >> $LOGDIR/log
}

# write an error entry to out log file
# $1 - log entry
logError() {
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: <span style=\"color:red;\">$1</span><br/>" >> $LOGDIR/log
}

# set the led or send a beep
# $1 - event (see http://www.synology-wiki.de/index.php/LEDs_und_Buttons)
beep() {
echo $1 > /dev/ttyS1
}

beepError() {
beep 3
sleep 1s
beep 3
sleep 1s
beep 3
sleep 1s
}
118 changes: 57 additions & 61 deletions source/package/encryptbackup
Original file line number Diff line number Diff line change
@@ -1,103 +1,99 @@
#!/bin/sh

# file name containing the password
source /var/packages/autorun/target/common

# $1 - file name containing the password
if [ -z "$1" ]
then
echo "incorrect '\$1' - aborting ..."
exit 1
fi
# backup name

# $2 - backup name
if [ -z "$2" ]
then
echo "incorrect '\$2' - aborting ..."
exit 1
fi
# external device from setup

# $3 - external device from setup
if [ -z "$3" ]
then
echo "incorrect '\$3' - aborting ..."
exit 1
fi
# external device currently attached

# $4 - external device currently attached
if [ -z "$4" ]
then
echo "incorrect '\$4' - aborting ..."
exit 1
fi
# eject?

# $5 - eject?
if [ -z "$5" ]
then
echo "incorrect '\$5' - aborting ..."
exit 1
fi
# encrypt file names?

# $6 - encrypt file names?
ENCFN="y"
if [ -n "$6" ]
then
ENCFN=$6
fi

LOGDIR="/var/packages/autorun/target"

if [ $3 = $4 ]
then
if [ -f "/var/packages/autorun/target/passwords/$1" ]
then
# load pwd
PASSWD=`cat /var/packages/autorun/target/passwords/$1`
# create directories
if [ -d "$4/@LocalBackup@" ]
if [ -f "/var/packages/autorun/target/passwords/$1" ]
then
: # fine
else
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$4' - no directory for encrypted data found, creating new one<br/>" >> $LOGDIR/log
mkdir "$4/@LocalBackup@"
fi
if [ -d "$4/LocalBackup" ]
then
: # fine
else
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$4' - no directory for the backup found, creating new one<br/>" >> $LOGDIR/log
mkdir "$4/LocalBackup"
fi
# mount
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$4' - mounting the encrypted file system<br/>" >> $LOGDIR/log
/usr/syno/sbin/mount.ecryptfs $4/@LocalBackup@ $4/LocalBackup -o ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_passthrough=n,no_sig_cache,ecryptfs_enable_filename_crypto=$ENCFN,passwd=$PASSWD
# execute the backup
/var/packages/autorun/target/localbackup "$2" "$3" "$4" "$5"
# unmount
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$4' - unmounting the encrypted file system<br/>" >> $LOGDIR/log
/bin/umount "$4/LocalBackup"
if [ $? -eq 0 ]
then
: # everything fine
# load pwd
PASSWD=`cat /var/packages/autorun/target/passwords/$1`

# create directories
if [ -d "$4/@LocalBackup@" ]
then
: # fine
else
logInfo "device '$4' - no directory for encrypted data found, creating new one"
mkdir "$4/@LocalBackup@"
fi
if [ -d "$4/LocalBackup" ]
then
: # fine
else
logInfo "device '$4' - no directory for the backup found, creating new one"
mkdir "$4/LocalBackup"
fi

# mount
logInfo "device '$4' - mounting the encrypted file system"
/usr/syno/sbin/mount.ecryptfs $4/@LocalBackup@ $4/LocalBackup -o ecryptfs_cipher=aes,ecryptfs_key_bytes=32,ecryptfs_passthrough=n,no_sig_cache,ecryptfs_enable_filename_crypto=$ENCFN,passwd=$PASSWD

# execute the backup
/var/packages/autorun/target/localbackup "$2" "$3" "$4" "$5"

# unmount
logInfo "device '$4' - unmounting the encrypted file system"
/bin/umount "$4/LocalBackup"
if [ $? -eq 0 ]
then
: # everything fine
else
# abort on error
logError "device '$4' - problem while unmounting the encrypted file system, aborting"
beepError
exit 1
fi
else
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$4' - <span style=\"color:red;\">problem while unmounting the encrypted file system, aborting</span><br/>" >> $LOGDIR/log
echo 3 > /dev/ttyS1
sleep 1s
echo 3 > /dev/ttyS1
sleep 1s
echo 3 > /dev/ttyS1
sleep 1s
exit 1
# abort on error
logError "device '$4' - stored password missing for backup '$2', aborting"
beepError
fi
else
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$4' - <span style=\"color:red;\">stored password missing for backup '$2', aborting</span><br/>" >> $LOGDIR/log
echo 3 > /dev/ttyS1
sleep 1s
echo 3 > /dev/ttyS1
sleep 1s
echo 3 > /dev/ttyS1
sleep 1s
fi
else
echo "`date +%Y-%m-%d` `date +%H:%M:%S`: device '$4' - <span style=\"color:red;\">parameters changed for local backup '$2' - '$3' expected but '$3' found, aborting</span><br/>" >> $LOGDIR/log
echo 3 > /dev/ttyS1
sleep 1s
echo 3 > /dev/ttyS1
sleep 1s
echo 3 > /dev/ttyS1
sleep 1s
logError "device '$4' - parameters changed for local backup '$2' - '$3' expected but '$4' found, aborting"
beepError
fi

exit $5
Loading

0 comments on commit a64c6c2

Please sign in to comment.