-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ubuntu.sh
executable file
·118 lines (91 loc) · 3.99 KB
/
setup.ubuntu.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
#/bin/bash
#
# Copyright (c) 2021-2024 Krai Ltd.
#
# SPDX-License-Identifier: MIT.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
source ./functions.sh
_WORKSPACE_DIR=${WORKSPACE_DIR:-/local/mnt/workspace}
_APT_INSTALL=${APT_INSTALL:-yes}
_DOCKER_INSTALL=${DOCKER_INSTALL:-yes}
_GH_INSTALL=${GH_INSTALL:-yes}
echo "Running '$0' ..."
print_variables "${!_@}"
echo
echo "Press Ctrl-C to break ..."
sleep 10
# Install system packages using apt.
if [[ "${_APT_INSTALL}" == "yes" ]]; then
echo "Installing via apt ..."
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y \
git wget patch vim \
libbz2-dev lzma \
python3-dev python3-pip \
lm-sensors ipmitool \
linux-tools-common linux-tools-generic hwdata \
ca-certificates curl gnupg lsb-release \
acl tree
sudo apt clean all
exit_if_error "apt install failed!"
fi # APT_INSTALL
# Install Docker following: https://docs.docker.com/engine/install/ubuntu/
if [[ "${_DOCKER_INSTALL}" == "yes" ]]; then
echo "Installing Docker ..."
# Remove old Docker installations.
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo mkdir -p /etc/apt/keyrings
sudo mv /etc/apt/keyrings/docker.gpg{,.bak}
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin
export WORKSPACE_DIR=${_WORKSPACE_DIR}
export WORKSPACE_DOCKER=${_WORKSPACE_DIR}/docker
export DOCKER_DAEMON_JSON=/etc/docker/daemon.json
sudo mkdir -p $WORKSPACE_DOCKER
sudo cp $DOCKER_DAEMON_JSON{,.bak}
echo -e "{\n\t\"data-root\": \"$WORKSPACE_DOCKER\"\n}" | sudo tee -a $DOCKER_DAEMON_JSON
cat $DOCKER_DAEMON_JSON
sudo service docker restart
sudo docker system info | grep "Docker Root Dir:"
# Test.
sudo docker --version
sudo docker run hello-world
sudo docker image ls
exit_if_error "Docker installation failed!"
fi # DOCKER_INSTALL
if [[ "${_GH_INSTALL}" == "yes" ]]; then
echo "Installing GitHub CLI ..."
# Install GitHub CLI folllowing: https://github.com/cli/cli/blob/trunk/docs/install_linux.md
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh -y
exit_if_error "GitHub CLI installation failed!"
fi # GH_INSTALL
# FIXME: Remove from the script as requires logging out and logging in again anyway?
sudo usermod -aG qaic,docker,sudo $USER
groups
echo
echo "DONE."