blob: 4387af2353d5714de1d530cec8d522f702bac882 (
plain) (
blame)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
#!/bin/sh
set -e
def_arch=$(uname -m)
def_ver="1.0-rc1"
readonly PROGNAME=$(basename $0)
[ -z $ZSH_VERSION ] || set -y
warn() {
printf '>>> '
printf '\033[01;33mWARNING\033[00;39m '
printf '>>> '
printf '\033[01;33mWARNING\033[00;39m '
printf '>>> '
printf '\033[01;33mWARNING\033[00;39m '
printf '>>> '
printf '\033[01;33mWARNING\033[00;39m '
printf '>>>\n'
}
fatal() {
printf '>>> '
printf '\033[01;31mERROR\033[00;39m '
printf '>>> '
printf '\033[01;31mERROR\033[00;39m '
printf '>>> '
printf '\033[01;31mERROR\033[00;39m '
printf '>>> '
printf '\033[01;31mERROR\033[00;39m '
printf '>>>\n'
}
ensure_commands() {
if ! command -v apk>/dev/null 2>/dev/null; then
fatal
printf 'You must have apk installed. On Gentoo, see sys-devel/apk-tools.\n'
exit 127
fi
if ! command -pv tar>/dev/null 2>/dev/null; then
fatal
printf 'You must have tar installed.\n'
exit 127
fi
}
usage() {
printf 'usage: %s [-a ARCH] [--mini] [-v VERSION] [--help]\n\n' $PROGNAME
printf 'Create an Adélie Linux root FS tarball (.TXZ) using the specified parameters.\n\n'
printf 'Default ARCH: %s\n' $def_arch
printf 'Default VERSION: %s\n' $def_ver
}
while [ -n "$1" ]; do
case $1 in
-a | --arch)
shift
readonly MY_ARCH=$1
;;
-h | --help)
usage
exit
;;
--mini)
readonly MINI=yes
;;
-v | --version)
shift
readonly MY_VER=$1
;;
-c | --cache)
shift
readonly MY_CACHE=$1
;;
--no-cache)
unset def_cache
;;
*)
usage >&2
exit 127
;;
esac
shift
done
[ -d /etc/apk/cache ] && def_cache=/etc/apk/cache
[ -z "${MY_ARCH}" -o "${MY_ARCH}" = "${def_arch}" ] || unset def_cache
set -a
readonly ARCH=${MY_ARCH:-$def_arch}
readonly LDARCH=${LDARCH:-$ARCH}
readonly PHASE=${MY_PHASE:-all}
readonly VERSION=${MY_VER:-$def_ver}
readonly APKVER=${MY_APKVER:-$VERSION}
readonly URL=${MY_URL:-https://distfiles.adelielinux.org/adelie/$VERSION/}
readonly CACHE=${MY_CACHE:-$def_cache}
set +a
ensure_commands
header() {
printf '\033[01;32m * \033[37m%s\033[00;39m\n' "$1"
}
header 'Adélie Linux Root FS Tarball Creation Tool'
printf '\n'
clean_dirs() {
warn
printf 'This will erase all files at the directories %s/rootfs-%s.\n\n' `pwd` $ARCH
printf 'When you are ready, press RETURN. To cancel, press Ctrl-C.\n'
read dontcare
rm -rf rootfs-$ARCH
mkdir rootfs-$ARCH
mkdir -p out
}
install_pkgs() {
header "Installing base system to tar root..."
if test -n "${MINI+mini}"; then
readonly PACKAGES="adelie-core dash-binsh"
readonly ARCH_PKGS=""
else
readonly PACKAGES="$(cat packages/base 2>/dev/null | tr '\n' ' ' || fatal 'No core packages specified')"
readonly ARCH_PKGS="$(cat packages/arch/$ARCH 2>/dev/null | tr '\n' ' ' || echo '')"
fi
mkdir -p rootfs-$ARCH/etc/apk
cp -r keys rootfs-$ARCH/etc/apk/
# Disable grub trigger.
mkdir -p rootfs-$ARCH/etc/default
printf "ADELIE_MANUAL_CONFIG=1\n" >> rootfs-$ARCH/etc/default/grub
mkdir -p rootfs-$ARCH/dev
mknod rootfs-$ARCH/dev/urandom c 1 9
mkdir -p rootfs-$ARCH/usr/sbin
apk --arch $ARCH \
${CACHE:+--cache-dir "${CACHE}"} \
-X "$URL/system/$EXTRA_MIRROR" \
-X "$URL/user/$EXTRA_MIRROR" \
-U --root rootfs-$ARCH --initdb add $PACKAGES $ARCH_PKGS
}
make_structure() {
if test -n "${MINI+mini}"; then
echo 'adelie-mini' > rootfs-$ARCH/etc/hostname
else
echo 'adelie-root' > rootfs-$ARCH/etc/hostname
for _runlevel in sysinit boot default shutdown; do
mkdir -p rootfs-$ARCH/etc/runlevels/$_runlevel
done
echo 'mtab_is_file=no' > rootfs-$ARCH/etc/conf.d/mtab
for siservice in udev udev-trigger lvmetad; do
ln -s /etc/init.d/$siservice \
rootfs-$ARCH/etc/runlevels/sysinit/$siservice
done
for bootservice in root binfmt bootmisc fsck hostname hwclock \
keymaps localmount loopback modules mtab procfs sysctl \
sysfsconf termencoding tmpfiles.setup urandom; do
ln -s /etc/init.d/$bootservice \
rootfs-$ARCH/etc/runlevels/boot/$bootservice
done
readonly BASE_SERVICES="$(cat services/base 2>/dev/null | tr '\n' ' ' || echo '')"
[ -z BASE_SERVICES ] || for base_service in $BASE_SERVICES; do
ln -s /etc/init.d/$base_service \
rootfs-$ARCH/etc/runlevels/default/$base_service
done
cp AdelieTux.icns rootfs-$ARCH/.VolumeIcon.icns
# Put a copy of the kernel(s) in the kernels/$ARCH/ directory,
# so users may download them for netbooting or such.
mkdir -p out/kernels/$ARCH
cp -r rootfs-$ARCH/boot/* out/kernels/$ARCH/
fi
cat >rootfs-$ARCH/etc/fstab <<- FSTAB
# Welcome to Adélie Linux.
# This fstab(5) is for the live media only. Edit for use for your installation.
tmpfs /tmp tmpfs defaults 0 1
proc /proc proc defaults 0 1
FSTAB
cat >rootfs-$ARCH/etc/resolv.conf <<- RESOLVE
nameserver 2620:fe::fe
nameserver 9.9.9.9
nameserver 149.112.112.112
RESOLVE
cat >rootfs-$ARCH/etc/apk/repositories <<-REPOS
https://distfiles.adelielinux.org/adelie/$APKVER/system/$EXTRA_MIRROR
https://distfiles.adelielinux.org/adelie/$APKVER/user/$EXTRA_MIRROR
REPOS
}
tar_it() {
header 'Creating file system archive...'
cd rootfs-$ARCH
tar -cf - . | xz -v > ../out/adelie-rootfs-${MINI+mini-}$ARCH-$VERSION-$(date +%Y%m%d).txz
}
# in case we want to add phase support like adelie-build-cd has later
case $PHASE in
clean)
clean_dirs
;;
install)
install_pkgs
make_structure
;;
tar)
tar_it
;;
all)
clean_dirs
install_pkgs
make_structure
tar_it
;;
*)
fatal
printf 'Unknown phase %s. Stop.\n' $PHASE
;;
esac
|