added some system setup scripts

This commit is contained in:
Jakub 2024-07-23 01:59:12 -04:00
parent 0855df7610
commit c263cbc655
3 changed files with 45 additions and 0 deletions

5
setup-scripts/sys/grub.sh Executable file
View File

@ -0,0 +1,5 @@
#/bin/sh
#TODO source config
grub-install
[ "$arch_boot_verbose" = 'true' ] && sed -i '6s/ quiet//' /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg

23
setup-scripts/sys/hibernate.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/sh
# requires swapfile at /swap be setup
# ensure no dupes by removing any old hooks
sed -Ei 's/resume//' /etc/mkinitcpio.conf
# setup hooks
sed -Ei 's/filesystems/filesystems resume/' /etc/mkinitcpio.conf
echo "Enabled hooks - note /etc/mkinicpio.conf's comments are messed up due to this"
mkinitcpio -p linux
# ensure no dupes by removing any old kernel params
sed -Ei 's/resume=UUID=.{36} *//' /etc/default/grub
sed -Ei 's/resume_offset=[[:digit:]]* *//' /etc/default/grub
# write patamaters
uuid="$(findmnt -no UUID -T /swap)"
offset="$(filefrag -v /swap | awk '$1=="0:" {print substr($4, 1, length($4)-2)}')"
echo "Setting kernel paramaters"
sed -Ei 's/^GRUB_CMDLINE_LINUX="/GRUB_CMDLINE_LINUX="resume=UUID='"$uuid"' resume_offset='"$offset"'/' /etc/default/grub
grub-mkconfig -o /boot/grub/grub.cfg
echo "Hibernation setup - changes will take affect after reboot."

17
setup-scripts/sys/swap-file.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/sh
[ -e /swap ] && {
# for saftey
swapoff /swap
rm /swap
sed -Ei '/\/swap\s*/d' /etc/fstab
}
touch /swap
size="$(( "$(free -g | awk '/Mem:/ {print $2}')" + 1 ))k"
dd if=/dev/zero of=/swap bs=1M count="$size" status=progress
chmod 0600 /swap
mkswap -U clear /swap
swapon /swap
echo '' >> /etc/fstab
echo '/swap none swap defaults 0 0' >> /etc/fstab
echo "Created $(echo $size | tr -d 'k') Gb swap file"