Created
November 24, 2016 01:32
-
-
Save canuk/077bf6771a3f0ed3bf1a8530c7eb1d7a to your computer and use it in GitHub Desktop.
ArchLinux Service for auto mounting USB drive for SMILEplug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=devmon Service | |
[Service] | |
Type=simple | |
User=www-data | |
# Set DISPLAY for popup dialogs | |
Environment=DISPLAY=:0 | |
EnvironmentFile=/etc/conf.d/devmon | |
ExecStart=/usr/bin/devmon --exec-on-device /dev/sdb1 "/etc/nginx/usb_sharing mount 1 %d" --exec-on-remove "/etc/nginx/usb_sharing unmount 1 %d" --exec-on-device /dev/sdc1 "/etc/nginx/usb_sharing mount 2 %d" --exec-on-remove "/etc/nginx/usb_sharing unmount 2 %d" | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##### | |
# This should live in /etc/nginx/ | |
# It symlinks the mount point for USB drives to a web-accessible directory in the ngnix htmldoc root | |
# edited on 11/22/16 by RMT for use in the SMLEpi device | |
##### | |
readonly storage1_share="/usr/share/nginx/html/storage1" | |
readonly storage2_share="/usr/share/nginx/html/storage2" | |
function exec_at_mount() | |
{ | |
case ${1} in | |
"1") | |
#Remove existing symlink | |
rm ${storage1_share} | |
# Create symlink | |
ln -s "${2}" ${storage1_share} | |
;; | |
"2") | |
#Remove existing symlink | |
rm ${storage2_share} | |
# Create symlink | |
ln -s "${2}" ${storage2_share} | |
;; | |
esac | |
exit 0; | |
} | |
function exec_at_unmount() | |
{ | |
case ${1} in | |
"1") | |
# Remove Link | |
rm ${storage1_share} | |
;; | |
"2") | |
# Remove Link | |
rm ${storage2_share} | |
;; | |
esac | |
exit 0; | |
} | |
# M A I N | |
# The incoming parameters are | |
# {1} mount/unmont | |
# {2} device number | |
# {3} mount point of the device | |
mount_point=${3} | |
device_num=${2} | |
if [[ ${1} == "mount" ]]; then | |
exec_at_mount ${device_num} "$mount_point" | |
fi | |
if [[ ${1} == "unmount" ]]; then | |
exec_at_unmount ${device_num} "$mount_point" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment