-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer.sh
executable file
·190 lines (151 loc) · 3.39 KB
/
installer.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/bin/sh -e
printf 'Welcome to the Iglunix guided installer\n'
prompt() {
# usage:
# prompt <prompt> <default> <var> [options ...]
q="$1"
default="$2"
d_prompt="$default"
if [ -z "$d_prompt" ]
then
d_prompt=none
fi
var="$3"
shift; shift; shift;
answer=''
while [ -z "$answer" ]
do
printf '%s: ' "$q"
[ ! -z "$1" ] && printf '%s ' "$@"
printf '[%s]: ' "$d_prompt"
read answer
if [ -z "$answer" ]
then
answer=$default
fi
done
read "$var" << EOF
$answer
EOF
}
glob_exists() {
while true
do
if [ -e "$1" ]
then
printf '%s\n' "$1"
fi
shift 2>/dev/null >/dev/null || break
done
}
confirm() {
while true
do
printf 'please press Y to confirm or N to exit: '
read X
[ "$X" == "Y" ] && break
if [ "$X" == "N" ]
then
printf 'installation aborted!\n'
exit
fi
done
}
set +e
disks=$(glob_exists /dev/sd? /dev/nvme?n?)
set -e
prompt 'Select Disk' '' disk $disks
prompt 'Enter Hostname' 'iglunix' hostname
printf 'You are about to install iglunix with the following configuration:%s\n'
printf '\n'
printf ' to the disk : %s\n' "$disk"
printf ' with hostname : %s\n' "$hostname"
printf '\n'
printf 'WARNING: this will WIPE ALL DATA on %s\n' "$disk"
printf '\n'
confirm
printf 'Disk %s will be partitioned with the following layout: \n' "$disk"
printf '\n'
printf ' first 512B : MBR\n'
printf ' next 1536B : Empty space\n'
printf ' next 512MiB : EFI system partition mount : /boot format: VFAT\n'
printf ' rest of disk : root partition mount : / format: EXT4\n'
printf '\n'
printf 'Would you like to commit these changes to the disk?\n'
confirm
printf 'Writing partition table'
fdisk "$disk" << EOF
o
n
p
1
2048
1048575
t
ef
n
p
2
1048576
w
EOF
sync
printf 'Formatting ESP /boot\n'
set -- $disk*1
if [ ! -e "$1" ]
then
printf 'WTF went wrong. The boot partition does not exist!\n'
exit 1
fi
BOOT="$1"
mkfs.vfat -n "IGLU_BOOT" "$BOOT"
printf 'Formatting Root /\n'
set -- $disk*2
if [ ! -e "$1" ]
then
printf 'WTF went wrong. The root partition does not exist!\n'
exit 1
fi
ROOT="$1"
mkfs.ext4 -L "IGLU_ROOT" "$ROOT"
printf 'Mounting file systems\n'
mkdir -p /mnt/new-root
mount -t ext4 "$ROOT" /mnt/new-root
mkdir -p /mnt/new-root/boot
mount -t vfat "$BOOT" /mnt/new-root/boot
boot_disk=$(findfs LABEL='IGLUNIX_IMG')
printf 'Extracting packages'
mkdir -p /mnt/boot-disk
mount -t vfat $boot_disk /mnt/boot-disk
pkgs=$(tar -I zstd -tf /mnt/boot-disk/pkgs.tar.zst)
for pkg in $pkgs
do
tar -I zstd -xf /mnt/boot-disk/pkgs.tar.zst $pkg -C /tmp
tar -xf /tmp/$pkg -C /mnt/new-root
rm -f /tmp/$pkg
done
mkdir -p /mnt/new-root/etc
printf 'Setting hostname\n'
printf '%s\n' "$hostname" > /mnt/new-root/etc/hostname
printf 'Setting fstab\n'
printf 'LABEL=IGLU_ROOT / ext4 defaults 0 0\n' > /mnt/new-root/etc/fstab
printf 'LABEL=IGLU_BOOT /boot vfat defaults 0 0\n' >> /mnt/new-root/etc/fstab
printf 'Adding root user\n'
cat > /mnt/new-root/etc/passwd << EOF
root:x:0:0:Admin,,,:/root:/bin/sh
EOF
cat > /mnt/new-root/etc/group << EOF
root:x:0:
EOF
cat > /mnt/new-root/etc/shadow << EOF
root::::::::
EOF
chmod 600 /mnt/new-root/etc/shadow
printf 'Set root password\n'
chroot /mnt/new-root /bin/busybox passwd
printf 'Generating initrd\n'
mkdir -p /mnt/new-root/tmp
mount --bind /tmp /mnt/new-root/tmp
chroot /mnt/new-root /sbin/mkrd
printf 'Installation should now be finished!\n'
printf 'Chroot into your new system to inspect everything before rebooting\n'