2 # Copyright (C) 2019 Ian Kelling
3 # SPDX-License-Identifier: Apache-2.0
5 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
6 shopt -s inherit_errexit
2>/dev
/null ||
: # ignore fail in bash < 4.4
8 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
9 # alternatively, using https://iankelling.org/git/?p=errhandle;a=tree
10 # source /path/errhandle/err
12 source /a
/bin
/errhandle
/err
14 [[ $EUID == 0 ]] ||
exec sudo
-E "${BASH_SOURCE[0]}" "$@"
16 subvol
=$1 # eg ubuntubionic
19 if (( $# != 2 )); then
20 echo $0: error expected
2 arguments
24 # lots of this is taken from default.PARTITION
26 if (($
(nproc
) > 2)); then
30 rm -f $nr/etc
/{fs
,crypt}tab
31 while read -r line
; do
32 printf "%s none keyscript=decrypt_keyctl,discard,luks,initramfs\n" "$line" >>$nr/etc
/crypttab
33 done < <(awk '{print $1,$2}' /mnt
/root
/root2-crypttab
)
34 awk '$3 == "/dev/urandom" {print}' /etc
/crypttab
>>$nr/etc
/crypttab
37 rootdev
=$
(awk '$2 == "/mnt/root2" {print $1}' /mnt
/root
/root2-fstab
)
38 fstabstd
=x-systemd.device-timeout
=30s
,x-systemd.mount-timeout
=30s
39 bootdev
=$
(awk '$2 == "/mnt/boot2" {print $1}' /mnt
/root
/root2-fstab
)
42 cat >> $nr/etc
/fstab
<<EOF
43 $rootdev / btrfs $fstabstd,noatime,subvol=root_$subvol$mopts 0 0
44 $rootdev /mnt/root btrfs $fstabstd,noatime,subvolid=0$mopts 0 0
45 $bootdev /boot btrfs nofail,$fstabstd,noatime,subvol=boot_$subvol 0 0
46 $bootdev /mnt/boot btrfs nofail,$fstabstd,noatime,subvolid=0 0 0
47 tmpfs /tmp tmpfs nodev,nosuid,size=50%,mode=1777 0 0
49 awk '$2 == "/boot/efi" {print}' /etc
/fstab
>>$nr/etc
/fstab
52 while read -r mdname
; do
53 cat >> $nr/etc
/fstab
<<EOF
54 /dev/mapper/$mdname none swap nofail,$fstabstd,sw 0 0
56 done < <(awk '$3 == "/dev/urandom" {print $1}' /etc
/crypttab
)