forked from gapan/iso-creation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
07-initrd.sh
executable file
·282 lines (247 loc) · 8.09 KB
/
07-initrd.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/bin/sh
#
# This script gets a slackware initrd.img file from a slackware
# repository and converts it to a salix initrd.img file.
#
# You really shouldn't build an initrd yourself if you're
# making a custom iso. Use the initrd files found in a
# Salix iso instead.
#
# This script assumes that in a 32bit system, you're running the smp
# kernel and that you at least have the non-smp kernel-modules package
# installed.
#
# You need to be running a stock slackware kernel.
CWD=`pwd`
SCRIPTSDIR=$CWD/initrd-scripts
if [ "$UID" != "0" ]; then
echo "You need to be root to run this"
exit 1
fi
if [ ! -f USER ]; then
echo "No USER file."
exit 1
fi
user=`cat USER`
if [ ! -f VERSION ]; then
echo "No VERSION file."
exit 1
else
VER=`cat VERSION`
fi
if [ -z "$arch" ]; then
case "$( uname -m )" in
i?86) arch=i486 ;;
*) arch=$( uname -m ) ;;
esac
fi
MSG="This script gets a slackware initrd.img file from a slackware\n\
repository and converts it to a salix initrd.img file.\n\
\n\
You really shouldn't build an initrd yourself if you're\n\
making a custom iso. Use the initrd files found in a\n\
Salix iso instead.\n\
\n\
When you get the initrd files from a salix iso, put them in an\n\
initrd/i486 or initrd/x86_64 directory, according to your\n\
architecture.\n\
\n\
This script assumes that in a 32bit system, you're running the smp\n\
kernel and that you at least have the non-smp kernel-modules package\n\
installed.\n\
\n\
You need to be running a stock slackware kernel.\n\
\n\
You also need to be running the architecture for which you are\n\
creating the initrd. The architecture you are running now\n\
is ${arch}.\n\
\n\
ARE YOU SURE YOU KNOW WHAT YOU'RE DOING?"
dialog --title "Are you sure you want to do this?" \
--defaultno \
--yesno "$MSG" 0 0
retval=$?
if [ $retval -eq 1 ] || [ $retval -eq 255 ]; then
exit 0
fi
MSG="Do you want to download the slackware initrd? If you have done\n\
this already, you don't have to do it again. Reply yes if you don't\n\
know."
dialog --title "Do you want to download the Slackware initrd?" \
--defaultno \
--yesno "$MSG" 0 0
DOWNLOAD=$?
unset LIBDIRSUFFIX
if [[ "$arch" == "x86_64" ]]; then
export LIBDIRSUFFIX="64"
fi
SLACKREPO=http://download.salixos.org/$arch/slackware-$VER
mkdir -p initrd/$arch
rm -rf initrd/$arch/initrd.img
# get the slack initrd
if [ $DOWNLOAD -eq 0 ] && [ ! -f initrd/$arch/slack-initrd.img ]; then
echo "Getting the slackware initrd..."
rm -f initrd/$arch/slack-initrd.img
wget $SLACKREPO/isolinux/initrd.img -O initrd/$arch/slack-initrd.img
if [ $? -ne 0 ]; then
echo "Download failed"
exit 1
fi
fi
# unpack slack initrd
echo "Unpacking slackware initrd..."
rm -rf /boot/initrd-tree
mkdir /boot/initrd-tree
cd /boot/initrd-tree
xzcat < $CWD/initrd/$arch/slack-initrd.img | cpio -i
cd $CWD
# replace rc.d scripts
echo "Replacing rc.d scripts..."
rm /boot/initrd-tree/etc/rc.d/*
cp $SCRIPTSDIR/etc-rc.d/* /boot/initrd-tree/etc/rc.d/
# replace setup scripts
echo "Replacing setup scripts..."
rm /boot/initrd-tree/usr/lib/setup/*
cp $SCRIPTSDIR/usr-lib-setup/* /boot/initrd-tree/usr/lib/setup/
# download and install required packages
echo "Installing spkg..."
spkg -qq --root=/boot/initrd-tree/ -i iso/salix/core/spkg-*.t?z
# the slackware installer does not install the locale files for dialog
# and we need those to have the installer completely translated.
install_dialog () {
echo "Installing dialog..."
spkg -qq --root=/boot/initrd-tree/ -i iso/salix/core/dialog-*.t?z
}
install_dialog
# We just need xzdec, needed by spkg. - Didier
install_xzdec () {
echo "Installing xzdec ..."
tar xf iso/salix/core/xz-*.t?z -C /boot/initrd-tree usr/bin/xzdec
mv /boot/initrd-tree/usr/bin/xzdec /boot/initrd-tree/bin/xzdec
}
install_xzdec
# pv is useful sometimes, especially when used with dd
install_pv () {
echo "Installing pv..."
tar xf iso/salix/core/pv-*.txz -C /boot/initrd-tree usr/bin/pv
mv /boot/initrd-tree/usr/bin/pv /boot/initrd-tree/bin/pv
}
install_pv
# We need gettext (but not gettext-tools) - Didier
install_gettext() {
echo "Installing gettext..."
tar xf iso/salix/core/gettext-[[:digit:]]*.txz -C /boot/initrd-tree --wildcards \
usr/bin/{envsubst,gettext*}
}
install_gettext
# add some extra keymaps
add_keymaps () {
echo "Adding some extra keymaps..."
mkdir -p initrd/tmp
tar xf iso/salix/core/kbd-extra-*.txz \
--wildcards \
--strip-components=6 \
-C initrd/tmp/ \
usr/share/kbd/keymaps/i386/*/*.map.gz
for i in `ls initrd/tmp/*.map.gz`; do
MAP=`echo $i | sed "s/\(.*\)\.map\.gz/\1/"`
gunzip $i
loadkeys -b $MAP.map > $MAP.bmap
rm $MAP.map
done
mkdir -p initrd/keymaps
tar xf /boot/initrd-tree/etc/keymaps.tar.gz -C initrd/keymaps
mv initrd/tmp/*.bmap initrd/keymaps/
rmdir initrd/tmp
rm /boot/initrd-tree/etc/keymaps.tar.gz
cd initrd/keymaps
tar czf /boot/initrd-tree/etc/keymaps.tar.gz *.bmap
cd -
rm -rf initrd/keymaps
}
add_keymaps
# We need appropriate fonts for each locale - Didier
install_fonts() {
echo "Installing terminus fonts..."
FONT_LIST=$(grep -o "FONT[^=]*=[^;]*" $SCRIPTSDIR/etc-rc.d/rc.font | \
sort | uniq | cut -d= -f2| sed ':a;N;s/\n/ /;ta')
for i in $FONT_LIST; do
tar xf iso/salix/core/terminus-font-*t?z -C /boot/initrd-tree \
usr/share/kbd/consolefonts/$i
done
}
install_fonts
# We need messages catalogs for available locales - Didier
install_messages_catalogs() {
echo "Installing messages catalogs"
for j in $(find po -name "*.po"); do
LocaleDir=`echo $j | sed "s|po/\(.*\)\.po|\1|"`
MO_DIR=/boot/initrd-tree/usr/share/locale/$LocaleDir/LC_MESSAGES
mkdir -p $MO_DIR
msgfmt --strict -c -v --statistics -o $MO_DIR/salix-installer.mo $j
chown root:root $MO_DIR/salix-installer.mo
chmod 644 $MO_DIR/salix-installer.mo
done
}
install_messages_catalogs
# We need definitions for all available locales. - Didier
install_locales_definitions() {
echo "Installing locale definitions"
mkdir -p /boot/initrd-tree/usr/lib$LIBDIRSUFFIX/locale
TMPDIR=$(mktemp -d)
# We can't cherry pick the locales we need from the archive, because it
# contains hard links. - Didier
tar -xf iso/salix/core/glibc-i18n-*.txz -C $TMPDIR
# Read the available locales from the isolinux boot menu options. Use
# the 64-bit one, it shouldn't make a difference anyway. Downside is
# that if there is no menu option for a locale, there is no support for
# it during installation.
LOCALES=$( grep LANG isolinux-files/x86_64/isolinux.cfg | \
sed "s/.* LANG=\(.*\)\.utf8/\1.utf8/" | tr '\n' ' ' )
for i in $LOCALES; do
cp -a $TMPDIR/usr/lib$LIBDIRSUFFIX/locale/$i \
/boot/initrd-tree/usr/lib$LIBDIRSUFFIX/locale
done
rm -rf $TMPDIR
}
install_locales_definitions
echo "Tweaking config files..."
# network logon message
cat << EOF > /boot/initrd-tree/etc/motd.net
Welcome to Salix${LIBDIRSUFFIX} $VER
Please run '. /etc/profile' to initialise the environment.
EOF
# change the hostname
sed "s/slackware/salix${LIBDIRSUFFIX}/g" -i /boot/initrd-tree/etc/HOSTNAME
sed "/^127.0.0.1/s|slackware|salix${LIBDIRSUFFIX}|g" -i /boot/initrd-tree/etc/hosts
# add "setup" to bash history so it can be recalled with up arrow
echo "setup" > /boot/initrd-tree/.bash_history
# remove not needed dirs
echo "Removing unnecessary stuff..."
rm -rf /boot/initrd-tree/usr/{doc,include,man,src}
# For localization, we need /boot/initrd-tree/usr/share/locale!
# rm -rf /boot/initrd-tree/usr/share/locale
rm -rf /boot/initrd-tree/usr/src
rm -rf /boot/initrd-tree/var/lib/pkgtools
# remove cyrus-sasl stuff - No mre installed - Didier
# rm -f /boot/initrd-tree/usr/sbin/{pluginviewer,saslauthd,sasldblistusers2,saslpasswd2,testsaslauthd}
# rm -f /boot/initrd-tree/etc/rc.d/rc.saslauthd
# rm -rf /boot/initrd-tree/usr/lib${LIBDIRSUFFIX}/sasl*/
echo "Repacking initrd..."
# We didn't install modules, so no need for depmod
# depmod -b /boot/initrd-tree
rm -f /boot/initrd-tree/{wait-for-root,rootfs,rootdev,initrd-name}
(
cd /boot/initrd-tree
find . -print | cpio -o --owner root:root -H newc \
| xz -9 -C crc32 > $CWD/initrd/$arch/initrd.img
)
# clean up
rm -rf /boot/initrd-tree
# chown everything back
chown -R ${user}:users initrd
echo "DONE!"
read -p 'Delete the Slackware initrd? Enter "y" to delete: ' DELETE
[ x"$DELETE" == "xy" ] && \
echo "Deleting slack-initrd.img." && \
rm initrd/$arch/slack-initrd.img