-
Notifications
You must be signed in to change notification settings - Fork 4
/
debstrap.sh
162 lines (140 loc) · 4.85 KB
/
debstrap.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
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
161
162
#!/bin/bash
## debstrap.sh by Ian LeCorbeau: a simple debootstrapping script that will
## install a custom, minimal Debian system.
# Using a few variables for convenience
DEVICE=$1
BOOTMODE=$2
SWAPSPACE=
ROOTSPACE=
HOMESPACE=
## 'set -e' should really only be enabled for debugging purposes. Though it might seem
## useful to have the script exit when there's an error, the reality is that some errors
## are normal and expected (such as debconf errors) and the last thing you want is for the
## script to fail 3/4 of the way through because of something inconsequential.
#set -e
usage() {
printf '%s\n' "You must provide the name of the device on which the system is to be installed (eg: sda) and the boot mode (bios or efi)"
exit
}
print_dev() {
sed -i "s/DEVICE/$DEVICE/g" debstrap_in_chroot.sh
sed -i "s/BOOTMODE=/BOOTMODE=$BOOTMODE/g" debstrap_in_chroot.sh
}
get_deps() {
printf '%s\n' "Getting installer dependencies" &&
apt update && apt install debootstrap arch-install-scripts curl -y
}
makepart() {
echo
printf "The system will be installed on /dev/$DEVICE in $BOOTMODE mode. Proceed? (Y/n): "
read -r answer
if [ "$answer" = n ]; then
printf '%s\n' "Exiting script. Start again"
exit
else
echo
printf '%s\n' "Partitioning /dev/$DEVICE."
sfdisk --delete /dev/"$DEVICE"
partprobe /dev/"$DEVICE"
if [ "$BOOTMODE" = "bios" ]; then
(echo o) | fdisk /dev/"$DEVICE"
(echo n; echo p; echo 1; echo ; echo +"$SWAPSPACE"G; echo w) | fdisk /dev/"$DEVICE"
sfdisk --part-type /dev/"$DEVICE" 1 82
(echo n; echo p; echo 2; echo ; echo +"$ROOTSPACE"G; echo w) | fdisk /dev/"$DEVICE"
if [ -z "$HOMESPACE" ]; then
(echo n; echo p; echo 3; echo ; echo ; echo w) | fdisk /dev/"$DEVICE"
else
(echo n; echo p; echo 3; echo ; echo +"$HOMESPACE"G; echo w) | fdisk /dev/"$DEVICE"
fi
partprobe /dev/"$DEVICE" && sleep 1
printf '%s\n' "Creating Partitions" && sleep 1
mkswap /dev/"$DEVICE"1
swapon /dev/"$DEVICE"1
mkfs.ext4 /dev/"$DEVICE"2
mkfs.ext4 /dev/"$DEVICE"3
printf '%s\n' "Mounting Partitions" && sleep 1
mount /dev/"$DEVICE"2 /mnt
mkdir -p /mnt/home
mount /dev/"$DEVICE"3 /mnt/home
else
echo
printf '%s\n' "Partitioning /dev/$DEVICE."
sfdisk --delete /dev/"$DEVICE" && sleep 1
partprobe /dev/"$DEVICE" && sleep 1
(echo g) | fdisk /dev/"$DEVICE"
(echo n; echo p; echo 1; echo 2048; echo +600M; echo w) | fdisk /dev/"$DEVICE"
sfdisk --part-type /dev/"$DEVICE" 1 EF
(echo n; echo p; echo 2; echo ; echo +"$SWAPSPACE"G; echo w) | fdisk /dev/"$DEVICE"
sfdisk --part-type /dev/"$DEVICE" 2 82
(echo n; echo p; echo 3; echo ; echo +"$ROOTSPACE"G; echo w) | fdisk /dev/"$DEVICE"
if [ -z "$HOMESPACE" ]; then
(echo n; echo p; echo 4; echo ; echo ; echo w) | fdisk /dev/"$DEVICE"
else
(echo n; echo p; echo 4; echo ; echo +"$HOMESPACE"G; echo w) | fdisk /dev/"$DEVICE"
fi
partprobe /dev/"$DEVICE" && sleep 1
printf '%s\n' "Creating Partitions" && sleep 1
mkfs.fat -F 32 /dev/"$DEVICE"1
mkswap /dev/"$DEVICE"2
swapon /dev/"$DEVICE"2
mkfs.ext4 /dev/"$DEVICE"3
mkfs.ext4 /dev/"$DEVICE"4
printf '%s\n' "Mounting Partitions" && sleep 1
mount /dev/"$DEVICE"3 /mnt
mkdir -p /mnt/home
mkdir -p /mnt/boot
mount /dev/"$DEVICE"4 /mnt/home
fi
fi
}
bootstrap() {
echo
printf '%s\n' "Deboostraping base system" && sleep 1
/usr/sbin/debootstrap --variant=minbase bullseye /mnt http://deb.debian.org/debian/
}
gen_fstab() {
echo
printf '%s\n' "Generating fstab..." && sleep 1
genfstab -U /mnt >> /mnt/etc/fstab
}
apt_src_list() {
echo
printf '%s\n' "Generating apt sources.list" && sleep 1
printf '%s\n' "deb http://deb.debian.org/debian/ bullseye main contrib non-free
deb-src http://deb.debian.org/debian/ bullseye main contrib non-free
deb http://security.debian.org/debian-security bullseye-security main contrib non-free
deb-src http://security.debian.org/debian-security bullseye-security main contrib non-free
deb http://deb.debian.org/debian/ bullseye-updates main contrib non-free
deb-src http://deb.debian.org/debian/ bullseye-updates main contrib non-free" > /mnt/etc/apt/sources.list
}
get_files() {
printf '%s\n' "Fetching custom .profile and .bash_aliases" && sleep 1
curl -O https://raw.githubusercontent.com/I-LeCorbeau/debian-live-build/main/config/includes.chroot_after_packages/etc/skel/.bash_aliases
mv .bash_aliases /mnt/etc/skel/.bash_aliases
curl -O https://raw.githubusercontent.com/I-LeCorbeau/debian-live-build/main/config/includes.chroot_after_packages/etc/skel/.profile
mv .profile /mnt/etc/skel/.profile
}
cpfiles() {
cp /etc/adjtime /mnt/etc/adjtime
cp debstrap_in_chroot.sh /mnt/debstrap_in_chroot.sh
chmod +x /mnt/debstrap_in_chroot.sh
}
get_in_chroot() {
arch-chroot /mnt ./debstrap_in_chroot.sh
}
main(){
print_dev
get_deps
makepart
bootstrap
gen_fstab
apt_src_list
get_files
cpfiles
get_in_chroot
}
if [ -z "$1" ]; then
usage
else
main
fi