forked from plus3it/amigen7
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MkTabs.sh
executable file
·88 lines (75 loc) · 2.34 KB
/
MkTabs.sh
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
# shellcheck disable=SC2181
#
# Script to set up the chroot'ed /etc/fstab
#
#################################################################
CHROOT="${CHROOT:-/mnt/ec2-root}"
TARGSWAP=${2:-/dev/VolGroup00/swapVol}
FSTAB="${CHROOT}/etc/fstab"
# Check for arguments
if [[ $# -lt 1 ]]
then
echo "Missing parameter(s). Aborting..." > /dev/stderr
exit 1
fi
# Make sure that chroot'ed /etc/directory exists
if [[ ! -d ${CHROOT}/etc ]]
then
mkdir -p "${CHROOT}/etc"
if [[ $? -ne 0 ]]
then
echo "Failed to create /etc" > /dev/stderr && exit 1
else
echo "Created ${CHROOT}/etc"
fi
fi
# Create file-header
cat << EOF > "${FSTAB}"
#
# /etc/fstab
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
EOF
# shellcheck disable=SC2001
_CHROOT=$(echo "${CHROOT}" | sed 's#^/##')
# Read mtab matches into an array
IFS=$'\n'; MTABLNS=( $(grep "${CHROOT}" /etc/mtab | grep ^/dev | \
sed 's#'"${_CHROOT}"'##') )
for FSLINE in "${MTABLNS[@]}"
do
BLKDEV=$(echo "${FSLINE}" | awk '{print $1}')
MNTPNT=$(echo "${FSLINE}" | awk '{print $2}' | sed 's#//#/#')
FSTYPE=$(echo "${FSLINE}" | awk '{print $3}')
case ${FSTYPE} in
ext[234])
if [[ ! $(e2label "${BLKDEV}") = "" ]]
then
BLKDEV="LABEL=$(e2label "${BLKDEV}")"
fi
;;
xfs)
echo POINK
;;
esac
if [ "$MNTPNT" = "/tmp" ]; then
printf "%s\t%s\t%s\tdefaults\t0 0\n" "${BLKDEV}" "${MNTPNT}" "${FSTYPE}"
else
printf "%s\t%s\t%s\tdefaults,nodev,nosuid,noexec\t0 0\n" "${BLKDEV}" "${MNTPNT}" "${FSTYPE}"
fi
done >> "${FSTAB}"
printf "%s\t%s\t%s\t%s\t0 0\n" "${TARGSWAP}" swap swap '-' >> "${FSTAB}"
# Read mtab matches into an array
IFS=$'\n'; MTABLNS=( $(grep "${CHROOT}" /etc/mtab | sed 's#'"${_CHROOT}"'##') )
for FSLINE in "${MTABLNS[@]}"
do
BLKDEV=$(echo "${FSLINE}" | awk '{print $1}')
MNTPNT=$(echo "${FSLINE}" | awk '{print $2}' | sed 's#//#/#')
FSTYPE=$(echo "${FSLINE}" | awk '{print $3}')
MNTOPT=$(echo "${FSLINE}" | awk '{print $4}')
FSFREQ=$(echo "${FSLINE}" | awk '{print $5}')
FSPASS=$(echo "${FSLINE}" | awk '{print $6}')
printf "%s %s %s %s %s %s\n" "${BLKDEV}" "${MNTPNT}" "${FSTYPE}" "${MNTOPT}" "${FSFREQ}" "${FSPASS}"
done > "${CHROOT}/etc/mtab"