forked from RayViljoen/Raspberry-PI-SD-Installer-OS-X
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall
executable file
·125 lines (94 loc) · 2.97 KB
/
install
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
#!/bin/bash
# Raspberry PI Install Script
# Author: Ray Viljoen
# Quit on error
set -e
_piline="------------------------------------------------------------------------------------"
# Display colorized information output
function _info() {
COLOR='\033[00;32m' # green
RESET='\033[00;00m' # white
echo -e "${COLOR}${@}${RESET}"
}
# Display colorized warning output
function _warn() {
COLOR='\033[00;31m' # red
RESET='\033[00;00m' # white
echo -e "${COLOR}${@}${RESET}"
}
_info '
__________.___ .___ __ .__ .__
\______ \ | | | ____ _______/ |______ | | | | ___________
| ___/ | | |/ \ / ___/\ __\__ \ | | | | _/ __ \_ __ \
| | | | | | | \\___ \ | | / __ \| |_| |_\ ___/| | \/
|____| |___| |___|___| /____ > |__| (____ /____/____/\___ >__|
\/ \/ \/ \/
'
# Set $1 as image path
DISTRO="$1"
# Check image path is set else exit
if [ -z "$DISTRO" ]; then
_warn $_piline
_warn "ERR: No image path supplied"
_warn $_piline
exit 0
fi
# Selected disk
_udisk=""
function promptDisk() {
# ================================================
# Check connected disks and save paths to array
# ================================================
# Counter
i=0
echo $_piline
# Loop over df -lh
while read line; do
# Print with local mount only and add counter to select disk
if [ "$i" -gt 0 ]; then
echo "$i) $line"
# Asign first work (path) to array with corresponding counter
_mount[i]=$( echo $line | awk '{print $1;}')
else
_info " $line"
echo $_piline
fi
# Increment counter
((i++))
done <<< "$(df -h)"
echo -e "$_piline\n"
_opts=''
for i in "${!_mount[@]}"; do
[ -z "$_opts" ] && _opts="${_opts}${i}" || _opts="${_opts}, ${i}"
done
# Ask user to select mounted disk
echo "Select the disk to use by enetering the disk number."
_warn "*** MAKE SURE YOU SELECT THE CORRECT DISK ***"
_warn "*** Refer to the Readme if uncertain ***"
echo -n -e "\nUse disk [ $_opts ] #"
read ans
# Set selected disk
_udisk=${_mount[$ans]}
# Test if valid disk selected
if [ -z "$_udisk" ]; then
_warn "\n ======= Invalid selection ======= \n"
promptDisk
fi
}
# Run prompt
promptDisk
# ===========================================================
# Past this point a valid disk has been selected, so proceed.
# ===========================================================
# Format disk name to raw format
_rawdisk=$( echo $_udisk | awk 'sub("..$", "")' | sed 's/disk/rdisk/')
# Unmount Disk
echo "Unmounting Disk"
diskutil unmount $_udisk
echo "Writing image"
echo "Ctrl+T to see progress.."
sudo dd bs=1m if=${DISTRO} of=${_rawdisk}
# Eject disk
echo "Ejecting Disk"
diskutil eject ${_rawdisk}
_info "All Done!"