1a6b6a99bc70dc28b12b157a34967c11ab7c0a7d
[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[0]}" "$@"
20
21 set -e; . /usr/local/lib/bash-bear; set +e
22
23 this_file="$(readlink -f -- "${BASH_SOURCE[0]}")"
24 readonly this_file this_dir="${this_file%/*}"
25 PATH="$this_dir:$PATH" # directory of this file
26
27 usage() {
28 cat <<EOF
29 Usage: ${0##*/} DISTRO_CODENAME
30 Make basefile with desktop packages preinstalled
31
32 The longest amount of time when doing a new install is installing
33 packages. We can make that faster by preinstalling them in a
34 basefile. When a basefile is created, debootstrap allows you to
35 specify extra packages, but in trisquel, most packages don't install
36 that way. Not sure exactly why. So, we can do a fai dirinstall (fancy
37 chroot) to install packages, then turn that into a new basefile.
38
39 The script depnds on being in a directory with other scripts from it's repo.
40
41 Warning: uses paths specific to author's machine.
42
43 -h|--help Print help and exit.
44
45 Note: Uses GNU getopt options parsing style
46 EOF
47 exit $1
48 }
49
50 read -r distver <<<"$@"
51
52 if [[ $# != 1 ]]; then
53 echo "$0: error: expected one argument"
54 usage 1
55 fi
56
57
58 case $distver in
59 flidas)
60 distro=trisquel
61 classes="UBUNTU FLIDAS64 VOL_FLIDAS FLIDAS DESKTOP"
62 ;;
63 stretch)
64 classes="DEBIAN STRETCH64 VOL_STRETCH STRETCH DESKTOP"
65 ;;
66 *)
67 echo "$0: error: unknown DISTRO_CODENAME"
68 usage 1
69 ;;
70 esac
71
72 distro=trisquel
73
74 # background: i tried using a tmpfs for this. it had minimal effect, like 17 mins vs 18 mins
75 t=/tmp/dirinstall
76
77
78 err-cleanup() {
79 sed -i 's/^#LOGUSER=/LOGUSER=/' /etc/fai/fai.conf
80 for d in proc var/lib/dpkg var/cache; do
81 umount -R $t/$d ||:
82 done
83 rm -rf $t
84 }
85
86
87 myfai-chboot default
88 sed -i 's/^LOGUSER=/#LOGUSER=/' /etc/fai/fai.conf
89 # config umount required after a failed run, proc umount always required
90 umount /var/lib/fai/config ||: ; umount -R $t/proc ||:
91
92 fai-redep faiserver.b8.nz $distro
93 echo "echo $classes" > /srv/fai/config/class/51-multi-boot
94
95 rm -rf $t; mkdir -p $t
96
97 # shellcheck disable=SC1007 # intentional
98 LANG= fai -N -u hostname_does_not_matter dirinstall $t
99
100 # Turn a dirinstall into a basefile. taken from mk-basefile
101 chroot $t apt-get clean
102 rm -f $t/etc/hostname $t/etc/resolv.conf \
103 $t/var/lib/apt/lists/*_* $t/usr/bin/qemu-*-static \
104 $t/etc/udev/rules.d/70-persistent-net.rules
105 echo | dd of=$t/etc/machine-id
106 tar --one-file-system -C $t -cf - . | zstd -9 > /a/bin/fai-basefiles/basefiles/${distver^^}64BIG.tar.zst
107
108
109 cleanup
110 exit 0