-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-sdcard-archlinuxarm.sh
executable file
·78 lines (65 loc) · 2.28 KB
/
install-sdcard-archlinuxarm.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
#!/bin/bash
######################################################################
#
# Copyright (c) 2015 revosftw (https://github.com/revosftw)
#
######################################################################
#!/bin/sh
prepare_mmc () {
lsblk
echo -e "\nSelect the SD CARD (ex: /dev/sda):"
read device
partitions=($(lsblk "$device" | fgrep '─' | sed -E 's/^.+─(\w+).+$/\1/g'))
echo -e "Unmount SD CARD"
for eachPartion in "${partitions[@]}"
do sudo umount -v "/dev/$eachPartion"
done
lsblk
read -p "Press enter to continue"
echo -e "Prepating SD CARD"
(echo o; echo n; echo p;echo 1; echo ; echo +100M; echo t; echo c; echo n; echo p; echo 2; echo ; echo ;echo w)|sudo fdisk $device
sudo fdisk -l $device
echo -e "Preparing /boot partition"
sudo mkfs.vfat -n "arm_boot" "/dev/${partitions[0]}"
mkdir boot
sudo mount "/dev/${partitions[0]}" boot
echo -e "Mounted /boot partition"
echo -e "Preparing /root partition"
sudo mkfs.ext4 -L "arm_root" "/dev/${partitions[1]}"
mkdir root
sudo mount "/dev/${partitions[1]}" root
echo -e "Mounted /root partition"
}
download_archlinux () {
echo -e "Searching for ArchLinuxARM-$1-latest.tar.gz"
ls|grep -qs "ArchLinuxARM-$1"
response=${response:="y"}
if ls|grep -qsc "ArchLinuxARM-$1"; then
echo -e "Found. Use old copy of ArchLinuxARM ? [\e[1mY\e[21m/n]"
read response
response=${response:="y"}
else
wget -q --show-progress --continue "http://archlinuxarm.org/os/ArchLinuxARM-$1-latest.tar.gz"
fi
if echo "$response" | grep -iq "^n"; then
wget -q --show-progress --continue "http://archlinuxarm.org/os/ArchLinuxARM-$1-latest.tar.gz"
fi
}
write_to_mmc () {
echo -e "Extracting image to SD CARD"
sudo su -c "bsdtar -xpf ArchLinuxARM-$1-latest.tar.gz -C root"
sudo su -c 'sync'
echo -e "Finalizing boot partition"
sudo mv root/boot/* boot
sudo umount boot root
sudo su -c "rm -rf boot root"
echo -e "SD CARD ready to boot with ArchLinuxARM."
echo -e "Default SSH credentials:\n\t\tusername:alarm\n\t\tpassword:alarm\n\t\troot-password: root"
}
[ "$UID" -eq 0 ] || exec sudo sh "$0" "$@"
echo -e "\nSelect Raspberry Pi Version (ex: rpi rpi-2)[\e[1mrpi-2\e[21m]:"
read raspberrypi_version
raspberrypi_version=${raspberrypi_version:="rpi-2"}
download_archlinux $raspberrypi_version
prepare_mmc
write_to_mmc $raspberrypi_version