forked from Atha/update-conf.d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-fstab
70 lines (60 loc) · 2.24 KB
/
update-fstab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# Version 2011-10-26 DEPRICATED!
#
# Script for flexible /etc/fstab.d configuration
# From Atha, with a lot of improvements from truc - thanks!
#
# You can find information on how to use this script at
# http://forums.gentoo.org/viewtopic.php?p=6364143
#
# This script idealy goes into /usr/local/bin and is called update-fstab -
# you need to configure your fstab entries in separate files in /etc/fstab.d;
# only filenames starting with two digits are included!
# Examples: /etc/fstab.d/01base or /etc/fstab.d/61nfs-dm8000, to name just two.
#
# Copyright for improvements 2010 truc
# Copyright 2008,2010 Atha
# Distributed under the terms of the GNU General Public License v2 or later
#
# The home of this script is https://github.com/Atha/update-conf.d
# It first appeared at http://forums.gentoo.org/viewtopic.php?p=6364143
#
# DEPRICATED! Please use update-conf.d instead!
#
## SETUP
# fstabdpath sets the path where the individual fstab file are located, this
# should normaly be /etc/fstab.d.
fstabdpath="/etc/fstab.d"
# fstabdverbose sets the verbosity level. Default is 1 (verbose output). If you
# want no messages set this to 0.
fstabdverbose="1"
## FUNCTIONS
message () {
[ ${fstabdverbose} -gt 0 ] && echo $@
}
## MAIN PROGRAM
if [ ! -d ${fstabdpath} ] ; then
echo "update-fstab: ${fstabdpath} is not present!" >&2
exit 1
fi
if [ -e ${fstabdpath}/fstab ] ; then
echo "update-fstab: please remove ${fstabdpath}/fstab before you run this script.
update-fstab: NOTE: It may have been left by a previously run update-fstab, but you should check anyway." >&2
exit 1
fi
cat << 'EOT' > ${fstabdpath}/fstab && message "${fstabdpath}/fstab created, header added"
# /etc/fstab
# automatically generated by the update-fstab script
#
# Please change the according lines in /etc/fstab.d/* if you want them to be
# permanent, otherwise they will not survive the next invocation of
# update-fstab!
#
EOT
for fstab_file in ${fstabdpath}/[0-9][0-9]* ; do
grep '^[^#].*' ${fstab_file} >> ${fstabdpath}/fstab
message "Added: ${fstab_file}"
done
mv -f /etc/fstab /etc/fstab.d.bak && message "Existing /etc/fstab renamed to /etc/fstab.d.bak"
mv -f ${fstabdpath}/fstab /etc/fstab && message "New file system table ${fstabdpath}/fstab moved to /etc/fstab"
exit 0