#!/bin/bash main="/tmp/vinstall" target="${main}/target" tmp_target="${main}/tmp_target" pass="oem" timezone="Europe/Berlin" if [ $DEBUG ]; then umount -R ${target}/boot/efi ${target}/boot ${target}/tmp/vinstaller/ ${target} vgchange -an cryptsetup close /dev/mapper/luks* fi mkdir -p $target . ./etc/functions target_phy_disk() { header "Choose target disk" local DISKS_DETAILS local output DISKS_DETAILS=$(lsblk -l -o KNAME,TYPE,SIZE,MODEL|grep disk) echo "$DISKS_DETAILS" multiplechoice $(echo "${DISKS_DETAILS}"|awk '{print $1}') TARGET_PHY_DISK="${output}" } target_phy_id() { local i local f2 for i in $(find /dev/disk/by-id ! -type d|grep -v part); do if realpath "$i" | grep -q -i "$TARGET_PHY_DISK"; then if echo "$i" | grep -v "wwn" | grep -q -v "eui"; then TARGET_PHY_ID="$i" f2=1 fi fi done if [ "$f2" == "1" ]; then return 0 else err "no id found" fi } use_efi() { if test -e /sys/firmware/efi; then EFI=1 else EFI=0 fi } encryption_style() { header "Choose encryption style" echo "a)keyfile in initramfs" #bios: 1 uefi: 2 echo "b)no encryption" #bios: 2 uefi: 2 #echo "not implemented:" #echo "c)no keyfile (double pw enter)" #bios: 1 uefi: 2 #echo "d)keyfile on usb" #bios: 1 uefi: ? #echo "e)unencrypted boot" #bios: 2 uefi: 2 multiplechoice "a" "b" "c" "d" "e" ENCRYPTION_STYLE="$output" } hibernation() { ramsize="$(($(getconf _PHYS_PAGES) * $(getconf PAGE_SIZE) / (1024 * 1024)))" ramsize="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}/1024); }")" HIBERNATE=1 if [[ "${ramsize}" -lt "2" ]]; then SWAPSIZE="$(( ramsize * 2 ))" SWAPSIZE="$(( ramsize * 3 ))" elif [[ "${ramsize}" -ge "2" ]] && [[ "${ramsize}" -lt "8" ]]; then SWAPSIZE="${ramsize}" SWAPSIZE="$(( ramsize * 2 ))" elif [[ "${ramsize}" -ge "8" ]] && [[ "${ramsize}" -lt "16" ]]; then SWAPSIZE="${ramsize}" SWAPSIZE="$(awk "BEGIN { printf(\"%.0f\n\", ${ramsize}*1.5); }")" elif [[ "${ramsize}" -ge "16" ]]; then SWAPSIZE="4" echo "hibernate not recommended, turning off" HIBERNATE="0" SWAPSIZE="4" fi } do_partition() { header "do partition" start=1 if [ "$EFI" == "1" ]; then parted $TARGET_PHY_ID -s -- mklabel gpt sleep 2 size=512 parted $TARGET_PHY_ID unit mib -s -- mkpart EFI fat32 $start $(( start + size )) parted $TARGET_PHY_ID unit mib -s -- set 1 esp on sleep 2 start=$(( start + size )) parted $TARGET_PHY_ID unit mib -s -- mkpart root ext4 $start 100% sleep 2 mkfs.vfat -F32 ${TARGET_PHY_ID}-part1 TARGET_PART="2" else parted $TARGET_PHY_ID -s -- mklabel msdos sleep 2 TARGET_PART="1" if [ "$ENCRYPTION_STYLE" == "b" ] || [ "$ENCRYPTION_STYLE" == "e" ]; then size=2048 parted $TARGET_PHY_ID unit mib -s -- mkpart primary ext4 $start $(( start + size )) sleep 2 start=$(( start + size )) mkfs.btrfs -f "${TARGET_PHY_ID}-part1" TARGET_PART="2" fi parted $TARGET_PHY_ID unit mib -s -- mkpart primary ext4 $start -1s fi sleep 2 TARGETNAME=$(basename ${TARGET_PHY_ID}-part${TARGET_PART}) TARGETNAME_UNDERSCORE=${TARGETNAME//-/_} T=/dev/disk/by-id/${TARGET_PHY_ID}-part${TARGET_PART} if [ "$ENCRYPTION_STYLE" == "a" ]; then T=/dev/mapper/luks_${TARGETNAME_UNDERSCORE} echo -n $pass | cryptsetup luksFormat ${TARGET_PHY_ID}-part${TARGET_PART} -d - #echo -n $pass | sudo cryptsetup luksOpen /dev/sdc1 sdc1 -d - echo -n $pass | cryptsetup luksOpen ${TARGET_PHY_ID}-part${TARGET_PART} "luks_${TARGETNAME_UNDERSCORE}" -d - fi vgcreate vg_${TARGETNAME_UNDERSCORE} $T lvcreate --name swap -L ${SWAPSIZE}G vg_${TARGETNAME_UNDERSCORE} lvcreate --name root -l 100%FREE vg_${TARGETNAME_UNDERSCORE} mkswap -f /dev/mapper/vg_${TARGETNAME_UNDERSCORE}-swap mkfs.btrfs -f /dev/mapper/vg_${TARGETNAME_UNDERSCORE}-root mount /dev/mapper/vg_${TARGETNAME_UNDERSCORE}-root $target btrfs subvol create ${target}/root btrfs subvol create ${target}/home umount $target mount /dev/mapper/vg_${TARGETNAME_UNDERSCORE}-root $target -o subvol=root if [ "$EFI" == "1" ]; then mkdir -p ${target}/boot/efi mount ${TARGET_PHY_ID}-part1 ${target}/boot/efi else if [ "$ENCRYPTION_STYLE" == "b" ] || [ "$ENCRYPTION_STYLE" == "e" ]; then mkdir -p ${target}/boot mount ${TARGET_PHY_ID}-part1 ${target}/boot fi fi for dir in dev proc sys run; do mkdir -p ${target}/$dir mount --rbind /$dir ${target}/$dir mount --make-rslave ${target}/$dir done } user() { input "Username" "voiduser" USERNAME=$output } hostname() { input "Hostname" "voidlinux" HOSTNAME=$output } base() { . ./etc/base packages reset packages } gfx() { for i in $(find ./etc/gfx/ -type f); do gfx+=("$(basename $i)") done if [ "${#gfx[@]}" -gt "1" ]; then multiplechoice "${gfx[@]}" GFX=$output elif [ "${#gfx[@]}" -eq "1" ]; then GFX=${gfx[0]} fi if ! [ "${#gfx[@]}" -eq "0" ]; then . ./etc/gfx/$GFX packages reset packages cp ./etc/gfx/$GFX $tmp_target fi } soundsystem() { for i in $(find ./etc/soundsystem/ -type f); do soundsystem+=("$(basename $i)") done if [ "${#soundsystem[@]}" -gt "1" ]; then multiplechoice "${soundsystem[@]}" SOUNDSYSTEM=$output elif [ "${#soundsystem[@]}" -eq "1" ]; then SOUNDSYSTEM=${soundsystem[0]} fi if ! [ "${#soundsystem[@]}" -eq "0" ]; then . ./etc/soundsystem/$SOUNDSYSTEM packages reset packages cp ./etc/soundsystem/$SOUNDSYSTEM $tmp_target fi } xserver() { for i in $(find ./etc/xserver/ -type f); do xserver+=("$(basename $i)") done if [ "${#xserver[@]}" -gt "1" ]; then multiplechoice "${xserver[@]}" XSERVER=$output elif [ "${#xserver[@]}" -eq "1" ]; then XSERVER=${xserver[0]} fi if ! [ "${#xserver[@]}" -eq "0" ]; then . ./etc/xserver/$XSERVER packages reset packages cp ./etc/xserver/$XSERVER $tmp_target fi } profile() { for i in $(find ./etc/profile/ -type f); do profile+=("$(basename $i)") done if [ "${#profile[@]}" -gt "1" ]; then multiplechoice "${profile[@]}" PROFILE=$output elif [ "${#profile[@]}" -eq "1" ]; then PROFILE=${profile[0]} fi if ! [ "${#profile[@]}" -eq "0" ]; then . ./etc/profile/$PROFILE packages reset packages cp ./etc/profile/$PROFILE $tmp_target if [ "$need_xserver" == "1" ]; then xserver fi if [ "$need_gfx" == "1" ]; then gfx fi if [ "$need_sound" == "1" ]; then soundsystem fi fi } printing() { for i in $(find ./etc/printing/ -type f); do printing+=("$(basename $i)") done if [ "${#printing[@]}" -ge "1" ]; then if yesno "Do you want printing?" "n"; then if [ "${#printing[@]}" -gt "1" ]; then multiplechoice "${printing[@]}" PRINTING=$output elif [ "${#printing[@]}" -eq "1" ]; then PRINTING=${printing[0]} fi . ./etc/printing/$PRINTING packages reset packages cp ./etc/printing/$PRINTING $tmp_target fi fi if [ "$output" == "yes" ]; then addpkg cups fi } lang() { multiplechoice "de" "en" LANGUAGE=$output if [ "$LANGUAGE" == "de" ]; then L1=de_DE fi } bootloader() { for i in $(find ./etc/bootloader/ -type f); do bootloader+=("$(basename $i)") done if [ "${#bootloader[@]}" -gt "1" ]; then multiplechoice "${bootloader[@]}" BOOTLOADER=$output elif [ "${#bootloader[@]}" -eq "1" ]; then BOOTLOADER=${bootloader[0]} fi if ! [ "${#bootloader[@]}" -eq "0" ]; then . ./etc/bootloader/$BOOTLOADER packages reset packages cp ./etc/bootloader/$BOOTLOADER $tmp_target fi } network() { for i in $(find ./etc/network/ -type f); do network+=("$(basename $i)") done if [ "${#network[@]}" -gt "1" ]; then multiplechoice "${network[@]}" NETWORK=$output elif [ "${#network[@]}" -eq "1" ]; then NETWORK=${network[0]} fi if ! [ "${#network[@]}" -eq "0" ]; then . ./etc/network/$NETWORK packages reset packages cp ./etc/network/$NETWORK $tmp_target fi } do_install() { mkdir -p ${target}/var/db/xbps/keys cp /var/db/xbps/keys/* ${target}/var/db/xbps/keys xbps-install -Sy -R https://alpha.de.repo.voidlinux.org/current -r $target "${pkgs[@]}" } do_chroot() { mkdir -p ${target}/tmp/vinstaller/ mount -t tmpfs -o size=50m tmpfs ${target}/tmp/vinstaller/ mkdir -p ${target}/tmp/vinstaller/run cp ./etc/functions ${target}/tmp/vinstaller/ cp ./etc/base ${target}/tmp/vinstaller/ cp -rf $tmp_target ${target}/tmp/vinstaller/run echo "USERNAME=$USERNAME" > ${target}/tmp/vinstaller/vars echo "pass=$pass" >> ${target}/tmp/vinstaller/vars echo "HOSTNAME=$HOSTNAME" >> ${target}/tmp/vinstaller/vars echo "EFI=$EFI" >> ${target}/tmp/vinstaller/vars echo "LANGUAGE=$LANGUAGE" >> ${target}/tmp/vinstaller/vars echo "L1=$L1" >> ${target}/tmp/vinstaller/vars echo "TARGET_PHY_ID=$TARGET_PHY_ID" >> ${target}/tmp/vinstaller/vars echo "TARGET_PART=$TARGET_PART" >> ${target}/tmp/vinstaller/vars echo "TARGETNAME_UNDERSCORE=$TARGETNAME_UNDERSCORE" >> ${target}/tmp/vinstaller/vars echo "ENCRYPTION_STYLE=$ENCRYPTION_STYLE" >> ${target}/tmp/vinstaller/vars echo "timezone=$timezone" >> ${target}/tmp/vinstaller/vars cat < ${target}/tmp/vinstaller/main_chroot #!/bin/bash . /tmp/vinstaller/functions . /tmp/vinstaller/vars . /tmp/vinstaller/base for file in \$(find /tmp/vinstaller/run -type f); do . \$file config done EOF chmod +x ${target}/tmp/vinstaller/main_chroot chroot ${target} /tmp/vinstaller/main_chroot } ready() { echo "\n\n" echo "#################" echo "" echo "login with ${USERNAME}:${pass}" echo "hostname: $HOSTNAME" echo "" echo bibernation tbd echo encryption tbd #if hib/enc 1, then echo hibernation on/off resp. enc on/off } target_phy_disk target_phy_id use_efi encryption_style hibernation user hostname base bootloader profile printing do_partition do_install do_chroot ready