This repository has been archived by the owner on Apr 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 55
/
setup.sh
200 lines (156 loc) · 5.55 KB
/
setup.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
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# Import
source utils/functions.sh # Functions
source utils/bootstrap.sh # Bootstrap Function
source utils/partition.sh # USB Partitioning
source utils/extract.sh # Extract Rootfs
source utils/system.sh # Host OS Abstraction
# Exit if the user did not specify the desktop
[[ -n "$1" ]] || { printerr "No desktop specified"; exit; }
[[ -n "$2" ]] || { printerr "No distro specified, using Ubuntu"; set -- $1 "ubuntu"; }
# Distro and desktop variables from arguments
export DESKTOP=$1
export DISTRO=$2
export DISTRO_VERSION=$3
export ORIGINAL_DIR=$(pwd)
sudo mkdir -p /mnt/breath
ls /mnt/breath && {
sudo umount /mnt/breath || true
sudo rm -rf /mnt/breath/*
}
export MNT="/mnt/breath"
# Import a seperate postinstall function depending on the distro
# shellcheck source=utils/ubuntu_postinstall.sh
source utils/distros/${DISTRO}.sh
# Exit on errors
set -e
# Many much importance
installDependencies toilet
# Print 15 lines to "fake" clear the screen
# shellcheck disable=SC2034
for i in {1..15}
do
echo
done
# Show title message - I told you it was important
toilet -f mono12 -F crop "Breath"
toilet -f term -F border "Made by MilkyDeveloper"
if [[ $FEATURES == *"KEYMAP"* ]]; then
# Ask to make the Search key a Caps Lock key
printq "Would you like to make the Search Key a Caps Lock key?"
read -r BREATH_CAPSLOCK
export BREATH_CAPSLOCK
fi
# Ask for username
printq "What would you like the username to be?"
printq "NOTE: No UPPERCASE letters, spaces, backslashes, or special characters"
read -r BREATH_USER
export BREATH_USER
# Ask for hostname
printq "\nWhat would you like the hostname to be? (if no hostname is specified, it will be ${DISTRO})"
printq "NOTE: No spaces, backslashes, or special characters"
read -r BREATH_HOST
# If the output is null, use the default hostname
if [ -z $BREATH_HOST ]; then
BREATH_HOST=$DISTRO
echo "Using the default hostname, $DISTRO"
fi
export BREATH_HOST
# Bootstrap files
bootstrapFiles
# If the user wants to build an ISO, the partition numbers are different
# (e.g.) /dev/sda2 or /dev/loop9p2 (notice the "p")
if [[ $FEATURES == *"ISO"* ]]; then
# Create and mount a 6GB IMG File
echo "Building ISO at ${PWD}/breath.img"
sleep 10
fallocate -l 12G breath.img
export USB=$(sudo losetup -f --show breath.img)
if [[ -z "$USB" ]]; then
echo "ERROR: no loop device"
exit 1
fi
export USB1="${USB}p1"
export USB2="${USB}p2"
else
# Wait for a USB to be plugged in
waitForUSB
# Ask user which USB Device they would like to use
printq "Which USB Drive or SD Card would you like to use (e.g. /dev/sda)? All data on the drive will be wiped!"
lsblk -o name,model,tran | grep --color=never "usb"
read USB
printq "Ok, using $USB to install Linux"
export USB1="${USB}1"
export USB2="${USB}2"
fi
# Unmount all partitions on the USB and /mnt
unmountUSB
# Partition the USB
partitionUSB
# Our USB has now been fully partitioned
# (1) Write the kernel to a 64mb Partition
# (2) Write a Linux distro rootfs to a partition filling the rest of the storage
# We used to do this in bootstrapFiles,
# but we now need the UUID, only available after partitioning,
# to allow booting on all platform's SD Card slot
postBootstrapFiles
# Flash the signed kernel to the kernel partition
sudo dd if=bzImage.signed of=${USB1}
# Format the root partition as ext4 and mount it to /mnt
yes | sudo mkfs.ext4 ${USB2}
syncStorage
sudo umount $MNT || sudo umount -lf $MNT || true
sudo rm -rf ${MNT}/*
sudo mount ${USB2} $MNT
# Extract the rootfs
extractRootfs
# Post-install for specific distros (located in utils/$DISTRO_postinstall.sh)
printq "Running post-installation steps for $DISTRO"
postinstall
# The heredoc (<<EOT) method of running commands in a chroot isn't interactive,
# but luckily passwd has an option to chroot
# In case a user mistypes the password confirmation, retry the password
printq "What would you like the root user's password to be?"
until sudo chroot $MNT sh -c "passwd root"; do printerr "Retrying Password"; sleep 1; done
# Copy (hopefully up-to-date) firmware from the host to the USB
sudo mkdir -p ${MNT}/lib/firmware
sudo cp -Rv /lib/firmware/* ${MNT}/lib/firmware || true
syncStorage
# Extract the modules to /mnt
extractModules
# Set the hostname
cat > hostname << EOF
${BREATH_HOST}
EOF
sudo cp hostname ${MNT}/etc/
# Set the hostname in hosts
sudo sed -i "1a\\127.0.1.1 ${BREATH_HOST}" ${MNT}/etc/hosts
# Install all utility files in the bin directory
cd $ORIGINAL_DIR
sudo chmod 755 bin/*
sudo cp bin/* ${MNT}/usr/local/bin
syncStorage
if [[ $FEATURES == *"KEYMAP"* ]]; then
# Set keymap
# Backup the default keymap and copy in the new map
sudo cp -n ${MNT}/usr/share/X11/xkb/symbols/pc ${MNT}/usr/share/X11/xkb/symbols/pc.org
sudo cp xkb/xkb.chromebook ${MNT}/usr/share/X11/xkb/symbols/pc
# Make the Search key a Caps_Lock key, if wanted by the user
# Backup the default event definitions and copy in the new one
if [[ $BREATH_CAPSLOCK =~ ^[Yy]$ ]]; then
sudo cp -n ${MNT}/usr/share/X11/xkb/keycodes/evdev ${MNT}/usr/share/X11/xkb/keycodes/evdev.org
sudo cp xkb/evdev.chromebook ${MNT}/usr/share/X11/xkb/keycodes/evdev
fi
fi
sudo umount $MNT
set +u
printq "Done!"
if [[ $FEATURES == *"ISO"* ]]; then
sudo losetup -d $USB
echo "IMG built at ~/linux-build/breath.img"
echo "You can flash this raw image using Etcher, Rufus, DD, or other ISO flash tools."
fi
echo "Plug the $DISTRO USB with the $DESKTOP desktop into the Chromebook."
echo "Boot with CTRL+U from the OS verification screen."
echo "(Provided that you have enabled USB booting as documented)"
set -u