-
Notifications
You must be signed in to change notification settings - Fork 19
/
quick-install-linux.sh
executable file
·174 lines (153 loc) · 6.62 KB
/
quick-install-linux.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
#!/usr/bin/env bash
if [[ -n "$CERC_SCRIPT_DEBUG" ]]; then
set -x
fi
install_dir=~/bin
# Skip the package install stuff if so directed
if ! [[ -n "$CERC_SO_INSTALL_SKIP_PACKAGES" ]]; then
# First display a reasonable warning to the user unless run with -y
if ! [[ $# -eq 1 && $1 == "-y" ]]; then
echo "**************************************************************************************"
echo "This script requires sudo privilege. It installs Laconic Stack Orchestrator"
echo "into: ${install_dir}. It also *removes* any existing docker installed on"
echo "this machine and then installs the latest docker release as well as other"
echo "required packages."
echo "Only proceed if you are sure you want to make those changes to this machine."
echo "**************************************************************************************"
read -p "Are you sure you want to proceed? " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# This script assumes root permissions on a fresh Ubuntu Digital Ocean droplet
# with these recommended specs: 16 GB Memory / 8 Intel vCPUs / 320 GB Disk
# TODO:
# Check python3 is available
# Check machine resources are sufficient
# Determine if we are on Debian or Ubuntu
linux_distro=$(lsb_release -a 2>/dev/null | grep "^Distributor ID:" | cut -f 2)
# Some systems don't have lsb_release installed (e.g. ChromeOS) and so we try to
# use /etc/os-release instead
if [[ -z "$linux_distro" ]]; then
if [[ -f "/etc/os-release" ]]; then
distro_name_string=$(grep "^NAME=" /etc/os-release | cut -d '=' -f 2)
if [[ $distro_name_string =~ Debian ]]; then
linux_distro="Debian"
elif [[ $distro_name_string =~ Ubuntu ]]; then
linux_distro="Ubuntu"
fi
else
echo "Failed to identify distro: /etc/os-release doesn't exist"
exit 1
fi
fi
case $linux_distro in
Debian)
echo "Installing docker for Debian"
;;
Ubuntu)
echo "Installing docker for Ubuntu"
;;
*)
echo "ERROR: Detected unknown distribution $linux_distro, can't install docker"
exit 1
;;
esac
# dismiss the popups
export DEBIAN_FRONTEND=noninteractive
## https://docs.docker.com/engine/install/ubuntu/
## https://docs.docker.com/engine/install/debian/
## https://superuser.com/questions/518859/ignore-packages-that-are-not-currently-installed-when-using-apt-get-remove1
packages_to_remove="docker docker-engine docker.io containerd runc docker-compose docker-doc podman-docker"
installed_packages_to_remove=""
for package_to_remove in $(echo $packages_to_remove); do
$(dpkg --info $package_to_remove &> /dev/null)
if [[ $? -eq 0 ]]; then
installed_packages_to_remove="$installed_packages_to_remove $package_to_remove"
fi
done
# Enable stop on error now, since we needed it off for the code above
set -euo pipefail ## https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
if [[ -n "${installed_packages_to_remove}" ]]; then
echo "**************************************************************************************"
echo "Removing existing docker packages"
sudo apt -y remove $installed_packages_to_remove
fi
echo "**************************************************************************************"
echo "Installing dependencies"
sudo apt -y update
# laconic-so depends on jq
sudo apt -y install jq
# laconic-so depends on git
sudo apt -y install git
# curl used below
sudo apt -y install curl
# docker repo add depends on gnupg and updated ca-certificates
sudo apt -y install ca-certificates gnupg
# Add dockerco package repository
# For reasons not obvious, the dockerco instructions for installation on
# Debian and Ubuntu are slightly different here
case $linux_distro in
Debian)
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
;;
Ubuntu)
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
;;
*)
echo "ERROR: Detected unknown distribution $linux_distro, can't install docker"
exit 1
;;
esac
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/${linux_distro,,} \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Penny in the update jar
sudo apt -y update
echo "**************************************************************************************"
echo "Installing docker"
sudo apt -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# Allow the current user to use Docker
sudo usermod -aG docker $USER
# End of long if block: Skip the package install stuff if so directed
fi
echo "**************************************************************************************"
echo "Installing laconic-so"
# install latest `laconic-so`
distribution_url=https://git.vdb.to/cerc-io/stack-orchestrator/releases/download/latest/laconic-so
install_filename=${install_dir}/laconic-so
mkdir -p ${install_dir}
curl -L -o ${install_filename} ${distribution_url}
chmod +x ${install_filename}
# Set up config file for self-update feature
mkdir ~/.laconic-so
echo "distribution-url: ${distribution_url}" > ~/.laconic-so/config.yml
echo "**************************************************************************************"
# Check if our PATH line is already there
path_add_command="export PATH=\$PATH:${install_dir}"
if ! grep -q "${path_add_command}" ~/.profile
then
echo "Adding this line to the end of ~/.profile:"
echo ${path_add_command}
echo ${path_add_command} >> ~/.profile
fi
echo "**************************************************************************************"
# PATH set here for commands run in this script
export PATH=$PATH:${install_dir}
echo Installed laconic-so version: $(laconic-so version)
echo "**************************************************************************************"
echo "The Laconic Stack Orchestrator program laconic-so has been installed at ${install_filename}"
echo "The directory ${install_dir} has been added to PATH in *new* shells via ~/.profile"
echo "**************************************************************************************"
# Message the user to check docker is working for them
echo "Please log in again (docker will not work in this current shell) then:"
echo "test that docker is correctly installed and working for your user by running the"
echo "command below (it should print a message beginning \"Hello from Docker!\"):"
echo
echo "docker run hello-world"
echo