forked from vbatts/slackware-container
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkimage-slackware.sh
166 lines (146 loc) · 3.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
#!/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/coreutils \
a/glibc-solibs \
a/aaa_terminfo \
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/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 \
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 $file" 1>&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
relbase=$(echo ${RELEASE} | cut -d- -f1)
if [ ! -f ${CACHEFS}/paths ] ; then
ruby ${CWD}/get_paths.rb ${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/installpkg ] ; then
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
chroot . /sbin/installpkg --root /mnt --terse ${l_pkg}
else
PATH=/bin:/sbin:/usr/bin:/usr/sbin \
chroot . /usr/lib/setup/installpkg --root /mnt --terse ${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/' 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
mount --bind /etc/resolv.conf etc/resolv.conf
chroot . sh -c 'yes y | /usr/sbin/slackpkg -batch=on -default_answer=y update'
chroot . sh -c '/usr/sbin/slackpkg -batch=on -default_answer=y upgrade-all'
# 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