-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarm
executable file
·92 lines (80 loc) · 2.39 KB
/
alarm
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
#!/usr/bin/env bash
echo " ";
echo " 888 ";
echo " 888 ";
echo " 888 ";
echo " 8888b. 888 8888b. 888d888 88888b.d88b. ";
echo " \"88b 888 \"88b 888P\" 888 \"888 \"88b ";
echo ".d888888 888 .d888888 888 888 888 888 ";
echo "888 888 888 888 888 888 888 888 888 ";
echo "\"Y888888 888 \"Y888888 888 888 888 888 ";
echo " ";
if [ "$(id -u)" -ne 0 ]; then
echo "Please run as root"
exit
fi
readonly YELLOW='\033[1;33m'
readonly BOLD='\033[1m'
readonly NC='\033[0m'
readonly SD="$1"
readonly HOSTNAME="$2"
if [ -z "$SD" ]; then
echo "Missing device to flash on"
exit 2
fi
echo -e "${YELLOW}WARNING!${NC}"
echo -e "About to flash Arch Linux ARM on ${YELLOW}$SD${NC}. All data will be lost."
while true; do
read -rp "Do you wish to continue? [y/n] " yn
case "$yn" in
[Nn]* )
echo "Aborting."
exit;;
[Yy]* )
break;;
esac
done
MIRROR="http://os.archlinuxarm.org/os"
FS="ArchLinuxARM-rpi-2-latest.tar.gz"
echo -e "${BOLD}[INFO]${NC} Removing signatures from drive..."
wipefs --all --force "$SD"
echo -e "${BOLD}[INFO]${NC} Setting up partition layout..."
echo "o
n
p
1
+100M
t
c
n
p
2
w" | fdisk "$SD" > /dev/null
echo -e "${BOLD}[INFO]${NC} Formatting partitions..."
yes | mkfs.vfat "$SD"1
yes | mkfs.ext4 "$SD"2
echo -e "${BOLD}[INFO]${NC} Preparing folder mounts..."
mkdir -p boot root
mount "$SD"1 boot
mount "$SD"2 root
echo -e "${BOLD}[INFO]${NC} Downloading filesystem..."
wget "$MIRROR"/"$FS" -q --show-progress
echo -e "${BOLD}[INFO]${NC} Flashing Arch Linux ARM..."
bsdtar -xpf "$FS" -C root
echo -e "${BOLD}[INFO]${NC} Committing buffer cache to disk. This may take a while..."
sync
echo -e "${BOLD}[INFO]${NC} Committing boot files..."
mv root/boot/* boot
echo -e "${BOLD}[INFO]${NC} Preparing setup script..."
echo "#!/usr/bin/env sh" > root/home/alarm/setup.sh
echo "pacman-key --init" >> root/home/alarm/setup.sh
echo "pacman-key --populate archlinuxarm" >> root/home/alarm/setup.sh
if [ -n "$HOSTNAME" ]; then
echo -e "${BOLD}[INFO]${NC} Setting hostname to $HOSTNAME..."
echo "$HOSTNAME" > root/etc/hostname
fi
echo -e "${BOLD}[INFO]${NC} Cleaning up..."
umount boot root
rmdir boot root
rm "$FS"
echo "Done!"