-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
152 lines (134 loc) · 3.83 KB
/
bootstrap.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
#!/bin/bash
#
# Bootstraps RPiLight on a Fresh Raspberry Pi
#
function usage()
{
echo "usage: bootstrap.sh"
echo
echo "Installs dependencies required to build (including Swift)"
}
#
# Detecting Distro
#
function process_distro() {
. /etc/os-release
distro_string="$ID-$VERSION_ID"
}
#
# Install Specific Versions of Swift
#
function install_swift_tarball() {
swift_release="$1"
swift_version="5.1.5"
tarball_url="https://github.com/uraimo/buildSwiftOnARM/releases/download/${swift_version}/swift-${swift_version}-${swift_release}.tgz"
swift_filename="swift-${swift_version}-${swift_release}.tgz"
echo "Downloading ${tarball_url}"
pushd ~
curl -L -o "$swift_filename" "$tarball_url"
swift_filename=~/$swift_filename
popd
echo "Installing Swift ${swift_version} to /opt/swift"
echo "WARNING: This will delete any existing data at /opt/swift"
sudo rm -rf /opt/swift
sudo mkdir -p /opt/swift
pushd /opt/swift
pv "${swift_filename}" | sudo tar -zx --strip-components=1
popd
#
# Need to add /opt/swift/bin to the PATH Before we can use it.
# This enables swift for all users on the device going forward.
#
swift_path="export PATH=\$PATH:/opt/swift/bin"
swift_profile="/etc/profile.d/swiftlang.sh"
echo $swift_path | sudo tee -a $swift_profile
# REVIEW: Should we delete the tarball once we know it's been installed?
}
#
# Distro-Specific Dependencies
#
function install_common_dependencies() {
echo "Installing Common Dependencies..."
sudo apt-get install --yes \
chrpath \
git \
pv
}
function install_stretch_dependencies() {
echo "Installing Dependencies for Raspbian Stretch / Ubuntu Xenial..."
sudo apt-get install --yes \
clang-3.8 \
libicu-dev \
libcurl4-nss-dev \
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.8 100
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.8 100
}
function install_buster_dependencies() {
echo "Installing Dependencies for Raspbian Buster / Ubuntu Bionic..."
sudo apt-get install --yes \
clang \
libicu-dev \
libcurl4-nss-dev \
curl
}
function update_apt() {
echo "Updating apt Package Database..."
if [ "$1" == "1" ]; then
apt-get update --allow-releaseinfo-change
else
apt-get update
fi
}
function install_dependencies() {
install_common_dependencies
case "$distro_string" in
debian-9)
update_apt 0
install_stretch_dependencies
install_swift_tarball "armv7-DebianStretch"
;;
raspbian-9)
update_apt 0
install_stretch_dependencies
install_swift_tarball "armv6-RPi0123-RaspbianStretch"
;;
ubuntu-16.*)
update_apt 0
install_stretch_dependencies
install_swift_tarball "armv7-Ubuntu1604"
;;
debian-10)
update_apt 0
install_buster_dependencies
install_swift_tarball "armv7-DebianBuster"
;;
raspbian-10)
update_apt 1
install_buster_dependencies
install_swift_tarball "armv6-RPi01234-RaspbianBuster"
;;
ubuntu-18.*)
update_apt 0
install_buster_dependencies
install_swift_tarball "armv7-Ubuntu1804"
;;
esac
}
#
# Script Flow
#
BUILD=1
while [ "$1" != "" ]; do
case $1 in
nobuild ) BUILD=0
;;
* ) usage
exit 1
esac
shift
done
process_distro
cd ~
# Install the Dependencies
install_dependencies
popd > /dev/null