Merge branch 'upstream', fai 5.4
[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 usedm=$(dmsetup ls 2>/dev/null | egrep -v '^live-rw|^live-base|^No devices found' | wc -l)
19 if [ $usedm -ne 0 ]; then
20 if [ ! -d $target/etc/lvm ]; then
21 echo ERROR: Found lvm devices, but the lvm2 package was not installed
22 error=1
23 fi
24 fi
25 fi
26
27 # remove backup files from cfengine, but only if cfengine is installed
28 if [ -x /usr/sbin/cfagent ] || [ -x $target/usr/sbin/cfagent ] ; then
29 dirs="root etc var"
30 for path in $dirs; do
31 find $target/$path -maxdepth 20 -name \*.cfedited -o -name \*.cfsaved | xargs -r rm
32 done
33 fi
34
35 [ "$FAI_DEBMIRROR" ] &&
36 ainsl /etc/fstab "#$FAI_DEBMIRROR $MNTPOINT nfs ro 0 0"
37
38 # set bios clock
39 if [ $do_init_tasks -eq 1 ] ; then
40 case "$UTC" in
41 no|"") hwopt="--localtime" ;;
42 yes) hwopt="--utc" ;;
43 esac
44 hwclock $hwopt --systohc || true
45 fi
46
47 # Make sure everything is configured properly
48 if ifclass DEBIAN || ifclass UBUNTU; then
49 echo "Running \"apt-get -f install\" for the last time."
50 $ROOTCMD apt-get -f install
51 fi
52
53 if [ $FAI_ACTION = "install" ]; then
54 lskernels=$(echo $target/boot/vmlinu*)
55 if [ ! -f ${lskernels%% *} ]; then
56 echo "ERROR: No kernel was installed. Have a look at shell.log" >&2
57 error=1
58 fi
59 fi
60
61 # copy sources.list
62 fcopy -iM /etc/apt/sources.list
63
64
65 setrel() {
66
67 # if release is not set, try to determine it
68
69 if [ -n "$release" ]; then
70 return
71 fi
72 if [ ! -f $target/etc/os-release ]; then
73 return
74 fi
75
76 dists="jessie stretch buster xenial trusty"
77 for d in $dists; do
78 if grep -iq $d $target/etc/os-release; then
79 release=$d
80 break
81 fi
82 done
83 }
84
85 # if installation was done from CD, replace useless sources.list
86 setrel
87 if [ -f $target/etc/apt/sources.list -a -n "$release" ]; then
88 grep -q 'file generated by fai-cd' $target/etc/apt/sources.list && cat <<EOF > $target/etc/apt/sources.list
89 deb $apt_cdn/debian $release main contrib non-free
90 deb $apt_cdn/debian-security $release/updates main contrib non-free
91 deb [trusted=yes] http://fai-project.org/download $release koeln
92 EOF
93 fi
94
95 # for ARM architecture, we may need the kernel and initrd to boot or flash the device
96 if ifclass ARM64; then
97 cp -pv $target/boot/vmlinuz* $target/boot/initrd* $LOGDIR
98 fi
99
100 exit $error