-
Notifications
You must be signed in to change notification settings - Fork 28
/
mkimage-slackware.sh
executable file
·243 lines (217 loc) · 5.94 KB
/
mkimage-slackware.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
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
240
241
#!/bin/bash
# Generate a very minimal filesystem from slackware
set -e
if [ -z "$ARCH" ]; then
case "$( uname -m )" in
i?86) ARCH="" ;;
arm*) ARCH=arm ;;
*) ARCH=64 ;;
esac
fi
BUILD_NAME=${BUILD_NAME:-"slackware"}
VERSION=${VERSION:="current"}
RELEASENAME=${RELEASENAME:-"slackware${ARCH}"}
RELEASE=${RELEASE:-"${RELEASENAME}-${VERSION}"}
MIRROR=${MIRROR:-"http://slackware.osuosl.org"}
CACHEFS=${CACHEFS:-"/tmp/${BUILD_NAME}/${RELEASE}"}
ROOTFS=${ROOTFS:-"/tmp/rootfs-${RELEASE}"}
CWD=$(pwd)
base_pkgs="a/aaa_base \
a/aaa_elflibs \
a/aaa_libraries \
a/coreutils \
a/glibc-solibs \
a/aaa_glibc-solibs \
a/aaa_terminfo \
a/pam \
a/cracklib \
a/libpwquality \
a/e2fsprogs \
a/nvi \
a/pkgtools \
a/shadow \
a/tar \
a/xz \
a/bash \
a/etc \
a/gzip \
l/pcre2 \
l/libpsl \
n/wget \
n/gnupg \
a/elvis \
ap/slackpkg \
l/ncurses \
a/bin \
a/bzip2 \
a/grep \
a/acl \
l/pcre \
l/gmp \
a/attr \
a/sed \
a/dialog \
a/file \
a/gawk \
a/time \
a/gettext \
a/libcgroup \
a/patch \
a/sysfsutils \
a/time \
a/tree \
a/utempter \
a/which \
a/util-linux \
a/elogind \
l/libseccomp \
l/mpfr \
l/libunistring \
ap/diffutils \
a/procps \
n/net-tools \
a/findutils \
n/iproute2 \
n/openssl"
function cacheit() {
file=$1
if [ ! -f "${CACHEFS}/${file}" ] ; then
mkdir -p $(dirname ${CACHEFS}/${file})
echo "Fetching ${MIRROR}/${RELEASE}/${file}" >&2
curl -s -o "${CACHEFS}/${file}" "${MIRROR}/${RELEASE}/${file}"
fi
echo "/cdrom/${file}"
}
mkdir -p $ROOTFS $CACHEFS
cacheit "isolinux/initrd.img"
cd $ROOTFS
# extract the initrd to the current rootfs
## ./slackware64-14.2/isolinux/initrd.img: gzip compressed data, last modified: Fri Jun 24 21:14:48 2016, max compression, from Unix, original size 68600832
## ./slackware64-current/isolinux/initrd.img: XZ compressed data
if $(file ${CACHEFS}/isolinux/initrd.img | grep -wq XZ) ; then
xzcat "${CACHEFS}/isolinux/initrd.img" | cpio -idvm --null --no-absolute-filenames
else
zcat "${CACHEFS}/isolinux/initrd.img" | cpio -idvm --null --no-absolute-filenames
fi
if stat -c %F $ROOTFS/cdrom | grep -q "symbolic link" ; then
rm $ROOTFS/cdrom
fi
mkdir -p $ROOTFS/{mnt,cdrom,dev,proc,sys}
for dir in cdrom dev sys proc ; do
if mount | grep -q $ROOTFS/$dir ; then
umount $ROOTFS/$dir
fi
done
mount --bind $CACHEFS ${ROOTFS}/cdrom
mount -t devtmpfs none ${ROOTFS}/dev
mount --bind -o ro /sys ${ROOTFS}/sys
mount --bind /proc ${ROOTFS}/proc
mkdir -p mnt/etc
cp etc/ld.so.conf mnt/etc
# older versions than 13.37 did not have certain flags
install_args=""
if [ -f ./sbin/upgradepkg ] && grep -qw terse ./sbin/upgradepkg ; then
install_args="--install-new --reinstall --terse"
elif [ -f ./usr/lib/setup/installpkg ] && grep -qw terse ./usr/lib/setup/installpkg ; then
install_args="--terse"
fi
# an update in upgradepkg during the 14.2 -> 15.0 cycle changed/broke this
root_env=""
root_flag="--root /mnt"
if [ "$VERSION" = "current" ] || [ "${VERSION}" = "15.0" ]; then
root_env='ROOT=/mnt'
root_flag=''
fi
relbase=$(echo ${RELEASE} | cut -d- -f1)
if [ ! -f ${CACHEFS}/paths ] ; then
bash ${CWD}/get_paths.sh -r ${RELEASE} > ${CACHEFS}/paths
fi
if [ ! -f ${CACHEFS}/paths-patches ] ; then
bash ${CWD}/get_paths.sh -r ${RELEASE} -m ${MIRROR} -p > ${CACHEFS}/paths-patches
fi
if [ ! -f ${CACHEFS}/paths-extra ] ; then
bash ${CWD}/get_paths.sh -r ${RELEASE} -m ${MIRROR} -e > ${CACHEFS}/paths-extra
fi
for pkg in ${base_pkgs}
do
path=$(grep "^packages/$(basename "${pkg}")-" ${CACHEFS}/paths-patches | cut -d : -f 1)
if [ ${#path} -eq 0 ] ; then
path=$(grep ^${pkg}- ${CACHEFS}/paths | cut -d : -f 1)
if [ ${#path} -eq 0 ] ; then
path=$(grep "^$(basename "${pkg}")/$(basename "${pkg}")-" ${CACHEFS}/paths-extra | cut -d : -f 1)
if [ ${#path} -eq 0 ] ; then
echo "$pkg not found"
continue
else
l_pkg=$(cacheit extra/$path)
fi
else
l_pkg=$(cacheit $relbase/$path)
fi
else
l_pkg=$(cacheit patches/$path)
fi
if [ -e ./sbin/upgradepkg ] ; then
echo PATH=/bin:/sbin:/usr/bin:/usr/sbin \
ROOT=/mnt \
chroot . /sbin/upgradepkg ${root_flag} ${install_args} ${l_pkg}
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
ROOT=/mnt \
chroot . /sbin/upgradepkg ${root_flag} ${install_args} ${l_pkg}
else
echo PATH=/bin:/sbin:/usr/bin:/usr/sbin \
ROOT=/mnt \
chroot . /usr/lib/setup/installpkg ${root_flag} ${install_args} ${l_pkg}
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
ROOT=/mnt \
chroot . /usr/lib/setup/installpkg ${root_flag} ${install_args} ${l_pkg}
fi
done
cd mnt
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
chroot . /bin/sh -c '/sbin/ldconfig'
# slackpkg would normally do this on first invocation
if [ ! -e ./root/.gnupg ] ; then
cacheit "GPG-KEY"
cp ${CACHEFS}/GPG-KEY .
echo PATH=/bin:/sbin:/usr/bin:/usr/sbin \
chroot . /usr/bin/gpg --import GPG-KEY
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
chroot . /usr/bin/gpg --import GPG-KEY
rm GPG-KEY
fi
set -x
echo "export TERM=linux" >> etc/profile.d/term.sh
chmod +x etc/profile.d/term.sh
echo ". /etc/profile" > .bashrc
echo "${MIRROR}/${RELEASE}/" >> etc/slackpkg/mirrors
sed -i 's/DIALOG=on/DIALOG=off/' etc/slackpkg/slackpkg.conf
sed -i 's/POSTINST=on/POSTINST=off/' etc/slackpkg/slackpkg.conf
sed -i 's/SPINNING=on/SPINNING=off/' etc/slackpkg/slackpkg.conf
if [ "$VERSION" = "current" ] ; then
mkdir -p var/lib/slackpkg
touch var/lib/slackpkg/current
fi
if [ ! -f etc/rc.d/rc.local ] ; then
mkdir -p etc/rc.d
cat >> etc/rc.d/rc.local <<EOF
#!/bin/sh
#
# /etc/rc.d/rc.local: Local system initialization script.
EOF
chmod +x etc/rc.d/rc.local
fi
# now some cleanup of the minimal image
set +x
rm -rf usr/share/locale/*
rm -rf usr/man/*
find usr/share/terminfo/ -type f ! -name 'linux' -a ! -name 'xterm' -a ! -name 'screen.linux' -exec rm -f "{}" \;
umount $ROOTFS/dev
rm -f dev/* # containers should expect the kernel API (`mount -t devtmpfs none /dev`)
tar --numeric-owner -cf- . > ${CWD}/${RELEASE}.tar
ls -sh ${CWD}/${RELEASE}.tar
for dir in cdrom dev sys proc ; do
if mount | grep -q $ROOTFS/$dir ; then
umount $ROOTFS/$dir
fi
done