Skip to content

Instantly share code, notes, and snippets.

@Tyderion
Last active December 22, 2015 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tyderion/6540996 to your computer and use it in GitHub Desktop.
Save Tyderion/6540996 to your computer and use it in GitHub Desktop.
Mount disks and then mount the folders for the nfs shares and remount them readonly. Checks if target nfs folder is mounted already.
#!/bin/bash
### BEGIN INIT INFO
# Provides: archiemount
# Required-Start: $local_fs
# Required-Stop: $local_fs
# Should-Start:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Mount my partitions in /var/nfs/ for use in nfs sharing
# Description: Mounts my media partition to /var/nfs/* by rebinding and then remounting them readonly (mediaplayers do not need write access...)
### END INIT INFO
# Why no nested arrays? :(
declare -A a_anime=( [uuid]='462CE9782CE96401' [folder]='/media/Anime/Anime' [mount]='/var/nfs/anime' [name]='Anime' )
declare -A a_series=( [uuid]='5826237C26235A70' [folder]='/media/Internet/Media/Video/Series' [mount]='/var/nfs/series' [name]='Internet' )
declare -A a_movies=( [folder]='/media/Internet/Media/Video/Films' [mount]='/var/nfs/movies' [name]='Internet' )
declare -A a_warez=( [uuid]="88B03321B03314E2" [name]='Warez' )
declare -A a_system=( [uuid]="068EF48C8EF47611" [name]='System' )
function start {
for mount in anime series movies system warez; do
uuid=""
folder=""
mountfolder=""
mountname=""
case $mount in
anime)
uuid=${a_anime[uuid]}
folder=${a_anime[folder]}
mountfolder=${a_anime[mount]}
mountname=${a_anime[name]}
;;
series)
uuid=${a_series[uuid]}
folder=${a_series[folder]}
mountfolder=${a_series[mount]}
mountname=${a_series[name]}
;;
movies)
uuid=${a_movies[uuid]}
folder=${a_movies[folder]}
mountfolder=${a_movies[mount]}
mountname=${a_movies[name]}
;;
warez)
uuid=${a_warez[uuid]}
mountname=${a_warez[name]}
;;
system)
uuid=${a_system[uuid]}
mountname=${a_system[name]}
;;
esac
df -h | grep ${mountname} >/dev/null
if [[ $? -eq 1 ]]; then
/usr/bin/udisks --mount /dev/disk/by-uuid/$uuid --mount-options umask=022
else
echo Partition $mountname already mounted
fi
if [[ "$mountfolder" != "" ]]; then
mount | grep $mountfolder >/dev/null
if [[ $? -eq 1 ]]; then
mount --bind $folder $mountfolder
mount -o remount,ro,bind $folder $mountfolder
else
echo "NFS for $mountfolder is already mounted"
fi
fi
done
}
function stop {
umount ${anime[mount]}
umount ${series[mount]}
umount ${movies[mount]}
}
case $1 in
start)
start
;;
status)
for mount in anime series movies system warez; do
uuid=""
folder=""
mountfolder=""
mountname=""
case $mount in
anime)
mountfolder=${a_anime[mount]}
mountname=${a_anime[name]}
;;
series)
mountfolder=${a_series[mount]}
mountname=${a_series[name]}
;;
movies)
mountfolder=${a_movies[mount]}
mountname=${a_movies[name]}
;;
warez)
mountname=${a_warez[name]}
;;
system)
mountname=${a_system[name]}
;;
esac
df -h | grep ${mountname} >/dev/null
if [[ $? -eq 1 ]]; then
echo "Partition $mountname is not mounted"
else
echo "Partition $mountname is mounted"
fi
if [[ "$mountfolder" != "" ]]; then
mount | grep $mountfolder >/dev/null
if [[ $? -eq 1 ]]; then
echo "$mountfolder is not mounted."
else
echo "$mountfolder is mounted."
fi
fi
done
;;
stop)
stop
;;
restart)
stop
start
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment