/
bbqinstall
executable file
·160 lines (124 loc) · 3.79 KB
/
bbqinstall
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
ERROR_LOG=/var/log/bbqinstall.log
if [ "$(whoami)" != 'root' ]; then
echo "You have no permission to run $0 as non-root user."
exit 1;
fi
BBQINSTALL_CONF="/etc/bbqinstall.conf"
EXCLUDES="/etc/bbqinstall_excludes"
usage() {
echo -e "$usage_text"
exit 0
}
usage_text="
Usage: bbqinstall <disk> <partition> write GRUB to \e[1m<disk>\e[0m and install system to \e[1m<partition>\e[0m
Example: bbqinstall /dev/sda /dev/sda1
Refer to the output of \e[1mblkid -o list\e[0m or \e[1mfdisk -l\e[0m for file system information.
"
# print file system table
[[ -z $1 ]] && echo "E: Specify disk path and a partition!" && usage
[[ -z $2 ]] && echo "E: Specify a partition!" && usage
[[ ! -e $1 ]] && echo "E: $1 is not a valid drive" && exit 0
[[ ! -e $2 ]] && echo "E: $2 is not a valid partition" && exit 0
cm1=`exec df -P $1 | tail -1 | cut -d' ' -f 1`
cm2=`exec df -P $2 | tail -1 | cut -d' ' -f 1`
echo "I: $1 is mounted per $cm1"
echo "I: $2 is mounted per $cm2"
INSTALL_GRUB="$1"
INSTALL_PART="$2"
# ERROR CHECK
check_exit () {
[[ $? -eq 0 ]] || { echo "
Exit due to error: $?
See $ERROR_LOG for details.
"
exit 1 ; }
}
if [[ -f $BBQINSTALL_CONF ]]; then
echo "I: $BBQINSTALL_CONF found, sourcing"
source "$BBQINSTALL_CONF"
else
echo "I: $BBQINSTALL_CONF not found, using defaults"
### THESE ARE POSSIBLE VALUES THAT ARE NOT IMPLEMENTED YET.
# ROOT_PASS="root"
# HOST="grill"
#################################################################
fi
if ! [[ -f $EXCLUDES ]] ; then
cat > "$EXCLUDES" << EOF
- /dev/*
- /cdrom/*
- /media/*
- /target
- /swapfile
- /mnt/*
- /sys/*
- /proc/*
- /tmp/*
- /live
- /lib/live/mount/*
- /boot/grub/grub.cfg
- /boot/grub/menu.lst
- /boot/grub/device.map
- /etc/udev/rules.d/70-persistent-cd.rules
- /etc/udev/rules.d/70-persistent-net.rules
- /etc/fstab
- /etc/mtab
- /home/snapshot
- /home/*/.gvfs
EOF
check_exit
chmod 666 "$EXCLUDES"
fi
if $(df | grep -q /target/proc/) ; then
umount /target/proc/
fi
if $(df | grep -q /target/dev/) ; then
umount /target/dev/
fi
if $(df | grep -q /target/sys/) ; then
umount /target/sys/
fi
mkdir /target
echo "I: Creating file system on $INSTALL_PART"
mke2fs -t ext4 "$INSTALL_PART" ; check_exit
tune2fs -r 10000 "$INSTALL_PART" ; check_exit
echo "I: Mounting $INSTALL_PART on target filesystem"
mount $INSTALL_PART /target ; check_exit
echo "I: Copying files"
rsync --progress -av / /target/ --exclude-from="$EXCLUDES"
echo "I: Adding fstab entries"
echo -e "proc\t\t/proc\tproc\tdefaults\t0\t0
$install_part\t/\t$fs_type_os\tdefaults,noatime\t0\t1" >> /target/etc/fstab
echo "I: Mounting target filesystem"
mount --bind /dev/ /target/dev/ ; check_exit
mount --bind /proc/ /target/proc/ ; check_exit
mount --bind /sys/ /target/sys/ ; check_exit
echo "I: Installing bootloader to $INSTALL_GRUB"
chroot /target grub-install $INSTALL_GRUB
chroot /target update-grub
echo "I: Removing live user from installation"
chroot /target deluser user
chroot /target rm -rf /home/user
echo "I: Disabling autologin"
chroot /target cp /usr/lib/bbqinstaller/inittab.debian /etc/inittab
echo "I: Setting terminal capabilities"
chroot /target setcap 'cap_sys_tty_config+ep' /usr/bin/fbterm
echo "I: Cleaning up"
if $(df | grep -q /target/proc/) ; then
umount /target/proc/
fi
if $(df | grep -q /target/dev/) ; then
umount /target/dev/
fi
if $(df | grep -q /target/sys/) ; then
umount /target/sys/
fi
if $(df | grep -q /target) ; then
umount -l /target/
fi
echo "I: Success. Installation finished."
echo
echo -e "You can now boot into the newly installed system and log in as \e[1mroot\e[0m using the password \e[1mroot\e[0m."
echo -e "Then, change the root password using the command \e[1mpasswd root\e[0m."
echo -e "Add new users using the command \e[1madduser <username>\e[0m."