forked from pkegg/PortMaster-Build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init-docker
executable file
·89 lines (78 loc) · 2.96 KB
/
init-docker
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
#! /bin/bash
set -e
if ! which docker &> /dev/null; then
if which apt &> /dev/null; then
echo "Attempting to install docker. If you do not want this. Install manually from https://docs.docker.com/engine/install/"
sudo apt update
sudo apt install docker.io -y
elif which pacman &> /dev/null; then
sudo pacman -S --noconfirm docker
else
echo "Please install docker. It is suggested to install docker from https://docs.docker.com/engine/install/"
exit 1
fi
fi
if ! groups | grep -q docker; then
if [[ $OSTYPE == 'darwin'* ]]; then
echo "no need to add docker group on mac - OK"
else
echo "adding docker group to this user"
sudo usermod -aG docker $USER
echo "Added 'docker' group to this user"
echo "ERROR: You must re-login or run: newgrp docker"
echo " Then rerun this script"
exit 1
fi
fi
if ! docker ps -q &> /dev/null; then
echo "Something seems wrong. This command does not work: docker ps"
echo "Please ensure that you can access docker without sudo"
echo "You may need to follow the instructions here (and reboot) or start docker service: https://docs.docker.com/engine/install/linux-postinstall/"
exit 1
fi
BUILDX_RELEASE=v0.7.0
if ! docker buildx &> /dev/null; then
echo "no buildx found"
if ! which curl &> /dev/null; then
if which apt &> /dev/null; then
echo "Installing curl..."
sudo apt update
sudo apt install curl -y
else
echo "curl is required to install buildx"
echo "please install curl"
exit 1
fi
fi
CLI_PLUGIN_DIR="$(realpath ~/)/.docker/cli-plugins"
BUILDX_BIN="${CLI_PLUGIN_DIR}/docker-buildx"
mkdir -p ${CLI_PLUGIN_DIR}
if ! which dpkg &> /dev/null; then
echo "Only debian based systems (with dpkg) fully supported to install docker buildx. Please install docker buildx manually."
exit 1
else
architecture="$(dpkg --print-architecture)"
echo "architecture: $architecture"
curl -L -o "${BUILDX_BIN}" https://github.com/docker/buildx/releases/download/${BUILDX_RELEASE}/buildx-${BUILDX_RELEASE}.linux-${architecture}
chmod +x "${BUILDX_BIN}"
echo "testing docker buildx..."
docker buildx ls &> /dev/null
echo "done"
fi
fi
if [[ $OSTYPE == 'darwin'* ]]; then
echo "no need to install qemu on mac - OK"
elif which arch &> /dev/null && [[ "$(arch)" == "amd64" && ! -f /proc/sys/fs/binfmt_misc/qemu-aarch64 || ! -f /proc/sys/fs/binfmt_misc/qemu-arm ]]; then
if which dpkg; then
echo "Permanently installing support for other platforms"
sudo apt-get update
sudo apt-get install -y qemu binfmt-support qemu-user-static
else
echo "WARNING: Could not install qemu, binfmt-support and qemu-user-static. $0 may need to be run after each reboot!"
docker run --rm --privileged tonistiigi/binfmt:latest --install all
fi
fi
if ! docker buildx ls | grep -q portmaster-remote-builder; then
docker buildx create --name portmaster-remote-builder --driver docker-container
fi
echo "docker ready"