updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / update-fstab / update-fstab.sh
blob8d84dc672300d87e6c1b4aaa502febfec804152a
1 #!/bin/sh
2 # Script for flexible /etc/fstab.d configuration
3 # From Atha, with a lot of improvements from truc - thanks!
5 # You can find information on how to use this script at
6 # http://forums.gentoo.org/viewtopic.php?p=6364143
8 # This script idealy goes into /usr/local/bin and is called update-fstab -
9 # you need to configure your fstab entries in separate files in /etc/fstab.d;
10 # only filenames starting with two digits are included!
11 # Examples: /etc/fstab.d/01base or /etc/fstab.d/61nfs-dm8000, to name just two.
13 # Copyright 2008 Atha
14 # Distributed under the terms of the GNU General Public License v2 or later
17 ## SETUP
18 # fstabdpath sets the path where the individual fstab file are located, this should normaly be /etc/fstab.d.
19 fstabdpath="/etc/fstab.d"
20 # fstabdverbose sets the verbosity level. Default is 0 (no messages). If you want verbose output (i.e. to debug) set this to 1.
21 fstabdverbose="1"
24 ## FUNCTIONS
25 message () {
26 [ ${fstabdverbose} -gt 0 ] && echo $@
30 ## MAIN PROGRAM
31 if [ ! -d ${fstabdpath} ] ; then
32 echo "update-fstab: ${fstabdpath} is not present!" >&2
33 exit 1
36 if [ -e ${fstabdpath}/fstab ] ; then
37 echo "update-fstab: please remove ${fstabdpath}/fstab before you run this script.
38 update-fstab: NOTE: It may have been left by a previously run update-fstab, but you should check anyway." >&2
39 exit 1
42 cat << 'EOT' > ${fstabdpath}/fstab && message "${fstabdpath}/fstab created, header added"
43 # /etc/fstab
44 # automatically generated by the update-fstab script
46 # Please change the according lines in /etc/fstab.d/* if you want them to be permanent,
47 # otherwise they will not survive the next invocation of update-fstab!
49 EOT
51 for fstab_file in ${fstabdpath}/[0-9][0-9]* ; do
52 grep '^[^#].*' ${fstab_file} >> ${fstabdpath}/fstab
53 message "Added: ${fstab_file}"
54 done
56 mv -f /etc/fstab /etc/fstab.d.bak && message "Existing /etc/fstab renamed to /etc/fstab.d.bak"
57 mv -f ${fstabdpath}/fstab /etc/fstab && message "New file system table ${fstabdpath}/fstab moved to /etc/fstab"
59 exit 0