vinstaller/main.sh

356 lines
8.7 KiB
Bash
Raw Normal View History

2022-02-06 22:12:28 +01:00
#!/bin/bash
main="/tmp/vinstall"
target="${main}/target"
2022-02-07 05:35:12 +01:00
tmp_target="${main}/tmp_target"
2022-02-06 23:25:49 +01:00
pass="oem"
2022-02-07 01:34:16 +01:00
if [ $DEBUG ]; then
2022-02-07 03:43:38 +01:00
umount -R ${target}/boot/efi ${target}/boot ${target}
2022-02-07 01:34:16 +01:00
vgchange -an
2022-02-07 01:35:12 +01:00
cryptsetup close /dev/mapper/luks*
fi
2022-02-07 01:34:16 +01:00
2022-02-06 23:25:49 +01:00
mkdir -p $target
2022-02-06 22:12:28 +01:00
2022-02-07 05:06:37 +01:00
. ./etc/functions
2022-02-06 22:12:28 +01:00
target_phy_disk() {
header "Choose target disk"
local DISKS_DETAILS
local output
DISKS_DETAILS=$(lsblk -l -o KNAME,TYPE,SIZE,MODEL,WWN|grep disk)
echo "$DISKS_DETAILS"
2022-02-07 04:29:43 +01:00
multiplechoice $(echo "${DISKS_DETAILS}"|awk '{print $1}')
2022-02-06 23:25:49 +01:00
TARGET_PHY_DISK="/dev/${output}"
2022-02-06 22:12:28 +01:00
}
target_phy_id() {
local i
local f1
local f2
for i in $(find /dev/disk/by-id|grep -v part); do
if realpath "$i" | grep -q -i "$TARGET_PHY_DISK"; then
if echo "$i" | grep -q "wwn"; then
TARGET_PHY_WWN="$i"
f1=1
fi
if echo "$i" | grep -q -v "wwn"; then
TARGET_PHY_ID="$i"
f2=1
fi
fi
done
if [ "$f1" == "1" ] && [ "$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 "implemented:"
echo "a)keyfile in initramfs" #bios: 1 uefi: 2
2022-02-06 23:25:49 +01:00
echo "b)no encryption" #bios: 2 uefi: 2
2022-02-07 05:38:43 +01:00
#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
2022-02-07 03:58:13 +01:00
multiplechoice "a" "b" "c" "d" "e"
2022-02-06 22:12:28 +01:00
ENCRYPTION_STYLE="$output"
}
2022-02-06 23:25:49 +01:00
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
2022-02-07 00:38:15 +01:00
parted -a optimal $TARGET_PHY_WWN -s -- mklabel gpt
2022-02-06 23:25:49 +01:00
size=500
2022-02-07 01:05:55 +01:00
parted -a optimal $TARGET_PHY_WWN unit mib -s -- mkpart EFI fat32 $start $(( start + size ))
2022-02-07 01:36:01 +01:00
sleep 2
2022-02-07 01:07:35 +01:00
start=$(( start + size ))
2022-02-07 00:38:15 +01:00
parted -a optimal $TARGET_PHY_WWN unit mib -s -- mkpart root $start -1s
2022-02-07 01:21:25 +01:00
mkfs.vfat -F32 ${TARGET_PHY_WWN}-part1
2022-02-06 23:25:49 +01:00
TARGET_PART="2"
else
2022-02-07 00:38:15 +01:00
parted -a optimal $TARGET_PHY_WWN -s -- mklabel msdos
2022-02-06 23:25:49 +01:00
TARGET_PART="1"
if [ "$ENCRYPTION_STYLE" == "b" ] || [ "$ENCRYPTION_STYLE" == "e" ]; then
size=2048
2022-02-07 01:05:55 +01:00
parted -a optimal $TARGET_PHY_WWN unit mib -s -- mkpart primary ext4 $start $(( start + size ))
2022-02-07 01:36:01 +01:00
sleep 2
2022-02-07 01:07:35 +01:00
start=$(( start + size ))
2022-02-07 01:30:08 +01:00
mkfs.btrfs -f "${TARGET_PHY_WWN}-part1"
2022-02-06 23:25:49 +01:00
TARGET_PART="2"
fi
2022-02-07 00:38:15 +01:00
parted -a optimal $TARGET_PHY_WWN unit mib -s -- mkpart primary ext4 $start -1s
2022-02-06 23:25:49 +01:00
fi
2022-02-07 01:36:01 +01:00
sleep 2
2022-02-06 23:25:49 +01:00
TARGETNAME=$(basename ${TARGET_PHY_WWN}-part${TARGET_PART})
2022-02-07 01:15:40 +01:00
TARGETNAME_UNDERSCORE=${TARGETNAME//-/_}
2022-02-07 00:25:49 +01:00
echo -n $pass | cryptsetup luksFormat ${TARGET_PHY_WWN}-part${TARGET_PART} -d -
2022-02-06 23:25:49 +01:00
#echo -n $pass | sudo cryptsetup luksOpen /dev/sdc1 sdc1 -d -
2022-02-07 01:34:16 +01:00
echo -n $pass | cryptsetup luksOpen ${TARGET_PHY_WWN}-part${TARGET_PART} "luks_${TARGETNAME_UNDERSCORE}" -d -
vgcreate vg_${TARGETNAME_UNDERSCORE} /dev/mapper/luks_${TARGETNAME_UNDERSCORE}
2022-02-07 01:17:29 +01:00
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
2022-02-06 23:25:49 +01:00
btrfs subvol create ${target}/root
btrfs subvol create ${target}/home
umount $target
2022-02-07 01:17:29 +01:00
mount /dev/mapper/vg_${TARGETNAME_UNDERSCORE}-root $target -o subvol=root
2022-02-06 22:12:28 +01:00
if [ "$EFI" == "1" ]; then
2022-02-06 23:25:49 +01:00
mkdir -p ${target}/boot/efi
mount ${TARGET_PHY_WWN}-part1 ${target}/boot/efi
2022-02-06 22:12:28 +01:00
else
2022-02-06 23:25:49 +01:00
if [ "$ENCRYPTION_STYLE" == "b" ] || [ "$ENCRYPTION_STYLE" == "e" ]; then
mkdir -p ${target}/boot
mount ${TARGET_PHY_WWN}-part1 ${target}/boot
fi
2022-02-06 22:12:28 +01:00
fi
2022-02-07 03:32:29 +01:00
for dir in dev proc sys run; do
mkdir -p ${target}/$dir
mount --rbind /$dir ${target}/$dir
mount --make-rslave ${target}/$dir
done
2022-02-06 22:12:28 +01:00
}
2022-02-07 02:34:12 +01:00
user() {
2022-02-07 04:19:38 +01:00
input "Username" "voiduser"
USERNAME=$output
2022-02-07 02:34:12 +01:00
}
2022-02-06 23:25:49 +01:00
2022-02-07 03:32:29 +01:00
hostname() {
2022-02-07 04:19:38 +01:00
input "Hostname" "voidlinux"
HOSTNAME=$output
2022-02-07 03:32:29 +01:00
}
base() {
2022-02-07 03:50:46 +01:00
. ./etc/base
2022-02-07 03:32:29 +01:00
packages
reset packages
2022-02-07 05:35:12 +01:00
cp ./etc/base $tmp_target
2022-02-07 03:32:29 +01:00
}
2022-02-07 02:34:12 +01:00
gfx() {
2022-02-07 05:35:12 +01:00
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
2022-02-07 02:34:12 +01:00
}
2022-02-06 23:25:49 +01:00
2022-02-07 02:34:12 +01:00
soundsystem() {
2022-02-07 05:35:12 +01:00
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
2022-02-07 02:34:12 +01:00
}
2022-02-06 23:25:49 +01:00
2022-02-07 05:35:12 +01:00
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
2022-02-07 02:34:12 +01:00
packages
2022-02-07 03:32:29 +01:00
reset packages
2022-02-07 05:35:12 +01:00
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
2022-02-07 04:18:16 +01:00
packages
reset packages
2022-02-07 05:35:12 +01:00
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
2022-02-07 02:34:12 +01:00
fi
}
2022-02-06 23:25:49 +01:00
2022-02-07 02:34:12 +01:00
printing() {
2022-02-07 05:36:07 +01:00
yesno "Do you want printing?" "n"
2022-02-07 02:34:12 +01:00
if [ "$output" == "yes" ]; then
addpkg cups
fi
}
lang() {
2022-02-07 04:09:57 +01:00
multiplechoice "de" "en"
2022-02-07 03:32:29 +01:00
LANGUAGE=$output
if [ "$LANGUAGE" == "de" ]; then
2022-02-07 02:34:12 +01:00
L1=de_DE
fi
}
bootloader() {
2022-02-07 05:35:12 +01:00
for i in $(find ./etc/bootloader/ -type f); do
bootloader+=("$(basename $i)")
2022-02-07 05:06:12 +01:00
done
2022-02-07 05:35:12 +01:00
if [ "${#bootloader[@]}" -gt "1" ]; then
multiplechoice "${bootloader[@]}"
BOOTLOADER=$output
elif [ "${#bootloader[@]}" -eq "1" ]; then
BOOTLOADER=${bootloader[0]}
2022-02-07 02:34:12 +01:00
fi
2022-02-07 05:35:12 +01:00
if ! [ "${#bootloader[@]}" -eq "0" ]; then
. ./etc/bootloader/$BOOTLOADER
packages
reset packages
cp ./etc/bootloader/$BOOTLOADER $tmp_target
fi
2022-02-07 02:34:12 +01:00
}
2022-02-07 05:06:12 +01:00
network() {
2022-02-07 05:35:12 +01:00
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
2022-02-07 05:06:12 +01:00
}
2022-02-07 02:34:12 +01:00
do_install() {
2022-02-07 03:32:29 +01:00
mkdir -p ${target}/var/db/xbps/keys
cp /var/db/xbps/keys/* ${target}/var/db/xbps/keys
2022-02-07 02:40:24 +01:00
xbps-install -Sy -R https://alpha.de.repo.voidlinux.org/current -r $target "${pkgs[@]}"
2022-02-07 02:34:12 +01:00
}
2022-02-07 03:32:29 +01:00
do_chroot() {
mkdir -p ${target}/tmp/vinstaller/run
2022-02-07 03:42:38 +01:00
2022-02-07 03:50:46 +01:00
cp ./etc/base ${target}/tmp/vinstaller/run
2022-02-07 05:06:12 +01:00
cp ./etc/functions ${target}/tmp/vinstaller/run
2022-02-07 03:32:29 +01:00
if ! [ "$DE" == "minimal" ]; then
2022-02-07 03:50:46 +01:00
cp ./etc/gfx/$GFX ${target}/tmp/vinstaller/run
cp ./etc/soundsystem/$SOUNDSYSTEM ${target}/tmp/vinstaller/run
2022-02-07 04:18:16 +01:00
cp ./etc/de/$DE ${target}/tmp/vinstaller/run
2022-02-07 05:06:12 +01:00
cp ./etc/x11 ${target}/tmp/vinstaller/run
2022-02-07 03:32:29 +01:00
fi
2022-02-07 03:42:38 +01:00
echo "USERNAME=$USERNAME" > ${target}/tmp/vinstaller/vars
2022-02-07 04:26:42 +01:00
echo "pass=$pass" > ${target}/tmp/vinstaller/vars
2022-02-07 03:42:38 +01:00
echo "HOSTNAME=$HOSTNAME" >> ${target}/tmp/vinstaller/vars
echo "EFI=$EFI" >> ${target}/tmp/vinstaller/vars
echo "LANGUAGE=$LANGUAGE" >> ${target}/tmp/vinstaller/vars
echo "TARGET_PHY_WWN=$TARGET_PHY_WWN" >> ${target}/tmp/vinstaller/vars
echo "TARGET_PART=$TARGET_PART" >> ${target}/tmp/vinstaller/vars
echo "TARGETNAME_UNDERSCORE=$TARGETNAME_UNDERSCORE" >> ${target}/tmp/vinstaller/vars
2022-02-07 03:32:29 +01:00
cat <<EOF > ${target}/tmp/vinstaller/main_chroot
2022-02-07 04:23:51 +01:00
#!/bin/bash
2022-02-07 03:42:38 +01:00
. /tmp/vinstaller/vars
2022-02-07 05:06:12 +01:00
. /tmp/vinstaller/functions
2022-02-07 03:50:46 +01:00
for file in \$(find /tmp/vinstaller/run -type f); do
2022-02-07 04:26:42 +01:00
. \$file
2022-02-07 03:32:29 +01:00
config
done
EOF
2022-02-07 04:42:31 +01:00
2022-02-07 04:39:26 +01:00
chmod +x ${target}/tmp/vinstaller/main_chroot
2022-02-07 04:23:51 +01:00
chroot ${target} /tmp/vinstaller/main_chroot
2022-02-07 03:32:29 +01:00
}
2022-02-07 02:34:12 +01:00
target_phy_disk
target_phy_id
use_efi
encryption_style
hibernation
user
2022-02-07 03:32:29 +01:00
hostname
2022-02-07 02:34:12 +01:00
base
bootloader
2022-02-07 05:35:38 +01:00
profile
2022-02-07 04:18:16 +01:00
printing
2022-02-07 00:29:48 +01:00
do_partition
2022-02-07 03:32:29 +01:00
do_install
do_chroot