-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun.sh
executable file
·96 lines (78 loc) · 2.45 KB
/
run.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
#!/bin/bash
#
# Dockerized building environment for use with Thingino firmware
#
# 2022, Paul Philippov <[email protected]>
DOCKER=
install_docker() {
echo "Installing Docker from its offical repository."
echo "This operation requires superuser privileges."
# install required packages
command -v curl >/dev/null || sudo apt install curl
# retrive official Docker repository key if missing
local gpg_key=/usr/share/keyrings/docker-archive-keyring.gpg
if [ ! -f "$gpg_key" ]; then
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
sudo gpg --dearmor -o $gpg_key
fi
# add Docker official repository
local distro=$(lsb_release -si | tr 'A-Z' 'a-z')
local codename=$(lsb_release -sc)
[ "$codename" = "trixie" ] && codename="bookworm"
echo "deb [arch=amd64 signed-by=${gpg_key}] https://download.docker.com/linux/$distro $codename stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# update packages
sudo apt-get update
# install official version of Docker
sudo apt-get --assume-yes install docker-ce docker-ce-cli containerd.io
sudo usermod -a -G docker $USER
need_docker=0
echo "Done"
echo "You might need to re-login to pick up the new docker group rights."
}
# Check for podman/docker
need_docker=0
if command -v podman >/dev/null; then
echo "Found Podman"
DOCKER=podman
elif command -v docker >/dev/null; then
echo "Found Docker"
DOCKER=docker
docker_ver=$(docker -v | awk -F '[ ,.]' '{print $3}')
if [ "$docker_ver" -lt 20 ]; then
echo "Installed Docker is outdated."
need_docker=1
fi
else
echo "No Podman or Docker was found."
need_docker=2
fi
while [ "$need_docker" -gt 0 ]; do
echo
read -p "Do you want to install Docker from its official repository? [y/n] " yn
case $yn in
[yY]*)
install_docker
DOCKER=docker
;;
[nN]*)
echo "Aborted."
exit 1
;;
*)
echo "Please answer only yes or no."
esac
done
# Build a Docker image with selected development environment
$DOCKER build -t thingino-dev .
[ -d workspace/thingino ] || git clone --recurse-submodules \
https://github.com/themactep/thingino-firmware.git \
workspace/thingino
[ -z "$BR2_DL_DIR" ] && BR2_DL_DIR="$(pwd)/workspace/downloads"
[ -d "$BR2_DL_DIR" ] || mkdir -p "$BR2_DL_DIR"
# Run a container in interactive mode and mount the source files in it
$DOCKER run --rm -it \
--mount type=bind,source="$(pwd)/workspace",target=/home/me \
--mount type=bind,source="$BR2_DL_DIR",target=/home/me/downloads \
thingino-dev:latest
exit 0