-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinux-respinner.sh
More file actions
386 lines (323 loc) · 13.2 KB
/
linux-respinner.sh
File metadata and controls
386 lines (323 loc) · 13.2 KB
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#!/bin/sh
Encoding=UTF-8
# Multifunction Linux Distro Respinner Script v0.10.
# Copyright (c) 2018 by Philip Collier, <webmaster@ab9il.net>
# Multifunction Linux Distro Respinner setup is free software; you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation; either version 3 of
# the License, or (at your option) any later version. There is NO warranty;
# not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# Run this script as root to extract the iso contents,
# set up the chroot environment, or build a respun iso file.
# Boot into the iso you will respin. Create the working directory
# (sysdir) and copy the original iso into it. Set the variables
# before running this script. Change SYSUSER and PART to match the
# current username and partition to match your currently running
# system, or the paths will be incorrect.
#
# define variables:
# SYSUSER: your username as builder of the respin
SYSUSER=winston
# CHROOTDNS: DNS to use during chroot operation
CHROOTDNS='9.9.9.9'
# PART: the partition where the respin project is located
PART=data1
# SYSDIR: the working directory of the respin project
SYSDIR=churchill
# ISONAME: the filename for the iso to be extracted
ISONAME=respunlinux-orig
# ISOINFO: data for the .disk/info file in the respun iso
ISOINFO='RespunLinux - Release amd64 (20190215)'
# UBURELEASE=Release Year.Month for Ubuntu distros
UBURELEASE=18.04
# UBUCODE=Ubuntu codename
UBUCODE=bionic
# MINTCODE=Mint codename
MINTCODE=
# NEWISO: filename for the new iso
NEWISO=respunlinux-latest
# DISTRONAME: plain language name for the respun distro
DISTRONAME="Respun Linux"
# DISTROURL: url for the respin's web page
DISTROURL="https://respunlinux.com"
# FLAVOUR: /etc/casper.conf flavour
FLAVOUR=Respun
# HOST: /etc/casper.conf host in the respun distro
HOST=respun
# USERNAME: /etc/casper.conf user in the respun distro
USERNAME=user
# VERSION: version number of the respun distro
VERSION=0.8
#--------------------DO NOT EDIT BELOW THIS LINE--------------------
extract() {
#apt update
#apt install -y squashfs-tools genisoimage syslinux-utils
cd /media/$SYSUSER/$PART/$SYSDIR
mkdir mnt
mkdir utils
mkdir extract-cd
mount -o loop /media/$SYSUSER/$PART/$SYSDIR/$ISONAME.iso mnt
rsync --exclude=/casper/filesystem.squashfs -a mnt/ extract-cd
unsquashfs mnt/casper/filesystem.squashfs
mv squashfs-root edit
#cp /sbin/initctl /media/$SYSUSER/$PART/$SYSDIR/utils/initctl
umount mnt
rm -rf /media/$SYSUSER/$PART/$SYSDIR/mnt
echo '#!/bin/sh
Encoding=UTF-8
enter(){
echo "Mounting directories..."
mount -t proc none /proc
mount -t sysfs none /sys
mount -t devpts none /dev/pts
export HOME=/root
export LC_ALL=C
dbus-uuidgen > /var/lib/dbus/machine-id
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl
echo "Moving to system root directory..."
cd
/bin/bash
leave
}
leave(){
echo "Cleaning up before chroot exit..."
apt autoremove --purge
apt clean
rm /var/lib/dbus/machine-id
rm /sbin/initctl
dpkg-divert --rename --remove /sbin/initctl
rm -rf /var/cache/apt/.[^.]*
rm -rf /var/lib/apt/lists/.[^.]*
rm -rf /var/cache/fontconfig/.[^.]*
rm -rf /etc/apt/sources.list.d/*.save
rm -rf /root/.[^.]*
rm -rf /tmp/.[^.]*
rm -rf /var/tmp/.[^.]*
rm -f /etc/hosts
rm /etc/machine-id
umount /proc || umount -lf /proc
umount /sys
umount /dev/pts
echo "Exiting chroot..."
exit
}
case $1 in
enter)
enter
;;
leave)
leave
;;
**)
echo "Usage: $0 (enter|leave)"
;;
esac' > /media/$SYSUSER/$PART/$SYSDIR/utils/chroot-manager
chmod +x /media/$SYSUSER/$PART/$SYSDIR/utils/chroot-manager
cp /media/$SYSUSER/$PART/$SYSDIR/utils/chroot-manager /media/$SYSUSER/$PART/$SYSDIR/edit/usr/sbin/chroot-manager
}
enterchroot() {
#get prerequisites
echo '\nGetting prerequisites...'
apt install -y squashfs-tools genisoimage syslinux-utils
cd /media/$SYSUSER/$PART/$SYSDIR
echo '\nBinding directories...'
mount -o bind /run/ /media/$SYSUSER/$PART/$SYSDIR/edit/run
mount --bind /dev /media/$SYSUSER/$PART/$SYSDIR/edit/dev
mount --bind /proc /media/$SYSUSER/$PART/$SYSDIR/edit/proc
cp /etc/hosts /media/$SYSUSER/$PART/$SYSDIR/edit/etc/hosts
mkdir /media/$SYSUSER/$PART/$SYSDIR/edit/run/systemd/resolve
echo 'nameserver '${CHROOTDNS}'' > /media/$SYSUSER/$PART/$SYSDIR/edit/run/systemd/resolve/stub-resolv.conf
echo '\nChrooting...'
chroot /media/$SYSUSER/$PART/$SYSDIR/edit chroot-manager enter
umount /media/$SYSUSER/$PART/$SYSDIR/edit/run
umount /media/$SYSUSER/$PART/$SYSDIR/edit/proc
umount /media/$SYSUSER/$PART/$SYSDIR/edit/dev
rm -f /media/$SYSUSER/$PART/$SYSDIR/edit/etc/hosts
rm -rf /media/$SYSUSER/$PART/$SYSDIR/edit/root/.[^.]*
rm -rf /media/$SYSUSER/$PART/$SYSDIR/edit/tmp/.[^.]*
rm -rf /media/$SYSUSER/$PART/$SYSDIR/edit/var/cache/apt/.[^.]*
rm -rf /media/$SYSUSER/$PART/$SYSDIR/edit/var/cache/fontconfig/.[^.]*
rm -rf /media/$SYSUSER/$PART/$SYSDIR/edit/var/lib/apt/lists/.[^.]*
rm -rf /media/$SYSUSER/$PART/$SYSDIR/edit/etc/apt/*.save
rm -rf /media/$SYSUSER/$PART/$SYSDIR/edit/etc/apt/sources.list.d/*.save
}
makedisk() {
echo '\n Jumping above root directory, moving files...\n'
cleanup
mkdir /media/$SYSUSER/$PART/$SYSDIR/edit/root/.config
mkdir /media/$SYSUSER/$PART/$SYSDIR/edit/root/.config/dconf
mkdir /media/$SYSUSER/$PART/$SYSDIR/edit/var/cache/apt/archives
mkdir /media/$SYSUSER/$PART/$SYSDIR/edit/var/cache/apt/archives/partial
touch /media/$SYSUSER/$PART/$SYSDIR/edit/var/cache/apt/archives/lock
cp -f /media/$SYSUSER/$PART/$SYSDIR/utils/initctl /media/$SYSUSER/$PART/$SYSDIR/edit/sbin/initctl
cp -f /media/$SYSUSER/$PART/$SYSDIR/utils/.bashrc /media/$SYSUSER/$PART/$SYSDIR/edit/root/.bashrc
cp -f /media/$SYSUSER/$PART/$SYSDIR/utils/.bashrc /media/$SYSUSER/$PART/$SYSDIR/edit/etc/skel/.bashrc
cp -f /media/$SYSUSER/$PART/$SYSDIR/utils/user /media/$SYSUSER/$PART/$SYSDIR/edit/root/.config/dconf/user
cp -f /media/$SYSUSER/$PART/$SYSDIR/utils/user /media/$SYSUSER/$PART/$SYSDIR/edit/etc/skel/.config/dconf/user
#set distro identity
echo '# This file should go in /etc/casper.conf
# Supported variables are:
# USERNAME, USERFULLNAME, HOST, BUILD_SYSTEM, FLAVOUR
export USERNAME="'${USERNAME}'"
export USERFULLNAME="Live session user"
export HOST="'${HOST}'"
export BUILD_SYSTEM="Ubuntu"
# USERNAME and HOSTNAME as specified above will not be honoured and will be set to
# flavour string acquired at boot time, unless you set FLAVOUR to any
# non-empty string.
export FLAVOUR="'${FLAVOUR}'"' > /media/$SYSUSER/$PART/$SYSDIR/edit/etc/casper.conf
echo ${DISTRONAME}' '${VERSION}' \\n \l' > /media/$SYSUSER/$PART/$SYSDIR/edit/etc/issue
echo ${DISTRONAME}' '${VERSION} > /media/$SYSUSER/$PART/$SYSDIR/edit/etc/issue.net
echo 'DISTRIB_ID=Ubuntu
DISTRIB_RELEASE="'${UBURELEASE}'"
DISTRIB_CODENAME="'${UBUCODE}'"
DISTRIB_DESCRIPTION="'${DISTRONAME}' '${VERSION}'"' > /media/$SYSUSER/$PART/$SYSDIR/edit/etc/lsb-release
echo '
The programs included with the '${DISTRONAME}' system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
'${DISTRONAME}' comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
' > /media/$SYSUSER/$PART/$SYSDIR/edit/etc/legal
echo 'NAME="'${DISTRONAME}'"
VERSION="'${VERSION}'"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="'${DISTRONAME}'"
VERSION_ID="'${VERSION}'"
HOME_URL="'${DISTROURL}'"
SUPPORT_URL="'${DISTROURL}'"
BUG_REPORT_URL="'${DISTROURL}'"
PRIVACY_POLICY_URL="'${DISTROURL}'"
VERSION_CODENAME="'${UBUCODE}'"
UBUNTU_CODENAME="'${UBUCODE}'"' > /media/$SYSUSER/$PART/$SYSDIR/edit/usr/lib/os-release
echo '#!/bin/sh
#
# 10-help-text - print the help text associated with the distro
# Copyright (C) 2009-2010 Canonical Ltd.
#
# Authors: Dustin Kirkland <kirkland@canonical.com>,
# Brian Murray <brian@canonical.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
printf "\n * Support: '${DISTROURL}'\n"' > /media/$SYSUSER/$PART/$SYSDIR/edit/etc/update-motd.d/10-help-text
chmod +x /media/$SYSUSER/$PART/$SYSDIR/edit/etc/update-motd.d/10-help-text
echo '#define DISKNAME '${DISTRONAME}' '${VERSION}'
#define TYPE binary
#define TYPEbinary 1
#define ARCH amd64
#define ARCHamd64 1
#define DISKNUM 1
#define DISKNUM1 1
#define TOTALNUM 0
#define TOTALNUM0 1' > /media/$SYSUSER/$PART/$SYSDIR/extract-cd/README.diskdefines
echo ${ISOINFO} > /media/$SYSUSER/$PART/$SYSDIR/extract-cd/.disk/info
echo ${DISTROURL} > /media/$SYSUSER/$PART/$SYSDIR/extract-cd/.disk/release_notes_url
#regenerate manifest
echo '\n Regenerating manifest...'
chmod +w extract-cd/casper/filesystem.manifest
chroot edit dpkg-query -W --showformat='${Package} ${Version}\n' | tee extract-cd/casper/filesystem.manifest
cp extract-cd/casper/filesystem.manifest extract-cd/casper/filesystem.manifest-desktop
sed -i '/ubiquity/d' extract-cd/casper/filesystem.manifest-desktop
sed -i '/casper/d' extract-cd/casper/filesystem.manifest-desktop
#compress filesystem
echo '\n Compressing filesystem...\n'
rm extract-cd/casper/filesystem.squashfs
mksquashfs edit extract-cd/casper/filesystem.squashfs -comp xz
printf $(du -sx --block-size=1 edit | cut -f1) | tee extract-cd/casper/filesystem.size
#update md5sums
echo '\n Updating md5 sums...'
cd extract-cd
rm md5sum.txt
find -type f -print0 | xargs -0 md5sum | grep -v isolinux/boot.cat | tee md5sum.txt
#create iso image
echo '\n Creating the iso...'
mkisofs -input-charset utf-8 -U -A $NEWISO -V $NEWISO -volset $NEWISO -J -joliet-long -r -v -T -o ../$NEWISO.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -eltorito-alt-boot -e boot/grub/efi.img -no-emul-boot .
cd ../
isohybrid $NEWISO.iso
echo '\n Computing the SHA256 sum for the iso file...'
echo 'sha256sum: ' > $NEWISO-sha256sum.txt
sha256sum $NEWISO.iso >> $NEWISO-sha256sum.txt
echo '\n iso creation finished'
}
extractinitrd() {
cd initrd-rebuild
#For initrd.gz from an apt-get upgrade in chroot
#gzip -dc ../initrd.gz | cpio -id
#For initrd.gz in the iso file
#gzip -dc ../extract-cd/casper/initrd.gz | cpio -id
#For initrd.lz in the iso file
lzma -dc -S .lz ../extract-cd/casper/initrd.lz | cpio -id
}
repackinitrd() {
cd initrd-rebuild
find . | cpio --quiet --dereference -o -H newc | lzma -7 > ../extract-cd/casper/initrd-new.lz
}
cleanup() {
echo '\n Setting permissions, cleaning up...\n'
umount /media/$SYSUSER/$PART/$SYSDIR/edit/dev
find /media/$SYSUSER/$PART/$SYSDIR/extract-cd/isolinux -type f -exec chmod 644 {} \;
find /media/$SYSUSER/$PART/$SYSDIR/edit/etc/apt/sources.list.d -name "*.save" -type f -exec rm -f {} \;
find /media/$SYSUSER/$PART/$SYSDIR/edit/home -type f -exec rm -f {} \;
find /media/$SYSUSER/$PART/$SYSDIR/edit/root -type f -exec rm -f {} \;
find /media/$SYSUSER/$PART/$SYSDIR/edit/tmp -type f -exec rm -f {} \;
find /media/$SYSUSER/$PART/$SYSDIR/edit/var/crash -type f -exec rm -f {} \;
find /media/$SYSUSER/$PART/$SYSDIR/edit/var/lib/apt -type f -exec rm -f {} \;
find /media/$SYSUSER/$PART/$SYSDIR/edit/var/log -type f -exec rm -f {} \;
find /media/$SYSUSER/$PART/$SYSDIR/edit/var/tmp -type f -exec rm -f {} \;
find /media/$SYSUSER/$PART/$SYSDIR/edit/usr/local -name "*.py[co]" -o -name __pycache__ -exec rm -rf {} \;
cd /media/$SYSUSER/$PART/$SYSDIR
}
syncfolders() {
# rsync the html folder
rsync -av --delete /usr/local/share/html/ /media/$SYSUSER/$PART/$SYSDIR/edit/usr/local/share/html/
# rsync the mozilla folder (firefox)
rm -rf /home/$SYSUSER/.mozilla/firefox/bookmarkbackups/.[^.]*
rm -rf /home/$SYSUSER/.mozilla/firefox/*.default/storage/{default,permanent,temporary}
rsync -av --delete /home/$SYSUSER/.mozilla/ /media/$SYSUSER/$PART/$SYSDIR/edit/etc/skel/.mozilla/
}
copydconf(){
yes | cp -f /home/$SYSUSER/.config/dconf/user /media/$SYSUSER/$PART/$SYSDIR/utils/user
}
ans=$(zenity --list --height 340 --width 470 --text "LiveCD Respinner Script" \
--radiolist --column "Pick" --column "Action" TRUE "Do Nothing" \
FALSE "Extract Isofile Contents" \
FALSE "Enter the Chroot Environment" \
FALSE "Create New Iso File" \
FALSE "Extract Initrd Contents" \
FALSE "Repack Initrd Contents" \
FALSE "Sync Mozilla and HTML folders" \
FALSE "Sync current dconf/user file" \
FALSE "Distro Cleanup Actions" );
if [ "$ans" = "Do Nothing" ]; then
exit
elif [ "$ans" = "Extract Isofile Contents" ]; then
extract
elif [ "$ans" = "Enter the Chroot Environment" ]; then
enterchroot
elif [ "$ans" = "Create New Iso File" ]; then
makedisk
elif [ "$ans" = "Extract Initrd Contents" ]; then
extractinitrd
elif [ "$ans" = "Repack Initrd Contents" ]; then
repackinitrd
elif [ "$ans" = "Sync Mozilla and HTML folders" ]; then
syncfolders
elif [ "$ans" = "Sync current dconf settings" ]; then
copydconf
elif [ "$ans" = "Distro Cleanup Actions" ]; then
cleanup
fi