-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker_update_archlinux
More file actions
executable file
·169 lines (128 loc) · 4.31 KB
/
docker_update_archlinux
File metadata and controls
executable file
·169 lines (128 loc) · 4.31 KB
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
#!/bin/bash
# If uncommented, stores aarch64 packages to the host
# Good for repeat installations without bothering the mirrors
aarch64_pkg_cache=/var/cache/pacman/pkg/aarch64
# ____
# | _ \ _ __ ___ _ __
# | |_) | '__/ _ \ '_ \
# | __/| | | __/ |_) |
# |_| |_| \___| .__/
# |_|
_scriptPath=$(realpath $0)
_scriptRoot="$(dirname $(realpath $0))"
_scriptName="$(basename ${_scriptRoot})"
if [ -z "${CARCH}" ]
then
ARCHITECTURE=$(uname -m)
else
ARCHITECTURE=${CARCH}
fi
if ! command -v podman >/dev/null
then
echo "Can't find podman in PATH, is it installed?"
exit 1
fi
# _____ _ _
# | ___| _ _ __ ___| |_(_) ___ _ __ ___
# | |_ | | | | '_ \ / __| __| |/ _ \| '_ \/ __|
# | _|| |_| | | | | (__| |_| | (_) | | | \__ \
# |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
#
function update_container {
if [ -z "${baseImageName}" ]
then
echo "update_container: baseImageName not set?"
exit 1
fi
echo "Updating ${baseImageName}..."
# Remove any previous update container
podman container rm "${_scriptName}" >/dev/null 2>&1
# Attempt to run updates
podman run ${extraArgs[@]} --name "${_scriptName}" "${baseImageName}" pacman -Syu --noconfirm
returnCode=$?
if [ ${returnCode} -eq 0 ]
then
# Commit the update container as the new latest image
podman commit "${_scriptName}" "${baseImageName}"
fi
# Always clean up
podman container rm "${_scriptName}" >/dev/null 2>&1
}
function x86_64 {
baseImageName="archlinux:latest"
# Pull the latest archlinux:podman image to be updated.
# This will overwrite any local latest image
podman pull "${baseImageName}"
# Update the image
update_container
}
function aarch64_build {
buildDir="/tmp/aarch64_build"
if ! [ -f ${_scriptRoot}/arch-rootfs-aarch64.tar.gz ]
then
mkdir -p ${buildDir} || exit 1
if [ -z "${buildDir}" ] || ! [ -d "${buildDir}" ]
then
echo "Failed to get build dir."
exit 1
fi
if [ -n "${aarch64_pkg_cache}" ]
then
mkdir -p ${buildDir}/var/cache/pacman/pkg/aarch64
mkdir -p /var/cache/pacman/pkg/aarch64
mkdir -p "${aarch64_pkg_cache}"
mkdir -p "${buildDir}/var/cache/pacman/pkg"
mount --bind "${aarch64_pkg_cache}" "${buildDir}/var/cache/pacman/pkg"
fi
wget --no-clobber https://raw.githubusercontent.com/archlinuxarm/archlinuxarm-keyring/master/archlinuxarm.gpg
pacman-key --add archlinuxarm.gpg
set -x
# Sign the archlinuxarm keys
pacman-key -l archlinuxarm | grep -Po '[A-F0-9]{40}' | \
while read archlinuxarmKey
do
pacman-key --lsign-key ${archlinuxarmKey}
done
mkdir -p ${buildDir}/usr/bin
cp $(which qemu-aarch64-static) ${buildDir}/usr/bin
pacstrap -M -K -C ${_scriptRoot}/pacman.aarch64.conf ${buildDir} archlinuxarm-keyring base git sudo || exit 1
pushd ${buildDir} && tar -czf ${_scriptRoot}/arch-rootfs-aarch64.tar.gz .
popd
if [ -n "${aarch64_pkg_cache}" ]
then
umount "${buildDir}/var/cache/pacman/pkg" || exit 1
fi
# Clean out the buildDir
rm -rf ${buildDir:-/tmp/emergencyfallback}
else
echo "aarch64_build: Using existing archive: ${_scriptRoot}/arch-rootfs-aarch64.tar.gz"
fi
cat ${_scriptRoot}/arch-rootfs-aarch64.tar.gz | podman import - archlinux-aarch64:latest
}
function aarch64 {
baseImageName="archlinux-aarch64:latest"
extraArgs=(-v /var/cache/pacman/pkg/aarch64:/var/cache/pacman/pkg) # Always use the package cache on the host
# Ensure we have qemu-aarch64-static and that it's ready for use.
# Prepare the host to chroot in
pacman --needed --noconfirm -S qemu-user-static-binfmt qemu-user-static
cp -nv /usr/lib/binfmt.d/qemu-aarch64-static.conf /etc/binfmt.d/
# Check if we have already made this image and react accordingly
if [ -z "$(podman images -q archlinux-aarch64:latest)" ]; then
echo "Missing ${baseImageName}. Building..."
aarch64_build
else
echo "${baseImageName} already exists. Skipping build."
fi
# Quickly test the container
podman run --rm --name ${baseImageName/:*/}_testrun ${baseImageName} /bin/bash -c "echo hello world [aarch64]" || exit 1
# Update the image
update_container
}
# ____
# | _ \ _ _ _ __
# | |_) | | | | '_ \
# | _ <| |_| | | | |
# |_| \_\\__,_|_| |_|
#
# Run the correct function for the desired architecture
${ARCHITECTURE}