minor fixes and improvements
[automated-distro-installer] / fai / config / scripts / LAST / 50-misc
1 #! /bin/bash
2
3 # copyright Thomas Lange 2001-2016, lange@debian.org
4
5 error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code
6
7 if [ "$FAI_ACTION" = "dirinstall" -o $do_init_tasks -eq 0 ] ; then
8 :
9 else
10 # check if mdadm has been forgotten
11 if grep -q active /proc/mdstat 2>/dev/null; then
12 if [ ! -d $target/etc/mdadm ]; then
13 echo ERROR: Found Software RAID, but the mdadm package was not installed
14 error=1
15 fi
16 fi
17
18 # i use dm for crypt, not lvm, so this gives false positive. todo, send patch to remove this
19 # upstream.
20 # usedm=$(dmsetup ls 2>/dev/null | egrep -v '^live-rw|^live-base|^No devices found' | wc -l)
21 # if [ $usedm -ne 0 ]; then
22 # if [ ! -d $target/etc/lvm ]; then
23 # echo ERROR: Found lvm devices, but the lvm2 package was not installed
24 # error=1
25 # fi
26 # fi
27 fi
28
29 # remove backup files from cfengine, but only if cfengine is installed
30 if [ -x /usr/sbin/cfagent ] || [ -x $target/usr/sbin/cfagent ] ; then
31 dirs="root etc var"
32 for path in $dirs; do
33 find $target/$path -maxdepth 20 -name \*.cfedited -o -name \*.cfsaved | xargs -r rm
34 done
35 fi
36
37 [ "$FAI_DEBMIRROR" ] &&
38 ainsl /etc/fstab "#$FAI_DEBMIRROR $MNTPOINT nfs ro 0 0"
39
40 # set bios clock
41 if [ $do_init_tasks -eq 1 ] ; then
42 case "$UTC" in
43 no|"") hwopt="--localtime" ;;
44 yes) hwopt="--utc" ;;
45 esac
46 hwclock $hwopt --systohc || true
47 fi
48
49 # Make sure everything is configured properly
50 if ifclass DEBIAN || ifclass UBUNTU; then
51 echo "Running \"apt-get -f install\" for the last time."
52 $ROOTCMD apt-get -f install
53 fi
54
55 if [ $FAI_ACTION = "install" ]; then
56 lskernels=$(echo $target/boot/vmlinu*)
57 if [ ! -f ${lskernels%% *} ]; then
58 echo "ERROR: No kernel was installed. Have a look at shell.log" >&2
59 error=1
60 fi
61 fi
62
63 # copy sources.list
64 fcopy -iSM /etc/apt/sources.list
65
66
67 setrel() {
68
69 # if release is not set, try to determine it
70
71 if [ -n "$release" ]; then
72 return
73 fi
74 if [ ! -f $target/etc/os-release ]; then
75 return
76 fi
77
78 dists="jessie stretch buster bullseye bookworm bionic xenial trusty"
79 for d in $dists; do
80 if grep -iq $d $target/etc/os-release; then
81 release=$d
82 break
83 fi
84 done
85 }
86
87 # if installation was done from CD, replace useless sources.list
88 setrel
89 if [ -f $target/etc/apt/sources.list -a -n "$release" ]; then
90 grep -q 'file generated by fai-cd' $target/etc/apt/sources.list && cat <<EOF > $target/etc/apt/sources.list
91 deb $apt_cdn/debian $release main contrib non-free
92 deb $apt_cdn/debian-security $release/updates main contrib non-free
93 #deb [trusted=yes] http://fai-project.org/download $release koeln
94 EOF
95 # if the package fai-server was installed, enable the project's repository
96 if [ -f $target/var/lib/dpkg/info/fai-server.list ]; then
97 sed -i -e '/fai-project.org/s/^#//' $target/etc/apt/sources.list
98 fi
99 fi
100
101 # for ARM architecture, we may need the kernel and initrd to boot or flash the device
102 if ifclass ARM64; then
103 cp -pv $target/boot/vmlinuz* $target/boot/initrd* $FAI_RUNDIR
104 fi
105
106 exit $error