-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_docker.sh
executable file
·129 lines (115 loc) · 4.03 KB
/
build_docker.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
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
# SPDX-FileCopyrightText: 2024 Harald Sitter <[email protected]>
# SPDX-FileCopyrightText: 2024 Bruno Pajdek <[email protected]>
# Builds KDE Linux inside of an Arch Linux Docker container.
# Exit immediately if any command fails.
set -e
# Store the absolute path the script is located in to $SCRIPT_DIR.
SCRIPT_DIR="$(readlink --canonicalize "$(dirname "$0")")"
CONTAINER_RUNTIME="docker"
MIRRORS_COUNTRY=""
PARALLEL_DOWNLOADS=""
while [ $# -gt 0 ]; do
case "$1" in
--podman)
CONTAINER_RUNTIME="podman"
shift
;;
--country)
MIRRORS_COUNTRY="$2"
shift 2
;;
--parallel)
PARALLEL_DOWNLOADS="$2"
shift 2
;;
--help) # New help option
echo "Usage: $0 [options]"
echo "Options:"
echo " --podman Use podman instead of docker"
echo " --country <country code> Set the country code for mirrors"
echo " --parallel <number> Set the number of parallel downloads"
echo " --help Display this help message"
exit 0
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
if [ "$CONTAINER_RUNTIME" = "podman" ]; then
if ! podman info | grep -q 'rootless: false'; then
echo "Podman must be running in rootful mode. Just run this script as root."
exit 1
fi
# podman requires the volume mount points to exist already
mkdir -p "${SCRIPT_DIR}/kde-linux.cache/pacman"
mkdir -p "${SCRIPT_DIR}/kde-linux.cache/mkosi.pacman"
mkdir -p "${SCRIPT_DIR}/kde-linux.cache/flatpak"
fi
# Exit if Docker or Podman are not available.
if ! command -v "$CONTAINER_RUNTIME" 2>&1 > /dev/null; then
echo "$CONTAINER_RUNTIME not available on the system! Make sure it is installed."
exit 1
fi
# Print some configuration instructions if we're not running Docker on btrfs, then exit.
if ! $CONTAINER_RUNTIME info | grep --quiet ": btrfs"; then
echo "You should run this on a btrfs'd Docker or Podman instance."
echo "Other storage drivers will not work at all!"
echo
echo "If you are running Podman and btrfs:"
echo "Change the storage driver from overlay to btrfs in /etc/containers/storage.conf"
echo "and \`rm -rf /var/lib/containers/*\` to wipe out your existing containers."
echo
echo "If you use Docker and have btrfs:"
echo "add the following to /etc/docker/daemon.json:"
echo
echo "{"
echo " \"storage-driver\": \"btrfs\""
echo "}"
echo
echo "And run:"
echo
echo "# systemctl restart docker.socket docker.service"
echo
echo "If you are not using btrfs already, create a btrfs filesystem inside of a file"
echo "and mount it so Docker or Podman can use it. For Podman mount on to /var/lib/containers."
echo
echo "# fallocate -l 64G /docker.btrfs"
echo "# mkfs.btrfs /docker.btrfs"
echo "# mkdir -p /var/lib/docker"
echo "# mount /docker.btrfs /var/lib/docker"
echo
echo "Then follow the appropriate directions above."
exit 1
fi
# Print all commands before they are executed.
# We only do this now not to clutter the printed configuration instructions above.
set -x
# Make sure we have the latest available Arch Linux image.
$CONTAINER_RUNTIME pull archlinux:latest
ENV_OPTIONS=""
if [ -n "$MIRRORS_COUNTRY" ];
then
ENV_OPTIONS="$ENV_OPTIONS -e MIRRORS_COUNTRY=$MIRRORS_COUNTRY"
fi
if [ -n "$PARALLEL_DOWNLOADS" ];
then
ENV_OPTIONS="$ENV_OPTIONS -e PARALLEL_DOWNLOADS=$PARALLEL_DOWNLOADS"
fi
# Spin up a new Arch Linux container and run the in_docker.sh script inside of it,
# passing any command line arguments to it and mounting $SCRIPT_DIR to /workspace.
$CONTAINER_RUNTIME run \
--privileged \
--volume="${SCRIPT_DIR}:/workspace" \
--volume="${SCRIPT_DIR}/kde-linux.cache/pacman:/var/cache/pacman/pkg" \
--volume="${SCRIPT_DIR}/kde-linux.cache/mkosi.pacman:/var/cache/mkosi.pacman" \
--volume="${SCRIPT_DIR}/kde-linux.cache/flatpak:/var/lib/flatpak" \
--volume="/dev:/dev" \
--workdir="/workspace" \
--rm \
$ENV_OPTIONS \
archlinux:latest \
/workspace/in_docker.sh "$@"