Swap File Size improvements, style

This commit is contained in:
Price Hiller 2022-01-18 12:32:26 -06:00
parent 9e9e73400b
commit 895acd1694

View File

@ -8,7 +8,6 @@ confirmation() {
while :; do while :; do
read -p "${message}" -n 1 -r choice read -p "${message}" -n 1 -r choice
echo $choice
case "${choice}" in case "${choice}" in
y | Y) y | Y)
return 0 return 0
@ -150,7 +149,7 @@ get_available_disks() {
ret_val="${ret_val} ${disk}" ret_val="${ret_val} ${disk}"
done done
echo "${ret_val}" printf "%s\n" "${ret_val}"
} }
list_disks() { list_disks() {
@ -161,19 +160,13 @@ list_disks() {
count=0 count=0
log "info" "Available disks" log "info" "Available disks"
for disk in ${disks}; do for disk in ${disks}; do
echo " "${count}\.\) "${disk}" printf "%s\n" "${count}.)" "${disk}"
count=$(( count + 1 )) count=$(( count + 1 ))
done done
} }
get_num_of_elems() { get_num_of_elems() {
local count printf "%s" "${#count}"
count=0
for elem in ${1}; do
count=$(( count + 1 ))
done
echo "${count}"
} }
install() { install() {
@ -201,9 +194,9 @@ install() {
valid_disk_selected=1 valid_disk_selected=1
while [[ "${valid_disk_selected}" != 0 ]]; do while [[ "${valid_disk_selected}" != 0 ]]; do
list_disks "${available_disks}" list_disks "${available_disks}"
read -p "Select a disk number to install arch linux to: " disk_selected read -rp "Select a disk number to install arch linux to: " disk_selected
if ${disk_selected} -eq ${disk_selected} 2> /dev/null; then if "${disk_selected}" -eq "${disk_selected}" 2> /dev/null; then
: :
else else
log "error" "A number was not passed" log "error" "A number was not passed"
@ -272,11 +265,22 @@ install() {
mount /dev/mapper/cryptroot /mnt mount /dev/mapper/cryptroot /mnt
mkdir /mnt/boot mkdir /mnt/boot
mount "${install_path}p1" /mnt/boot mount "${install_path}p1" /mnt/boot
local mem_amount local mem_amount_kb
mem_amount="$(grep MemTotal /proc/meminfo | tr -s " " | cut -d " " -f2)" mem_amount_kb="$(grep MemTotal /proc/meminfo | tr -s " " | cut -d " " -f2)"
mem_amount=$(( mem_amount * 3/2 / 1000 )) mem_amount_mb=$(( mem_amount_kb / 1024 ))
log "info" "Creating swap file with memory amount: $(important "${mem_amount}") mebibytes"
dd if=/dev/zero of=/mnt/swapfile bs=1M count="${mem_amount}" status=progress # Space to swap is taken from fedora guidelines:
# https://docs.fedoraproject.org/en-US/Fedora/22/html/Installation_Guide/sect-installation-gui-manual-partitioning-recommended.html
if (( mem_amount_mb < 2048 )); then
mem_amount_kb=$(( mem_amount_kb * 3 / 1024 ))
elif (( mem_amount_mb < 8192 )); then
mem_amount_kb=$(( mem_amount_kb * 2 / 1024 ))
elif (( mem_amount_mb < 65536 )); then
mem_amount_kb=$((mem_amount_kb * 3/2 / 1024 ))
fi
log "info" "Creating swap file with memory amount: $(important "${mem_amount_kb}") mebibytes"
dd if=/dev/zero of=/mnt/swapfile bs=1M count="${mem_amount_kb}" status=progress
chmod 600 /mnt/swapfile chmod 600 /mnt/swapfile
mkswap /mnt/swapfile mkswap /mnt/swapfile
swapon /mnt/swapfile swapon /mnt/swapfile
@ -322,12 +326,12 @@ __EOF__
systemctl enable NetworkManager systemctl enable NetworkManager
__END_CHROOT_CMDS__ __END_CHROOT_CMDS__
log "info" "Next steps: update localities if incorrect, add your user, update the root password" log "info" "Next steps: update localities if incorrect, add your user, update the root password"
log "info" "Notice default login is the following, username: $(important "root") password: $(important "toor") log "info" "Notice default login is the following, username: $(important "root") password: $(important "toor")"
} }
main() { main() {
install install
} }
main "$@" main "${@}"