SpectreOS-old/arch-install
simono41 6c0ee575e9 fix
2018-04-01 16:45:09 +02:00

1056 lines
37 KiB
Bash
Executable file

#!/bin/bash
#
set -ex
echo "Version : DI 27. Feb 22:52:41 CET 2017"
WEBADDRESS="https://github.com/simono41/SpectreOS.git"
repo="SpectreOS"
user="user1"
version="%VERSION%"
[[ -n "${2}" ]] && version=${2}
[[ "$version" == "%VERSION%" ]] && version=voll
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
sudo $0 2>&1 | tee /home/user1/install.log
exit 0
fi
echo "Logged in as root"
function minimalinstallation() {
pacstrap -c -d -G -M ${mountpoint} $(cat /opt/${repo}/packages_voll.txt)
}
function gitclone() {
if [ -d "/opt/${repo}" ]; then
echo "${repo} already exists!!!"
cd /opt/${repo}
git pull
else
git clone ${WEBADDRESS} /opt/${repo}
fi
cd /
}
function secureumount() {
if [ "${dateisystem}" == "btrfs" ]; then
if cat /proc/mounts | grep ${mountpoint} > /dev/null; then
umount ${mountpoint}/boot
btrfs filesystem df ${mountpoint}
echo "umount!!!"
umount ${mountpoint}/home
umount ${mountpoint}/opt
umount ${mountpoint}/var/cache/pacman/pkg
umount ${mountpoint}/var/lib
# custom-mounts
for wort in ${mountsnaps}
do
umount ${mountpoint}${wort}
done
umount ${mountpoint}
umount /mnt/btrfs-root
#umount -R /mnt
fi
elif [ "${dateisystem}" == "ext4" ]; then
if cat /proc/mounts | grep ${mountpoint} > /dev/null; then
umount ${mountpoint}/boot
umount ${mountpoint}
fi
fi
if fdisk -l | grep /dev/mapper/luks0 > /dev/null; then
read -p "Should /dev/mapper/luks0 be removed? [Y/n] : " cryptremove
if [ "${cryptremove}" != "n" ]; then
cryptsetup remove /dev/mapper/luks0
fi
fi
if cat /proc/mounts | grep ${device}1 > /dev/null; then
umount ${device}1
fi
if cat /proc/mounts | grep ${usbkeydevice} > /dev/null; then
umount ${usbkeydevice}
fi
}
function partionierenmitswap() {
wipefs -a -f ${device}
sgdisk -o ${device}
sgdisk -a 2048 -n 1::+1024K -c 1:"BIOS Boot Partition" -t 1:ef02 ${device}
sgdisk -a 2048 -n 2::+1G -c 2:"EFI Boot Partition" -t 2:ef00 ${device}
sgdisk -a 2048 -n 3::+8G -c 3:"Linux swap" -t 3:8200 ${device}
sgdisk -a 2048 -n 4:: -c 4:"Linux filesystem" -t 4:8300 ${device}
if [ "${verschluesselung}" == "y" ]; then
echo "Please write big YES"
cryptsetup -c aes-xts-plain64 -y -s 512 luksFormat ${device}${rootpartitionnummer}
cryptsetup luksOpen ${device}${rootpartitionnummer} luks0
deviceluks="/dev/mapper/luks0"
fi
}
function partionierenohneswap() {
wipefs -a -f ${device}
sgdisk -o ${device}
sgdisk -a 2048 -n 1::+1024K -c 1:"BIOS Boot Partition" -t 1:ef02 ${device}
sgdisk -a 2048 -n 2::+1G -c 2:"EFI Boot Partition" -t 2:ef00 ${device}
sgdisk -a 2048 -n 3:: -c 3:"Linux filesystem" -t 3:8300 ${device}
if [ "${verschluesselung}" == "y" ]; then
echo "Please write big YES"
cryptsetup -c aes-xts-plain64 -y -s 512 luksFormat ${device}${rootpartitionnummer}
cryptsetup luksOpen ${device}${rootpartitionnummer} luks0
deviceluks="/dev/mapper/luks0"
fi
}
function usbkeyinstallation() {
mkdir -p /mnt/usb-stick
mount ${usbkeydevice} /mnt/usb-stick
dd if=/dev/urandom of=/mnt/usb-stick/archkey bs=512 count=4
cryptsetup luksAddKey ${device}${rootpartitionnummer} /mnt/usb-stick/archkey
}
function usbsecret() {
cp /opt/${repo}/install/usbsecret ${mountpoint}/usr/lib/initcpio/install/usbsecret
cp /opt/${repo}/hooks/usbsecret ${mountpoint}/root/usbsecret
# hooks
#cp install/usbsecret ${mountpoint}/usr/lib/initcpio/install/usbsecret
#cp hooks/usbsecret ${mountpoint}/usr/lib/initcpio/hooks/usbsecret
sed "s|%USB_UUID%|${usbsecretdeviceuuid}|g;" ${mountpoint}/root/usbsecret > ${mountpoint}/usr/lib/initcpio/hooks/usbsecret
}
function cron() {
echo "cron-job snapshot"
mkdir -p ${mountpoint}/var/spool/cron/
echo "0 18 * * * /usr/bin/snapshot make ROOT home opt var/cache/pacman/pkg ${mountsnaps}" > ${mountpoint}/var/spool/cron/root
if [ "${update}" != "n" ]; then
cp /opt/${repo}/snapshot.sh ${mountpoint}/usr/bin/snapshot
chmod 755 ${mountpoint}/usr/bin/snapshot
fi
}
function makeswapfile() {
#swapfile
fallocate -l ${swapfilespeicher} ${mountpoint}/swapfile
chmod 600 ${mountpoint}/swapfile
mkswap ${mountpoint}/swapfile
echo "/swapfile none swap defaults 0 0" >> ${mountpoint}/etc/fstab
}
function makebtrfsswapfile() {
/opt/${repo}/btrfs-swapon ${mountpoint}/usr/bin/btrfs-swapon
/opt/${repo}/btrfs-swapoff ${mountpoint}/usr/bin/btrfs-swapoff
/opt/${repo}/btrfs-swapon.service ${mountpoint}/root/btrfs-swapon.service
chmod +x ${mountpoint}/usr/bin/btrfs-swapon
chmod +x ${mountpoint}/usr/bin/btrfs-swapoff
sed "s|%swapfilespeicher%|${swapfilespeicher}|g;" ${mountpoint}/root/btrfs-swapon.service > ${mountpoint}/etc/systemd/system/btrfs-swapon.service
arch-chroot ${mountpoint} systemctl enable btrfs-swapon
}
function removeinstaller {
echo ""
if [ -f ${mountpoint}/usr/share/applications/arch-install.desktop ]
then
rm ${mountpoint}/usr/share/applications/arch-install.desktop
fi
echo ""
if [ -f ${mountpoint}/root/Schreibtisch/arch-install.desktop ]
then
rm ${mountpoint}/root/Schreibtisch/arch-install.desktop
fi
echo ""
if [ -f ${mountpoint}/home/${user}/Schreibtisch/arch-install.desktop ]
then
rm ${mountpoint}/home/${user}/Schreibtisch/arch-install.desktop
fi
echo ""
if [ -f ${mountpoint}/root/Desktop/arch-install.desktop ]
then
rm ${mountpoint}/root/Desktop/arch-install.desktop
fi
echo ""
if [ -f ${mountpoint}/home/${user}/Desktop/arch-install.desktop ]
then
rm ${mountpoint}/home/${user}/Desktop/arch-install.desktop
fi
echo ""
}
function installation {
#boot
echo "format"
mkfs.vfat -F 32 ${device}${efipartitionnummer}
#root
if [ "${dateisystem}" == "btrfs" ]; then
#mkfs.btrfs -f -L p_arch ${device}2
btrfsformat #btrfs
subvolume #btrfs
elif [ "${dateisystem}" == "ext4" ]; then
echo "confirm with j"
if [ "${verschluesselung}" == "y" ]; then
mkfs.ext4 -L p_arch ${deviceluks} #ext4
mount ${deviceluks} ${mountpoint}
else
mkfs.ext4 -L p_arch ${device}${rootpartitionnummer} #ext4
mount ${device}${rootpartitionnummer} ${mountpoint}
fi
fi
#swap
if [ "${swap}" != "n" ]; then
mkswap -L p_swap ${device}${swappartitionnummer}
fi
#installation
if [ "${offline}" != "n" ]
then
if [ -f /run/archiso/bootmnt/arch/$(uname -m)/airootfs.sfs ]; then
echo "It is not a copytoram system."
unsquashfs -f -d ${mountpoint} /run/archiso/bootmnt/arch/$(uname -m)/airootfs.sfs
elif [ -f /run/archiso/copytoram/airootfs.sfs ]; then
echo "It is a copytoram system."
unsquashfs -f -d ${mountpoint} /run/archiso/copytoram/airootfs.sfs
else
read -p "Where is the airootfs.sfs? Please specify the complete path or choose the online installation? [/airootfs.sfs/online] : " installationfehler
if [ "${installationfehler}" == "online" ]; then
minimalinstallation
else
unsquashfs -f -d ${mountpoint} ${installationfehler}
fi
fi
else
minimalinstallation
fi
# module and hooks
parameter="base udev "
if [ "${swap}" != "n" ]; then
parameter="${parameter}resume "
fi
if [ "${verschluesselung}" == "y" ]; then
parameter="${parameter}encrypt "
fi
parameter="${parameter}block filesystems keyboard "
if [ "${verschluesselung}" == "y" ]; then
echo "btrfs-hook is skipped!"
else
if [ "${dateisystem}" == "btrfs" ]; then
parameter="${parameter}btrfs "
fi
fi
if [ "${usbsecret}" == "y" ]; then
parameter="${parameter}usbsecret "
fi
if [ "${version}" != "libre" ]; then
parameter="${parameter}plymouth "
fi
echo ""
if [ "${version}" == "libre" ]; then
echo "MODULES=\"i915 radeon nouveau ata_generic ata_piix nls_cp437 vfat ext4 btrfs\"" > ${mountpoint}/etc/mkinitcpio.conf
else
echo "MODULES=\"nvidia nvidia_modeset nvidia_uvm nvidia_drm i915 radeon ata_generic ata_piix nls_cp437 vfat ext4 btrfs\"" > ${mountpoint}/etc/mkinitcpio.conf
fi
echo "HOOKS=\"${parameter}\"" >> ${mountpoint}/etc/mkinitcpio.conf
echo "COMPRESSION=\"lz4\"" >> ${mountpoint}/etc/mkinitcpio.conf
echo "FILES=\"/etc/modprobe.d/blacklist-floppy.conf\"" >> ${mountpoint}/etc/mkinitcpio.conf
echo ""
echo "blacklist floppy" > ${mountpoint}/etc/modprobe.d/blacklist-floppy.conf
echo "tmpfs /tmp tmpfs defaults 0 0" >> ${mountpoint}/etc/fstab
echo "tmpfs /dev/shm tmpfs defaults 0 0" >> ${mountpoint}/etc/fstab
#fstab
rootbind=$(blkid -s PARTUUID -o value ${device}${rootpartitionnummer})
#genfstab -Up ${mountpoint} >> ${mountpoint}/etc/fstab
if [ "${dateisystem}" == "btrfs" ]; then
btrfsfstab #btrfs
mkdir -p ${mountpoint}/run/btrfs-root
if [ "${verschluesselung}" == "y" ]; then
echo "${deviceluks} /run/btrfs-root/ btrfs defaults 0 0" >> ${mountpoint}/etc/fstab #btrfs
else
echo "PARTUUID=${rootbind} /run/btrfs-root/ btrfs defaults 0 0" >> ${mountpoint}/etc/fstab #btrfs
fi
#grep -v "/var/lib" < ${mountpoint}/etc/fstab > fstab.neu; mv fstab.neu ${mountpoint}/etc/fstab
echo "/run/btrfs-root/__current/ROOT/var/lib /var/lib none bind 0 0" >> ${mountpoint}/etc/fstab #btrfs
cron
elif [ "${dateisystem}" == "ext4" ]; then
if [ "${verschluesselung}" == "y" ]; then
echo "${deviceluks} / ext4 rw,defaults,noatime,nodiratime,discard 0 0" >> ${mountpoint}/etc/fstab
else
echo "PARTUUID=${rootbind} / ext4 rw,defaults,noatime,nodiratime,discard 0 0" >> ${mountpoint}/etc/fstab
fi
fi
bootbind=$(blkid -s PARTUUID -o value ${device}${efipartitionnummer})
echo -e "PARTUUID=${bootbind} /boot vfat rw,relatime 0 2" >> ${mountpoint}/etc/fstab
if [ "${swap}" != "n" ]; then
if [ "${verschluesselung}" == "y" ]; then
swappartition=$(blkid -s PARTUUID -o value ${device}${swappartitionnummer})
echo "swap PARTUUID=${swappartition} /dev/urandom swap,cipher=aes-cbc-essiv:sha256,size=256" >> ${mountpoint}/etc/crypttab
echo "/dev/mapper/swap none swap defaults 0 0" >> ${mountpoint}/etc/fstab
else
swappartition=$(blkid -s PARTUUID -o value ${device}${swappartitionnummer})
echo "PARTUUID=${swappartition} none swap defaults 0 0" >> ${mountpoint}/etc/fstab
fi
fi
#makeswapfile+fstab
if [ "${swapfile}" == "y" ]; then
if [ "${dateisystem}" == "btrfs" ]; then
makebtrfsswapfile
elif [ "${dateisystem}" == "ext4" ]; then
makeswapfile
fi
fi
#hostname
echo "${repo}-${version}" > ${mountpoint}/etc/hostname
if [ "${usbsecret}" == "y" ]; then
usbsecret
fi
if [ "${usbkey}" == "y" ]; then
usbkeyinstallation
fi
if [ "${verschluesselung}" == "y" ]; then
if [ "${boot}" == "grub" ]; then
tobootdevice=$(blkid -s PARTUUID -o value ${device}${rootpartitionnummer})
if [ "${swap}" != "n" ]; then
swappartition=$(blkid -s PARTUUID -o value ${device}${swappartitionnummer})
if [ "${usbkey}" == "y" ]; then
sed -i 's/GRUB_CMDLINE_LINUX=.*$/GRUB_CMDLINE_LINUX="cryptdevice=PARTUUID='$tobootdevice':luks0 resume=PARTUUID='$swappartition' cryptkey=UUID='$usbkeyuuid':'$usbkeydateisystem':\/archkey nvidia-drm.modeset=1 quiet splash"/' ${mountpoint}/etc/default/grub
else
sed -i 's/GRUB_CMDLINE_LINUX=.*$/GRUB_CMDLINE_LINUX="cryptdevice=PARTUUID='$tobootdevice':luks0 resume=PARTUUID='$swappartition' nvidia-drm.modeset=1 quiet splash"/' ${mountpoint}/etc/default/grub
fi
else
if [ "${usbkey}" == "y" ]; then
sed -i 's/GRUB_CMDLINE_LINUX=.*$/GRUB_CMDLINE_LINUX="cryptdevice=PARTUUID='$tobootdevice':luks0 cryptkey=UUID='$usbkeyuuid':'$usbkeydateisystem':\/archkey nvidia-drm.modeset=1 quiet splash"/' ${mountpoint}/etc/default/grub
else
sed -i 's/GRUB_CMDLINE_LINUX=.*$/GRUB_CMDLINE_LINUX="cryptdevice=PARTUUID='$tobootdevice':luks0 nvidia-drm.modeset=1 quiet splash"/' ${mountpoint}/etc/default/grub
fi
fi
echo "GRUB_ENABLE_CRYPTODISK=y" >> ${mountpoint}/etc/default/grub
fi
else
if [ "${boot}" == "grub" ]; then
tobootdevice=$(blkid -s PARTUUID -o value ${device}${rootpartitionnummer})
if [ "${swap}" != "n" ]; then
swappartition=$(blkid -s PARTUUID -o value ${device}${swappartitionnummer})
sed -i 's/GRUB_CMDLINE_LINUX=.*$/GRUB_CMDLINE_LINUX="resume=PARTUUID='$swappartition' nvidia-drm.modeset=1 quiet splash"/' ${mountpoint}/etc/default/grub
fi
fi
fi
#sie könne hier ihre scripte die bei der installation ausgeführt werden sollen hinzufügen :D
}
function btrfsformat() {
if [ "$raid" == "raid0" ]; then
if [ "${verschluesselung}" == "y" ]; then
mkfs.btrfs -f -m raid10 -d raid10 ${deviceluks} ${device1}
else
mkfs.btrfs -f -m raid0 -d raid0 ${device}${rootpartitionnummer} ${device1}
fi
elif [ "$raid" == "raid1" ]; then
if [ "${verschluesselung}" == "y" ]; then
mkfs.btrfs -f -m raid10 -d raid10 ${deviceluks} ${device1}
else
mkfs.btrfs -f -m raid1 -d raid1 ${device}${rootpartitionnummer} ${device1}
fi
elif [ "$raid" == "raid10" ]; then
if [ "${verschluesselung}" == "y" ]; then
mkfs.btrfs -f -m raid10 -d raid10 ${deviceluks} ${device1}
else
mkfs.btrfs -f -m raid10 -d raid10 ${device}${rootpartitionnummer} ${device1}
fi
else
if [ "${verschluesselung}" == "y" ]; then
mkfs.btrfs -f -m single ${deviceluks}
else
mkfs.btrfs -f -m single ${device}${rootpartitionnummer}
fi
fi
btrfs filesystem show
}
function btrfsfstab() {
rootbind=$(blkid -s PARTUUID -o value ${device}${rootpartitionnummer})
if [ "${verschluesselung}" == "y" ]; then
echo -e "${deviceluks} / btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/ROOT 0 0" >> ${mountpoint}/etc/fstab
echo -e "${deviceluks} /home btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/home 0 0" >> ${mountpoint}/etc/fstab
echo -e "${deviceluks} /opt btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/opt 0 0" >> ${mountpoint}/etc/fstab
echo -e "${deviceluks} /var/cache/pacman/pkg btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/var/cache/pacman/pkg 0 0" >> ${mountpoint}/etc/fstab
# custom-mounts
for wort in ${mountsnaps}
do
echo -e "${deviceluks} ${wort} btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current${wort} 0 0" >> ${mountpoint}/etc/fstab
done
else
echo -e "PARTUUID=${rootbind} / btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/ROOT 0 0" >> ${mountpoint}/etc/fstab
echo -e "PARTUUID=${rootbind} /home btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/home 0 0" >> ${mountpoint}/etc/fstab
echo -e "PARTUUID=${rootbind} /opt btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/opt 0 0" >> ${mountpoint}/etc/fstab
echo -e "PARTUUID=${rootbind} /var/cache/pacman/pkg btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/var/cache/pacman/pkg 0 0" >> ${mountpoint}/etc/fstab
# custom-mounts
for wort in ${mountsnaps}
do
echo -e "PARTUUID=${rootbind} ${wort} btrfs rw,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current${wort} 0 0" >> ${mountpoint}/etc/fstab
done
fi
}
function btrfsmount() {
#[[ -z "${device}" ]] && device=${2}
if [ "${1}" == "1" ] || [ "${1}" == "" ]; then
if [ "${verschluesselung}" == "y" ]; then
mkdir -p /mnt/btrfs-root
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo ${deviceluks} /mnt/btrfs-root
else
mkdir -p /mnt/btrfs-root
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo ${device}${rootpartitionnummer} /mnt/btrfs-root
fi
fi
if [ "${1}" == "2" ] || [ "${1}" == "" ]; then
if [ "${verschluesselung}" == "y" ]; then
mkdir -p ${mountpoint}
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/ROOT ${deviceluks} ${mountpoint}
mkdir -p ${mountpoint}/home
mkdir -p ${mountpoint}/opt
mkdir -p ${mountpoint}/var/cache/pacman/pkg
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/home ${deviceluks} ${mountpoint}/home
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/opt ${deviceluks} ${mountpoint}/opt
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/var/cache/pacman/pkg ${deviceluks} ${mountpoint}/var/cache/pacman/pkg
# custom-mounts
for wort in ${mountsnaps}
do
mkdir -p ${mountpoint}${wort}
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current${wort} ${deviceluks} ${mountpoint}${wort}
done
mkdir -p ${mountpoint}/var/lib
mount --bind /mnt/btrfs-root/__current/ROOT/var/lib ${mountpoint}/var/lib
else
mkdir -p ${mountpoint}
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/ROOT ${device}${rootpartitionnummer} ${mountpoint}
mkdir -p ${mountpoint}/home
mkdir -p ${mountpoint}/opt
mkdir -p ${mountpoint}/var/cache/pacman/pkg
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/home ${device}${rootpartitionnummer} ${mountpoint}/home
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/opt ${device}${rootpartitionnummer} ${mountpoint}/opt
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current/var/cache/pacman/pkg ${device}${rootpartitionnummer} ${mountpoint}/var/cache/pacman/pkg
# custom-mounts
for wort in ${mountsnaps}
do
mkdir -p ${mountpoint}${wort}
mount -o defaults,noatime,nodiratime,space_cache,discard,ssd,compress=lzo,subvol=__current${wort} ${device}${rootpartitionnummer} ${mountpoint}${wort}
done
mkdir -p ${mountpoint}/var/lib
mount --bind /mnt/btrfs-root/__current/ROOT/var/lib ${mountpoint}/var/lib
fi
# boot mount
mkdir -p ${mountpoint}/boot
mount -t vfat ${device}${efipartitionnummer} ${mountpoint}/boot
fi
}
function subvolume() {
# Mount
btrfsmount 1
# Create
mkdir -p /mnt/btrfs-root/__snapshot
mkdir -p /mnt/btrfs-root/__current
btrfs subvolume create /mnt/btrfs-root/__current/ROOT
btrfs subvolume create /mnt/btrfs-root/__current/home
btrfs subvolume create /mnt/btrfs-root/__current/opt
mkdir -p /mnt/btrfs-root/__current/var/cache/pacman
btrfs subvolume create /mnt/btrfs-root/__current/var/cache/pacman/pkg/
# custom-mounts
for wort in ${mountsnaps}
do
mkdir -p /mnt/btrfs-root/__current${wort%/*}
btrfs subvolume create /mnt/btrfs-root/__current${wort}
done
btrfs subvolume list -p /mnt/btrfs-root
# Mount
btrfsmount 2
}
function update() {
#statements
local if="${1}"
local of="${2}"
local execute="${3}"
local parameters="${4}"
if [ -f "${of}" ]
then
rm ${of}
else
echo "${of} noch nicht vorhanden!"
fi
/usr/bin/curl -v -C - -f ${if} > ${of}
chmod 755 ${of}
${of} ${execute} ${parameters}
}
function systemdboot() {
tobootdeviceuuid=$(blkid -s PARTUUID -o value ${device}${rootpartitionnummer})
swappartitionpart=$(blkid -s PARTUUID -o value ${device}${swappartitionnummer})
# zurücksetzen der parameter
parameter=""
if [ "${swap}" != "n" ]; then
parameter="${parameter}resume=PARTUUID=${swappartitionpart} "
fi
if [ "${verschluesselung}" == "y" ]; then
tobootdevice=${deviceluks}
parameter="${parameter}cryptdevice=PARTUUID=${tobootdeviceuuid}:luks0 "
if [ "${usbkey}" == "y" ]; then
parameter="${parameter}cryptkey=UUID=${usbkeyuuid}:${usbkeydateisystem}:/archkey "
fi
else
tobootdevice="PARTUUID=${tobootdeviceuuid}"
fi
if [ "${dateisystem}" == "btrfs" ]; then
parameter="${parameter}rootflags=subvol=__current/ROOT "
fi
#rootsub=$(btrfs subvolume list /mnt | awk 'NR<0 && NR>2 {print $2}')
mkdir -p ${mountpoint}/boot/EFI/systemd/
mkdir -p ${mountpoint}/boot/EFI/BOOT/
cp ${mountpoint}/usr/lib/systemd/boot/efi/systemd-bootx64.efi ${mountpoint}/boot/EFI/systemd/systemd-bootx64.efi
cp ${mountpoint}/usr/lib/systemd/boot/efi/systemd-bootx64.efi ${mountpoint}/boot/EFI/BOOT/BOOTX64.EFI
mkdir -p ${mountpoint}/boot/loader/entries/
echo "title "${repo}"" > ${mountpoint}/boot/loader/entries/arch-uefi.conf
echo "linux /vmlinuz-linux" >> ${mountpoint}/boot/loader/entries/arch-uefi.conf
echo "initrd /intel-ucode.img" >> ${mountpoint}/boot/loader/entries/arch-uefi.conf
echo "initrd /initramfs-linux.img" >> ${mountpoint}/boot/loader/entries/arch-uefi.conf
echo "options root=${tobootdevice} rw ${parameter}nvidia-drm.modeset=1 quiet splash" >> ${mountpoint}/boot/loader/entries/arch-uefi.conf
echo "title "${repo}"" > ${mountpoint}/boot/loader/entries/arch-uefi-fallback.conf
echo "linux /vmlinuz-linux" >> ${mountpoint}/boot/loader/entries/arch-uefi-fallback.conf
echo "initrd /intel-ucode.img" >> ${mountpoint}/boot/loader/entries/arch-uefi-fallback.conf
echo "initrd /initramfs-linux-fallback.img" >> ${mountpoint}/boot/loader/entries/arch-uefi-fallback.conf
echo "options root=${tobootdevice} rw ${parameter}nvidia-drm.modeset=1 quiet splash" >> ${mountpoint}/boot/loader/entries/arch-uefi-fallback.conf
echo "default arch-uefi" > ${mountpoint}/boot/loader/loader.conf
echo "timeout 1" >> ${mountpoint}/boot/loader/loader.conf
if [ "${booteintraege}" != "n" ]; then
echo "Additional boot entries are created !!!"
arch-chroot ${mountpoint} efibootmgr -c -d ${device} -p 1 -l /EFI/systemd/systemd-bootx64.efi -L "Linux Boot Manager"
arch-chroot ${mountpoint} efibootmgr -c -d ${device} -p 1 -l \vmlinuz-linux -L "Arch Linux efistub" -u "initrd=/initramfs-linux.img root=${tobootdevice} rw ${parameter}nvidia-drm.modeset=1 quiet splash"
# überschreibt die efistub deswegen entfernt
#arch-chroot ${mountpoint} efibootmgr -c -d ${device} -p 1 -l \vmlinuz-linux -L "Arch Linux fallback efistub" -u "initrd=/initramfs-linux-fallback.img root=${tobootdevice} rw ${parameter}nvidia-drm.modeset=1 quiet splash"
#arch-chroot ${mountpoint} bootctl install
fi
}
function abfrage() {
# Lade Deutsches Tastaturlayout
loadkeys de
read -p "What's your name?: " name
[[ -z "${name}" ]] && name=arch-linux
# Partionierung
# UEFI oder Legacy-BIOS
echo ""
echo "UEFI = Unified Extensible Firmware Interface"
echo "Recommended for newer PCs"
echo "IMPORTANT FOR THIS MUST BE SELECTED IN THE BOAT MENU THE UEFI USB STICK OTHERWISE CAN NOT BE CREATED A UEFI BOAT ENTRY !!!"
echo ""
echo "BIOS = basic input/output system"
echo "Recommended for old PCs and portable USB sticks "
echo ""
echo "Please write down the entries: D !!!"
echo "For each yes you have to make a y and for every no an n, unless it is interpreted differently!!!"
echo ""
if mount | grep efi > /dev/null; then
echo "System supports UEFI"
read -p "How would you like to have your hard drive partitioned?: [UEFI/bios] " Partition
[[ -z "${Partition}" ]] && Partition=uefi
else
echo "System supports not UEFI"
read -p "How would you like to have your hard drive partitioned?: [uefi/BIOS] " Partition
[[ -z "${Partition}" ]] && Partition=bios
fi
if [ "${Partition}" == "uefi" ]
then
read -p "Should be booted with systemd or with grub? [systemd/GRUB] : " boot
if [ "${boot}" == "systemd" ]; then
read -p "Should additional boot entries be created? [Y/n] : " booteintraege
fi
fi
[[ -z "${boot}" ]] && boot=grub
fdisk -l
read -p "Specify a hard disk: /dev/sda " device
[[ -z "${device}" ]] && device=/dev/sda
if [ "${device}" == "/dev/nvme0n1" ]; then
m2ssddevice=y
fi
#read -p "Which password should the root receive ?: root " pass
#[[ -z "${pass}" ]] && pass=root
read -p "Which file system should be used? [BTRFS/ext4] " dateisystem
[[ -z "${dateisystem}" ]] && dateisystem=btrfs
if [ "${dateisystem}" == "btrfs" ]; then
read -p "Should a raid be made ?: [raid0/raid1/raid10/n] " raid
[[ -z "${raid}" ]] && raid=n
if [ "${raid}" == "n" ]; then
echo "No raid is generated!"
else
fdisk -l
read -p "Please enter the disks in a row to be connected to a raid !!!: " device1
fi
echo "Standard snapshots / /home /opt /var/cache/pacman/pkg"
echo "The directories may not overlap otherwise there may be problems with the unmount !!!"
read -p "Should more snapshots be created ?: " mountsnaps
fi
read -p "Do you want to create a swap partition? : [Y/n] " swap
read -p "Do you want to create a swapfile? : [y/N] " swapfile
#echo "This attitude can be seen with: "
#echo "systemctl enable openvpn-client@client.service activate and with"
#echo "systemctl disable openvpn-client@client.service deactivate"
#echo "The bandwidth is thereby reduced but the security significantly increased"
#read -p "Should the connection with a VPN be encrypted? : [Y/n] " openvpn
if [ "${update}" != "n" ]; then
echo "WARNING the system is not encrypted !!!"
echo "WARNING The system will not start without the USB stick !!!"
read -p "Should a USB stick be installed as the key for the system? : [y/N] " usbsecret
if [ "${usbsecret}" == "y" ]; then
read -p "Which USB stick should be selected for the USB-secret key ?: /dev/sdb1 " usbsecretdevice
[[ -z "${usbsecretdevice}" ]] && device=/dev/sdb1
usbsecretdeviceuuid=$(blkid -s PARTUUID -o value ${usbsecretdevice})
[[ -z "${usbsecretdeviceuuid}" ]] && mkfs.ext4 ${usbsecretdevice}
fi
fi
if [ "${raid}" == "n" ]; then
read -p "Should the hard disk be encrypted? : [y/N] " verschluesselung
if [ "${verschluesselung}" == "y" ]; then
modprobe dm-crypt
read -p "Should an additional USB stick be created for decryption? : [y/N] " usbkey
if [ "${usbkey}" == "y" ]; then
read -p "Which USB stick should be selected ?: /dev/sdb1 " usbkeydevice
[[ -z "${usbkeydevice}" ]] && usbkeydevice=/dev/sdb1
usbkeydateisystem=$(blkid -s TYPE -o value ${usbkeydevice})
usbkeyuuid=$(blkid -s UUID -o value ${usbkeydevice})
fi
fi
fi
# berechnungen
if [ "${update}" != "n" ]; then
read -p "Should an offline installation be carried out? : [Y/n] " offline
if [ "${offline}" != "n" ]
then
install="offline"
else
install="online"
fi
else
install="offline"
fi
if [ "${offline}" != "n" ]; then
read -p "Do you want to activate the VNC protocol? : [y/N] " x11vnc
echo "This password is only valid for the current session !!!"
if [ "${x11vnc}" == "y" ]; then
x11vnc -storepasswd /etc/x11vnc.pass
systemctl restart x11vnc.service
fi
fi
# Ausgaben
# Dateisystem
if [ "${dateisystem}" == "btrfs" ]; then
mountpoint="/mnt/btrfs-current"
elif [ "${dateisystem}" == "ext4" ]; then
mountpoint="/mnt"
fi
#
echo "Surname: ${name}"
echo "partition type: ${Partition}"
echo "Bootloader: ${boot}"
echo "Drive: ${device}"
if [ "${raid}" != "n" ]; then
echo "Raid: ${raid}"
echo "Hard Drives: ${device1}"
fi
echo "File system: ${dateisystem}"
#echo "System-Partition ${speicher}"
#if [ "${swap}" != "n" ]; then
# echo "Swap-partition ${swapspeicher}"
#fi
#if [ "${swapfile}" == "y" ]; then
# echo "Swapfile ${swapfilespeicher}"
#fi
#echo "Rootpasswort: ${pass}"
echo "Architektur: $(uname -m)"
echo "Installation: ${install}"
if [ "${dateisystem}" == "btrfs" ]; then
for wort in ${mountsnaps}
do
echo "Snapshot ${wort} wird erstellt!!!"
done
fi
#if [ "${openvpn}" != "n" ]; then
# echo "VPN-Verschlüsselung: aktiv"
#fi
if [ "${usbsecret}" == "y" ]; then
echo "USB-secret: aktiv"
echo "USB-UIDD: ${usbsecretdeviceuuid}"
echo "USB-Label: ${usbsecretdevice}"
fi
if [ "${verschluesselung}" == "y" ]; then
echo "Fesptplatte with Luks 512KB encryption: aktiv"
if [ "${usbkey}" == "y" ]; then
echo "${usbkeydevice} is used as key for decrypting: "
echo "File system: ${usbkeydateisystem}"
fi
fi
# Partitionierung
if [ "${m2ssddevice}" == "y" ]; then
m2ssd=p
fi
if [ "${dateisystem}" == "btrfs" ]; then
if [ "${Partition}" == "uefi" ]; then
bootpartitionnummer=${m2ssd}1
efipartitionnummer=${m2ssd}2
if [ "${swap}" != "n" ]; then
swappartitionnummer=${m2ssd}3
rootpartitionnummer=${m2ssd}4
else
rootpartitionnummer=${m2ssd}3
fi
elif [ "${Partition}" == "bios" ]; then
bootpartitionnummer=${m2ssd}1
efipartitionnummer=${m2ssd}2
if [ "${swap}" != "n" ]; then
swappartitionnummer=${m2ssd}3
rootpartitionnummer=${m2ssd}4
else
rootpartitionnummer=${m2ssd}3
fi
fi
elif [ "${dateisystem}" == "ext4" ]; then
if [ "${Partition}" == "uefi" ]; then
bootpartitionnummer=${m2ssd}1
efipartitionnummer=${m2ssd}2
if [ "${swap}" != "n" ]; then
swappartitionnummer=${m2ssd}3
rootpartitionnummer=${m2ssd}4
else
rootpartitionnummer=${m2ssd}3
fi
elif [ "${Partition}" == "bios" ]; then
bootpartitionnummer=${m2ssd}1
efipartitionnummer=${m2ssd}2
if [ "${swap}" != "n" ]; then
swappartitionnummer=${m2ssd}3
rootpartitionnummer=${m2ssd}4
else
rootpartitionnummer=${m2ssd}3
fi
fi
fi
echo "Boot-Partition = ${device}${bootpartitionnummer}"
echo "EFI-Partition = ${device}${efipartitionnummer}"
if [ "${swap}" != "n" ]; then
echo "Swap-Partition = ${device}${swappartitionnummer}"
fi
echo "ROOT-Partition = ${device}${rootpartitionnummer}"
#
read -p "Are all the details correct ?: [y/N] " sicherheitsabfrage
if [ "$sicherheitsabfrage" != "y" ]
then
echo "ABGEBROCHEN"
exit 1
fi
# if [ "${update}" != "n" ]; then
# echo "Only needed for pure arch-linux systems !!!"
# read -p "Are you still installing important packages for the installation? [y/N] " packete
# if [ "${packete}" == "y" ]; then
# pacman -Syu base base-devel syslinux efibootmgr efitools grub os-prober btrfs-progs \
# dosfstools arch-install-scripts xorriso cdrtools squashfs-tools wget dosfstools btrfs-progs \
# gdisk dialog bash-completion git iw wireless_tools wpa_supplicant openvpn
# fi
# fi
echo "Operating system is installed !!!"
sleep 5
}
if [ "${1}" != "n" ]
then
if wget -qO- ipv4.icanhazip.com 1>/dev/null 2>&1; then
read -p "Should I look at the internet for a new install script and then run it ?: [Y/n] " update
if [ "${update}" == "debug" ]
then
echo "Skip the download a new script !!!"
else
if [ "${update}" != "n" ]
then
if [ -f /usr/bin/git ]; then
echo "Git is installed"
else
echo "Git is not installed"
pacman -Syu git --needed --noconfirm
fi
gitclone
/opt/${repo}/arch-install n ${version}
exit 0
fi
fi
else
echo "No internet connection detected!"
update=n
fi
fi
if [ "${update}" != "n" ]; then
echo "Online-Modus activated!"
#vpntunnel
fi
# debug = Installation ueberspringen zu arch-graphical-install und DEBEUG-MODUS
abfrage
secureumount
if [ "${name}" == "debug" ]
then
echo "DEBEUG-MODUS"
echo "If no more commands are required, simply press enter"
echo "Which command should be executed? "
befehl=blablabla
while [ "$befehl" != "" ]
do
read -p "" befehl
$befehl
done
fi
#
echo "A purge stops the chance of installing on the system."
echo "It may take a while!"
dd if=/dev/zero of=${device} bs=64M count=10 status=progress
#
if [ "${Partition}" == "uefi" ]
then
echo "Partitions with UEFI"
if [ "${swap}" != "n" ]; then
echo "Create additional swap partition"
partionierenmitswap
else
partionierenohneswap
fi
if [ "${name}" == "noinstall" ]; then
echo "installation"
installation
fi
if [ "${version}" == "libre" ]; then
arch-chroot ${mountpoint} mkinitcpio -p linux-libre
else
arch-chroot ${mountpoint} mkinitcpio -p linux
fi
echo ""
if [ "${boot}" == "grub" ]
then
arch-chroot ${mountpoint} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id="${repo}" --recheck
arch-chroot ${mountpoint} grub-mkconfig -o /boot/grub/grub.cfg
else
systemdboot
fi
#removeinstaller
echo "Finished"
elif [ "${Partition}" == "bios" ]; then
echo "Partitions with MBR"
if [ "${swap}" != "n" ]; then
echo "Create additional swap partition"
partionierenmitswap
else
partionierenohneswap
fi
if [ "${name}" == "noinstall" ]; then
echo "installation"
installation
fi
if [ "${version}" == "libre" ]; then
arch-chroot ${mountpoint} mkinitcpio -p linux-libre
else
arch-chroot ${mountpoint} mkinitcpio -p linux
fi
arch-chroot ${mountpoint} grub-install --target=i386-pc --recheck ${device}
arch-chroot ${mountpoint} grub-mkconfig -o /boot/grub/grub.cfg
#removeinstaller
echo "Finished"
else
echo "Entry Invalid"
exit 1
fi
if [ "${x11vnc}" == "y" ]; then
echo "Please enter a password for the VNC protocol!"
arch-chroot ${mountpoint} x11vnc -storepasswd /etc/x11vnc.pass
arch-chroot ${mountpoint} systemctl enable x11vnc.service
else
arch-chroot ${mountpoint} systemctl disable x11vnc.service
fi
if [ "${update}" != "n" ] && [ "${offline}" == "n" ] || [ "${installationfehler}" == "online" ]; then
read -p "Should the extended installation be carried out? [Y/n] " graphical
if [ "$graphical" != "n" ]
then
cp /opt/${repo}/arch-graphical-install-auto ${mountpoint}/root/arch-graphical-install-auto
if [ "${version}" == "libre" ]; then
arch-chroot ${mountpoint} /root/arch-graphical-install-auto libre
else
arch-chroot ${mountpoint} /root/arch-graphical-install-auto voll
fi
fi
fi
echo "df!!!"
df -h
if [ "${dateisystem}" == "btrfs" ]; then
btrfs filesystem df ${mountpoint}
fi
echo "umount!!!"
sleep 5
secureumount
echo ""
echo "Fertig!!!"
read -p "allation completed successfully. Do you want to RESTART the PC ?: [Y/n] " sicherheitsabfrage
if [ "$sicherheitsabfrage" != "n" ]
then
echo "restart now"
reboot
fi
exit 0