diff --git a/installing/debootstrap_ordis_portables.sh b/installing/debootstrap_ordis_portables.sh index 3403028..f2b6c88 100755 --- a/installing/debootstrap_ordis_portables.sh +++ b/installing/debootstrap_ordis_portables.sh @@ -39,13 +39,18 @@ varia[b]=boot_device boot_device= usage[R]="The device where the system will be installed" -varia[R]=boot_device -boot_device= +varia[R]=root_device +root_device= usage[l]="System locale" varia[l]=locale locale="en_US.UTF-8 UTF-8\nfr_FR.UTF-8 UTF-8" +usage[w]="Wireguard IP last number (4 for 1.2.3.4)" +varia[w]=wireguard_number +wireguard_number= + + . driglibash-args @@ -63,7 +68,7 @@ install="vim openssh-server git nginx" . driglibash-base chroot_run(){ - run echo "$@" | chroot "$mnt" + chroot "$mnt" $@ if [ "$?" -ne 0 ] ; then die "Error, chroot command [$@] exited with code '$?'" fi @@ -77,16 +82,14 @@ wait_for_user(){ mount_misc(){ run mkdir -p "$mnt"/{proc,dev,sys} - run mount -t proc none "$mnt/proc" - clean "umount '$mnt/proc'" + run mount -t proc /proc "$mnt/proc" + #clean "umount '$(realpath "$mnt/proc")'" # To access physical devices - run mount -o bind /dev "$mnt/dev" - clean "umount '$mnt/dev'" - run mount -o bind /dev/pts "$mnt/dev/pts" - clean "umount '$mnt/dev/pts'" - run mount -o bind /sys "$mnt/sys" - clean "umount '$mnt/sys'" - # mount /dev/pts ? apt install complain about its absence + run mount --rbind --make-rslave /dev "$mnt/dev" + #clean "umount -R '$(realpath "$mnt/dev")'" + run mount --rbind --make-rslave /sys "$mnt/sys" + #clean "umount -R '$(realpath "$mnt/sys")'" + clean "umount -R '$mnt'" } if [ -z "$hostname" ] ; then @@ -104,15 +107,25 @@ if ! [ -d "$secret_dir" ] ; then fi -section "debootstraping" +section "Mounting additionnal items" +if [ -n "$(df | grep "$root_device")" ] ; then + run umount "$root_device" +fi +run mount --make-private "$root_device" "$mnt" +clean "umount -R '$mnt'" + + # Debootstrap may fail when the target is an existing system -#if [ -n "$(ls -A $mnt)" ]; then -# die "Root dir '$mnt' is not empty. Won’t debootstrap it." -#fi +if [ -n "$(ls -A $mnt)" ]; then + die "Root dir '$mnt' is not empty. Won’t debootstrap it." +fi + + + +section "debootstraping" run debootstrap --verbose --arch "$arch" "$release" "$mnt" "$repo" -section "Mounting additionnal items" mount_misc @@ -121,7 +134,7 @@ section "Installing selected software" chroot "$mnt" <> "$mnt/root/.ssh/authorized_keys" + yell "Secret dir is not empty. May erase key." fi +run export HOSTNAME="$hostname" && ssh-keygen -b 4096 -f "$secret_dir/id_rsa" -P '' +run mkdir -p "$mnt/root/.ssh/" +cat "$secret_dir/id_rsa.pub" >> "$mnt/root/.ssh/authorized_keys" +section "Creating wireguard conf" +if [ -n "$wireguard_number" ] ; then + run cat >> "$mnt/etc/wireguard/jeancloud.conf" <> "$secret_dir/wg_conf_part_$hostname" < "/etc/locale.gen" chroot_run locale-gen