forked from nnnewb/slackware-WSL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkimage-slackware.sh
executable file
·230 lines (204 loc) · 5.55 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
#!/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://mirrors.ustc.edu.cn/slackware"}
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 -i -d -v -m --null
else
zcat "${CACHEFS}/isolinux/initrd.img" | cpio -i -d -v -m --null
fi
[ -h ${ROOTFS}/cdrom ] && rm ${ROOTFS}/cdrom
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 -t nullfs ${CACHEFS} ${ROOTFS}/cdrom
mount -t devfs devfs ${ROOTFS}/dev
mount -o ro -t linsysfs linsysfs ${ROOTFS}/sys
mount -t linprocfs linprocfs ${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
for pkg in ${base_pkgs}
do
path=$(grep ^${pkg} ${CACHEFS}/paths | cut -d : -f 1)
if [ ${#path} -eq 0 ] ; then
echo "$pkg not found"
continue
fi
l_pkg=$(cacheit $relbase/$path)
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
set -x
touch etc/resolv.conf
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/g' etc/slackpkg/slackpkg.conf
sed -i '' 's/POSTINST=on/POSTINST=off/g' etc/slackpkg/slackpkg.conf
sed -i '' 's/SPINNING=on/SPINNING=off/g' etc/slackpkg/slackpkg.conf
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
echo "nameserver 223.5.5.5" >> etc/resolv.conf
# for slackware 15.0, slackpkg return codes are now:
# 0 -> All OK, 1 -> something wrong, 20 -> empty list, 50 -> Slackpkg upgraded, 100 -> no pending updates
chroot_slackpkg() {
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
chroot . /bin/bash -c 'yes y | /usr/sbin/slackpkg -batch=on -default_answer=y update'
ret=0
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
chroot . /bin/bash -c '/usr/sbin/slackpkg -batch=on -default_answer=y upgrade-all' || ret=$?
if [ $ret -eq 0 ] || [ $ret -eq 20 ] ; then
echo "uprade-all is OK"
return
elif [ $ret -eq 50 ] ; then
chroot_slackpkg
else
return $?
fi
}
chroot_slackpkg
# now some cleanup of the minimal image
set +x
rm -rf var/lib/slackpkg/*
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`)
# umount etc/resolv.conf
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