From 6a6fcf2f4adbcd95d60a6f3214006263f4fc852b Mon Sep 17 00:00:00 2001 From: Brian Zalewski Date: Tue, 6 Dec 2022 10:26:47 +0000 Subject: [PATCH] Update .local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_10-system-tweaks, .local/share/chezmoi/home/.chezmoi.yaml.tmpl, .local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_configure-swap --- .local/share/chezmoi/home/.chezmoi.yaml.tmpl | 1 + .../run_onchange_before_10-system-tweaks | 22 ++++++++++++++++ .../linux/run_onchange_before_configure-swap | 26 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 .local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_10-system-tweaks create mode 100644 .local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_configure-swap diff --git a/.local/share/chezmoi/home/.chezmoi.yaml.tmpl b/.local/share/chezmoi/home/.chezmoi.yaml.tmpl index 79499f11..bccc431a 100644 --- a/.local/share/chezmoi/home/.chezmoi.yaml.tmpl +++ b/.local/share/chezmoi/home/.chezmoi.yaml.tmpl @@ -180,6 +180,7 @@ data: id: "{{ get .chezmoi.osRelease "id" | default .chezmoi.os }}" home: "{{ .chezmoi.homeDir }}" homeParentFolder: "{{ if eq .chezmoi.os "linux" }}/home{{ else if eq .chezmoi.os "darwin" }}/Users{{ else }}C:\Users{{ end }}" + hostname: "Betelgeuse" qubes: {{ ne (stat (joinPath "usr" "bin" "qubes-session")) false }} softwareGroup: "{{ $softwareGroup }}" type: "{{ $chassisType }}" diff --git a/.local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_10-system-tweaks b/.local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_10-system-tweaks new file mode 100644 index 00000000..232cb41e --- /dev/null +++ b/.local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_10-system-tweaks @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +### Set hostname (if redefined) +if command -v hostnamectl > /dev/null; then + # Betelgeuse is the default hostname so only change when it is different + if [ '{{ .host.hostname }}' != 'Betelgeuse' ]; then + logg info "Setting hostname to {{ .host.hostname }}" + sudo hostnamectl set-hostname {{ .host.hostname }} + fi +fi + +### Set timezone +if command -v timedatectl > /dev/null; then + logg info 'Setting timezone to `{{ .user.timezone }}`' + sudo timedatectl set-timezone {{ .user.timezone }} +fi + +### Modify vm.max_map_count +if command -v sysctl > /dev/null; then + logg info 'Increasing vm.max_map_count size to 262144' + sudo sysctl -w vm.max_map_count=262144 +fi diff --git a/.local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_configure-swap b/.local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_configure-swap new file mode 100644 index 00000000..59013cd6 --- /dev/null +++ b/.local/share/chezmoi/home/.chezmoiscripts/linux/run_onchange_before_configure-swap @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +# TODO - make equivalent to https://gitlab.com/megabyte-labs/gas-station/-/blob/master/roles/system/common/tasks/linux/swap.yml + +MEMORY_IN_KB="$(grep MemTotal /proc/meminfo | sed 's/.* \(\d+\) kB/\1/')" +MEMORY_IN_GB="$((MEMORY_IN_KB / 1024 / 1024))" + +if [ "$MEMORY_IN_GB" -gt 64 ]; then + SWAP_SPACE="$((MEMORY_IN_GB / 10))" +elif [ "$MEMORY_IN_GB" -gt 32 ]; then + SWAP_SPACE="$((MEMORY_IN_GB / 8))" +elif [ "$MEMORY_IN_GB" -gt 8 ]; then + SWAP_SPACE="$((MEMORY_IN_GB / 4))" +else + SWAP_SPACE="$MEMORY_IN_GB" +fi + +logg info "Creating a $SWAP_SPACE GB /swapfile" +sudo fallocate -l "$SWAP_SPACE" /swapfile +sudo chmod 600 /swapfile +sudo mkswap /swapfile +sudo swapon /swapfile +if cat /etc/fstab | grep "/swapfile"; then + sudo sed -i '/\/swapfile/\/swapfile none swap sw 0 0/' /etc/fstab +else + echo "/swapfile none swap sw 0 0" | sudo tee -a /etc/fstab +fi