Merge branch 'upstream'
[automated-distro-installer] / mk-basefile-big
1 #!/bin/bash
2 # Copyright (C) 2018 Ian Kelling
3
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18
19 [[ $EUID == 0 ]] || exec sudo -E "$BASH_SOURCE" "$@"
20
21
22 x="$(readlink -f "$BASH_SOURCE")"; source "${x%/*}/bash-trace"
23 x="$(readlink -f -- "$BASH_SOURCE")"; PATH="${x%/*}:$PATH" # directory of this file
24
25 usage() {
26 cat <<EOF
27 Usage: ${0##*/} DISTRO_CODENAME
28 Make basefile with desktop packages preinstalled
29
30 The longest amount of time when doing a new install is installing
31 packages. We can make that faster by preinstalling them in a
32 basefile. When a basefile is created, debootstrap allows you to
33 specify extra packages, but in trisquel, most packages don't install
34 that way. Not sure exactly why. So, we can do a fai dirinstall (fancy
35 chroot) to install packages, then turn that into a new basefile.
36
37 The script depnds on being in a directory with other scripts from it's repo.
38
39 Warning: uses paths specific to author's machine.
40
41 -h|--help Print help and exit.
42
43 Note: Uses GNU getopt options parsing style
44 EOF
45 exit $1
46 }
47
48 read distver <<<"$@"
49
50 if [[ $# != 1 ]]; then
51 echo "$0: error: expected one argument"
52 usage 1
53 fi
54
55
56 case $distver in
57 flidas)
58 distro=trisquel
59 classes="UBUNTU FLIDAS64 VOL_FLIDAS FLIDAS DESKTOP"
60 ;;
61 stretch)
62 classes="DEBIAN STRETCH64 VOL_STRETCH STRETCH DESKTOP"
63 ;;
64 *)
65 echo "$0: error: unknown DISTRO_CODENAME"
66 usage 1
67 ;;
68 esac
69
70 distro=trisquel
71
72 # background: i tried using a tmpfs for this. it had minimal effect, like 17 mins vs 18 mins
73 t=/tmp/dirinstall
74
75
76 err-cleanup() {
77 sed -i 's/^#LOGUSER=/LOGUSER=/' /etc/fai/fai.conf
78 for d in proc var/lib/dpkg var/cache; do
79 umount -R $t/$d ||:
80 done
81 rm -rf $t
82 }
83
84
85 myfai-chboot default
86 sed -i 's/^LOGUSER=/#LOGUSER=/' /etc/fai/fai.conf
87 # config umount required after a failed run, proc umount always required
88 umount /var/lib/fai/config ||: ; umount -R $t/proc ||:
89
90 fai-redep faiserver $distro
91 echo "echo $classes" > /srv/fai/config/class/51-multi-boot
92
93 rm -rf $t; mkdir -p $t
94
95 LANG= fai -N -u hostname_does_not_matter dirinstall $t
96
97 # Turn a dirinstall into a basefile. taken from mk-basefile
98 chroot $t apt-get clean
99 rm -f $t/etc/hostname $t/etc/resolv.conf \
100 $t/var/lib/apt/lists/*_* $t/usr/bin/qemu-*-static \
101 $t/etc/udev/rules.d/70-persistent-net.rules
102 echo | dd of=$t/etc/machine-id
103 tar --one-file-system -C $t -cf - . | gzip > /a/bin/fai-basefiles/basefiles/${distver^^}64BIG.tar.gz
104
105
106 cleanup
107 exit 0