mirror of
https://git.myvelabs.com/lab/archlinux.git
synced 2025-12-17 22:56:25 +00:00
First commit
This commit is contained in:
commit
36ad41a2fc
18 changed files with 10005 additions and 0 deletions
728
functions/chroot
Executable file
728
functions/chroot
Executable file
|
|
@ -0,0 +1,728 @@
|
|||
#!/usr/bin/env bash
|
||||
revision=0.1a
|
||||
set -a
|
||||
set -E
|
||||
echo
|
||||
|
||||
# Environment variables
|
||||
tee -a /etc/environment >/dev/null <<- environment
|
||||
EDITOR=vim
|
||||
SUDO_EDITOR=vim
|
||||
environment
|
||||
|
||||
# Global bashrc
|
||||
tee -a /etc/skel/.bashrc >/dev/null <<- 'bashglobal'
|
||||
|
||||
# Source bash functions
|
||||
if [ -d ~/.local/functions ]
|
||||
then
|
||||
for file in $(find ~/.local/functions -type f)
|
||||
do
|
||||
. ${file}
|
||||
done
|
||||
fi
|
||||
|
||||
# Add local functions folder to path
|
||||
export PATH=${PATH}:${HOME}/.local/bin:/zfs/bin:/opt/local/bin
|
||||
export SUDO_PROMPT=$'\a'"$(tput rev)[sudo] password for %p:$(tput sgr0)"' '
|
||||
|
||||
# Colored prompts
|
||||
alias diff='diff --color=auto'
|
||||
alias ip='ip -color=auto'
|
||||
export LESS='-R --use-color -Dd+r$Du+b$'
|
||||
|
||||
# Adjust terminal upon window resize
|
||||
shopt -s checkwinsize
|
||||
|
||||
# Auto cd into directory
|
||||
shopt -s autocd
|
||||
|
||||
# Enable tab complete for sudo
|
||||
complete -c -f sudo
|
||||
|
||||
# Ignore duplicate and whitespace history entries
|
||||
export HISTCONTROL=ignoreboth
|
||||
|
||||
#
|
||||
# ~/.bash_aliases
|
||||
#
|
||||
|
||||
# ZFS/btrfs
|
||||
alias zfs='sudo zfs'
|
||||
alias zpool='sudo zpool'
|
||||
alias btrfs='sudo btrfs'
|
||||
|
||||
# Shutdown reboot
|
||||
alias poweroff='sudo poweroff'
|
||||
alias reboot='sudo reboot'
|
||||
|
||||
# Text editors
|
||||
alias v='vim'
|
||||
alias sv='sudo vim'
|
||||
|
||||
# Clear bash history
|
||||
alias clearhistory='rm ${HISTFILE}; history -c -w'
|
||||
|
||||
# Miscellanous pacman
|
||||
alias orphans='sudo pacman -Rcns $(pacman -Qtdq)'
|
||||
alias unlockpacman='sudo rm /var/lib/pacman/db.lck && sudo pacman -Syyu'
|
||||
|
||||
# Rsync
|
||||
alias rsync='rsync -v -h --progress --info=progress2 --partial --append-verify'
|
||||
# --log-file=
|
||||
# --remove-source-files
|
||||
|
||||
#
|
||||
# ~/.bash_functions
|
||||
#
|
||||
|
||||
# Pacman tools
|
||||
function installer
|
||||
{
|
||||
/opt/local/bin/cacheserver
|
||||
sudo pacman -S ${@}
|
||||
echo
|
||||
}
|
||||
|
||||
function uninstall
|
||||
{
|
||||
sudo pacman -Rcns ${@}
|
||||
echo
|
||||
}
|
||||
|
||||
function mirrors
|
||||
{
|
||||
echo
|
||||
sudo reflector --country CA,US --age 24 --latest 20 --protocol https --fastest 25 --sort rate --save /etc/pacman.d/mirrorlist
|
||||
echo
|
||||
cat /etc/pacman.d/mirrorlist
|
||||
echo
|
||||
}
|
||||
|
||||
function syur
|
||||
{
|
||||
/opt/local/bin/syu &&
|
||||
reboot
|
||||
}
|
||||
|
||||
function syup
|
||||
{
|
||||
/opt/local/bin/syu &&
|
||||
poweroff
|
||||
}
|
||||
|
||||
# Update bash
|
||||
function update-bash
|
||||
{
|
||||
vim ~/.bashrc &&
|
||||
source ~/.bashrc
|
||||
}
|
||||
bashglobal
|
||||
|
||||
# Root bashrc
|
||||
rsync -a /etc/skel/.bashrc ~/
|
||||
mkdir -p ~/.local/functions/
|
||||
cat > ~/.local/functions/bashrc <<- 'bashrc'
|
||||
#!/usr/bin/env bash
|
||||
# Root shell color
|
||||
PS1="$(tput setaf 1)[\u@\h \W \$?]\$$(tput sgr0) "
|
||||
|
||||
# Colored prompts
|
||||
alias ll='ls --color=auto -l -a -h'
|
||||
alias egrep='egrep --color=auto'
|
||||
alias fgrep='fgrep --color=auto'
|
||||
|
||||
# Disable history
|
||||
unset HISTFILE
|
||||
rm -f ${HISTFILE}
|
||||
history -c -w
|
||||
bashrc
|
||||
|
||||
# Locale
|
||||
sed '/#en_US.UTF-8 UTF-8/ s/#//' -i /etc/locale.gen
|
||||
locale-gen >/dev/null
|
||||
echo 'LANG=en_US.UTF-8' >>/etc/locale.conf
|
||||
say as heading 'Locale configured'
|
||||
|
||||
# Time zone
|
||||
if ls -l /dev/disk/* | grep -q 'VBOX\|virtio\|QEMU'
|
||||
then
|
||||
ln -s -f $(find /usr/share/zoneinfo/ | shuf -n 1) /etc/localtime
|
||||
else
|
||||
ln -s -f /usr/share/zoneinfo/UTC /etc/localtime
|
||||
fi
|
||||
hwclock --systohc --utc
|
||||
say as heading 'Time zone configured'
|
||||
|
||||
# Hostname
|
||||
echo ${hostname} >/etc/hostname
|
||||
cat >>/etc/hosts <<HOSTS
|
||||
127.0.0.1 localhost
|
||||
127.0.1.1 ${hostname}
|
||||
HOSTS
|
||||
say as heading 'Hostname configured'
|
||||
|
||||
# User and superuser
|
||||
useradd -m -g users -G wheel -s /usr/bin/bash ${username} || die 'User account creation has failed'
|
||||
printf '%s\n' "${userpass}" "${userpass}" | passwd ${username} >/dev/null 2>&1
|
||||
unset userpass userpass2
|
||||
|
||||
# Disable root account
|
||||
passwd -l root >/dev/null 2>&1
|
||||
|
||||
# Sudoers
|
||||
install -m 0440 /dev/stdin /etc/sudoers.d/01-DEFAULTS <<- DEFAULTS
|
||||
Defaults passwd_timeout=0
|
||||
Defaults timestamp_type=global
|
||||
Defaults insults
|
||||
DEFAULTS
|
||||
|
||||
install -m 0440 /dev/stdin /etc/sudoers.d/02-COMMANDS <<- COMMANDS
|
||||
Cmnd_Alias POWER = /usr/bin/poweroff, /usr/bin/reboot
|
||||
Cmnd_Alias ZFS = /usr/bin/zfs, /usr/bin/zpool
|
||||
Cmnd_Alias BTRFS = /usr/bin/btrfs, /usr/bin/timeshift, /usr/bin/timeshift-gtk, /usr/bin/timeshift-launcher
|
||||
Cmnd_Alias QEMU = /usr/bin/virsh, /usr/bin/qemu-system-x86_64, /usr/bin/virt-install
|
||||
Cmnd_Alias FAIL2BAN = /usr/bin/fail2ban-client
|
||||
Cmnd_Alias ARCHISO = /opt/local/bin/mkairgap, /opt/local/bin/mkiso
|
||||
Cmnd_Alias PACMAN = /usr/bin/pacman -Sy
|
||||
Cmnd_Alias IPTABLES = /usr/bin/iptables, /usr/bin/iptables-save
|
||||
Cmnd_Alias MISC = /usr/bin/rsync
|
||||
COMMANDS
|
||||
|
||||
install -m 0440 /dev/stdin /etc/sudoers.d/03-WHEEL <<- WHEEL
|
||||
%wheel ALL=(ALL:ALL) ALL
|
||||
%wheel ALL=(ALL:ALL) NOPASSWD: POWER, ZFS, BTRFS, QEMU, FAIL2BAN, ARCHISO, PACMAN, IPTABLES, MISC
|
||||
WHEEL
|
||||
|
||||
install -m 0440 /dev/stdin /etc/sudoers.d/.zz-NOPASSWD <<- NOPASSWD
|
||||
Defaults:${username} !authenticate
|
||||
NOPASSWD
|
||||
|
||||
case ${filesystem} in
|
||||
zfs)
|
||||
# ZFS setup
|
||||
zpool set cachefile=/etc/zfs/zpool.cache zroot
|
||||
zgenhostid $(hostid)
|
||||
|
||||
# ZFS files
|
||||
touch /zfs/snapshot-syu
|
||||
chown ${username}:users /zfs/snapshot-syu
|
||||
|
||||
# Trim zroot monthly
|
||||
cat >/etc/systemd/system/zfs-trim@.timer <<- 'TRIM'
|
||||
[Unit]
|
||||
Description=Monthly zpool trim on %i
|
||||
|
||||
[Timer]
|
||||
OnCalendar=monthly
|
||||
AccuracySec=1h
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
TRIM
|
||||
cat >/etc/systemd/system/zfs-trim@.service <<- 'TRIM'
|
||||
[Unit]
|
||||
Description=zpool trim on %i
|
||||
Documentation=man:zpool-trim(8)
|
||||
Requires=zfs.target
|
||||
After=zfs.target
|
||||
ConditionACPower=true
|
||||
ConditionPathIsDirectory=/sys/module/zfs
|
||||
|
||||
[Service]
|
||||
Nice=19
|
||||
IOSchedulingClass=idle
|
||||
KillSignal=SIGINT
|
||||
ExecStart=/bin/sh -c '\
|
||||
if /usr/bin/zpool status %i | grep "trimming"; then\
|
||||
exec /usr/bin/zpool wait -t trim %i;\
|
||||
else exec /usr/bin/zpool trim -w %i; fi'
|
||||
ExecStop=-/bin/sh -c '/usr/bin/zpool trim -s %i 2>/dev/null || true'
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
TRIM
|
||||
# Scrub zroot monthly
|
||||
cat >/etc/systemd/system/zfs-scrub@.timer <<- 'SCRUB'
|
||||
[Unit]
|
||||
Description=Monthly zpool scrub on %i
|
||||
|
||||
[Timer]
|
||||
OnCalendar=monthly
|
||||
AccuracySec=1h
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
SCRUB
|
||||
cat >/etc/systemd/system/zfs-scrub@.service <<- 'SCRUB'
|
||||
[Unit]
|
||||
Description=zpool scrub on %i
|
||||
|
||||
[Service]
|
||||
Nice=19
|
||||
IOSchedulingClass=idle
|
||||
KillSignal=SIGINT
|
||||
ExecStart=/usr/bin/zpool scrub %i
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
SCRUB
|
||||
|
||||
# Pre and Post update backup hooks
|
||||
cat >/etc/pacman.d/hooks/00-syu_pre.hook <<- pre
|
||||
[Trigger]
|
||||
Type = Path
|
||||
Operation = Upgrade
|
||||
Operation = Install
|
||||
Operation = Remove
|
||||
Target = usr/lib/modules/*/vmlinuz
|
||||
Target = usr/lib/initcpio/*
|
||||
Target = usr/lib/firmware/*
|
||||
Target = usr/src/*/dkms.conf
|
||||
|
||||
[Action]
|
||||
Description = Creating pre zroot snapshot...
|
||||
When = PreTransaction
|
||||
Exec = /usr/bin/bash -c 'zfs snapshot zroot/ROOT@pre-\$(cat /zfs/snapshot-syu)'
|
||||
AbortOnFail
|
||||
pre
|
||||
cat >/etc/pacman.d/hooks/55-bootbackup_pre.hook <<- pre
|
||||
[Trigger]
|
||||
Operation = Upgrade
|
||||
Operation = Install
|
||||
Operation = Remove
|
||||
Type = Path
|
||||
Target = usr/lib/modules/*/vmlinuz
|
||||
Target = usr/lib/initcpio/*
|
||||
Target = usr/lib/firmware/*
|
||||
Target = usr/src/*/dkms.conf
|
||||
|
||||
[Action]
|
||||
Depends = rsync
|
||||
Description = Backing up pre /boot...
|
||||
When = PreTransaction
|
||||
Exec = /usr/bin/bash -c 'mount /boot; rsync -a --mkpath --delete /boot/ "/.boot/\$(cat /zfs/snapshot-syu)_pre"/'
|
||||
AbortOnFail
|
||||
pre
|
||||
cat >/etc/pacman.d/hooks/95-bootbackup_post.hook <<- post
|
||||
[Trigger]
|
||||
Operation = Upgrade
|
||||
Operation = Install
|
||||
Operation = Remove
|
||||
Type = Path
|
||||
Target = usr/lib/modules/*/vmlinuz
|
||||
Target = usr/lib/initcpio/*
|
||||
Target = usr/lib/firmware/*
|
||||
Target = usr/src/*/dkms.conf
|
||||
|
||||
[Action]
|
||||
Depends = rsync
|
||||
Description = Backing up post /boot...
|
||||
When = PostTransaction
|
||||
Exec = /usr/bin/bash -c 'rsync -a --mkpath --delete /boot/ "/.boot/\$(cat /zfs/snapshot-syu)_post"/'
|
||||
post
|
||||
cat >/etc/pacman.d/hooks/zz-syu_post.hook <<- post
|
||||
[Trigger]
|
||||
Type = Path
|
||||
Operation = Upgrade
|
||||
Operation = Install
|
||||
Operation = Remove
|
||||
Target = usr/lib/modules/*/vmlinuz
|
||||
Target = usr/lib/initcpio/*
|
||||
Target = usr/lib/firmware/*
|
||||
Target = usr/src/*/dkms.conf
|
||||
|
||||
[Action]
|
||||
Description = Creating post zroot snapshot...
|
||||
When = PostTransaction
|
||||
Exec = /usr/bin/bash -c 'zfs snapshot zroot/ROOT@post-\$(cat /zfs/snapshot-syu)'
|
||||
post
|
||||
|
||||
# Custom pacman wrapper
|
||||
install /dev/stdin /opt/local/bin/syu <<- syu
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
mirrorlist=
|
||||
|
||||
# Enable or disable pacman cache server
|
||||
/opt/local/bin/cacheserver
|
||||
|
||||
# Fetch latest mirrors
|
||||
sudo curl --fail --silent \${mirrorlist} -o /etc/pacman.d/mirrorlist
|
||||
|
||||
# Record current time
|
||||
echo \$(date "+%Y-%m-%d-%H:%M:%S") >/zfs/snapshot-syu
|
||||
|
||||
# Check for new packages and continue if found
|
||||
newpkg+=(\$(checkupdates --nocolor | awk '{print \$1}'))
|
||||
if [ "\${newpkg}" ]
|
||||
then
|
||||
# Sync pacman dbs
|
||||
sudo pacman --ask 4 -Sy >/dev/null
|
||||
|
||||
# Check zfs-linux kernel dependency
|
||||
zfslinux=\$(pacman -Si zfs-${linux_kernel} | grep "Depends On" | sed "s|.*${linux_kernel}=||")
|
||||
linux=\$(pacman -Si ${linux_kernel} | grep "Version" | awk '{print \$3}')
|
||||
if [ \${zfslinux} != \${linux} ]
|
||||
then
|
||||
archzfs="--ignore zfs-utils,zfs-${linux_kernel},${linux_kernel}"
|
||||
fi
|
||||
|
||||
# Update archlinux-keyring first
|
||||
if [[ \${newpkg[@]} =~ "archlinux-keyring" ]]
|
||||
then
|
||||
sudo pacman --ask 4 -S archlinux-keyring
|
||||
echo
|
||||
fi
|
||||
|
||||
# Perform update if dependencies are satisfied
|
||||
if sudo pacman --ask 4 -Syu \${archzfs} --needed
|
||||
then
|
||||
echo
|
||||
sudo pacdiff
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
syu
|
||||
;;
|
||||
*)
|
||||
case ${filesystem} in
|
||||
btrfs)
|
||||
# Pre and post update backup hooks
|
||||
cat >/etc/pacman.d/hooks/00-syu_pre.hook <<- pre
|
||||
[Trigger]
|
||||
Type = Path
|
||||
Operation = Upgrade
|
||||
Operation = Install
|
||||
Operation = Remove
|
||||
Target = usr/lib/modules/*/vmlinuz
|
||||
Target = usr/lib/initcpio/*
|
||||
Target = usr/lib/firmware/*
|
||||
Target = usr/src/*/dkms.conf
|
||||
|
||||
[Action]
|
||||
Depends = timeshift
|
||||
Description = Creating pre root snapshot...
|
||||
When = PreTransaction
|
||||
Exec = /usr/bin/bash -c 'timeshift --create --comments "pre_\$(date "+%Y-%m-%d-%H:%M:%S")" >/dev/null'
|
||||
AbortOnFail
|
||||
pre
|
||||
cat >/etc/pacman.d/hooks/55-bootbackup_pre.hook <<- pre
|
||||
[Trigger]
|
||||
Operation = Upgrade
|
||||
Operation = Install
|
||||
Operation = Remove
|
||||
Type = Path
|
||||
Target = usr/lib/modules/*/vmlinuz
|
||||
Target = usr/lib/initcpio/*
|
||||
Target = usr/lib/firmware/*
|
||||
Target = usr/src/*/dkms.conf
|
||||
|
||||
[Action]
|
||||
Depends = rsync
|
||||
Description = Backing up pre /boot...
|
||||
When = PreTransaction
|
||||
Exec = /usr/bin/bash -c 'rsync -a --mkpath --delete --exclude 'header.img' /boot/ "/.boot/\$(date "+%Y-%m-%d-%H:%M:%S")_pre"/'
|
||||
AbortOnFail
|
||||
pre
|
||||
cat >/etc/pacman.d/hooks/95-bootbackup_post.hook <<- post
|
||||
[Trigger]
|
||||
Operation = Upgrade
|
||||
Operation = Install
|
||||
Operation = Remove
|
||||
Type = Path
|
||||
Target = usr/lib/modules/*/vmlinuz
|
||||
Target = usr/lib/initcpio/*
|
||||
Target = usr/lib/firmware/*
|
||||
Target = usr/src/*/dkms.conf
|
||||
|
||||
[Action]
|
||||
Depends = rsync
|
||||
Description = Backing up post /boot...
|
||||
When = PostTransaction
|
||||
Exec = /usr/bin/bash -c 'rsync -a --mkpath --delete --exclude 'header.img' /boot/ "/.boot/\$(date "+%Y-%m-%d-%H:%M:%S")_post"/'
|
||||
post
|
||||
cat >/etc/pacman.d/hooks/zz-syu_post.hook <<- post
|
||||
[Trigger]
|
||||
Type = Path
|
||||
Operation = Upgrade
|
||||
Operation = Install
|
||||
Operation = Remove
|
||||
Target = usr/lib/modules/*/vmlinuz
|
||||
Target = usr/lib/initcpio/*
|
||||
Target = usr/lib/firmware/*
|
||||
Target = usr/src/*/dkms.conf
|
||||
|
||||
[Action]
|
||||
Depends = timeshift
|
||||
Description = Creating post root snapshot...
|
||||
When = PostTransaction
|
||||
Exec = /usr/bin/bash -c 'timeshift --create --comments "post_\$(date "+%Y-%m-%d-%H:%M:%S")" >/dev/null'
|
||||
post
|
||||
|
||||
install /dev/stdin /usr/local/bin/timeshift-gui <<- 'timeshift'
|
||||
#!/bin/sh
|
||||
pkexec env WAYLAND_DISPLAY="$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" XDG_RUNTIME_DIR=/run/user/0 timeshift-launcher
|
||||
timeshift
|
||||
;;
|
||||
esac
|
||||
|
||||
# Custom pacman wrapper
|
||||
install /dev/stdin /opt/local/bin/syu <<- syu
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
mirrorlist=
|
||||
|
||||
# Enable or disable pacman cache server
|
||||
/opt/local/bin/cacheserver
|
||||
|
||||
# Fetch latest mirrors
|
||||
sudo curl --fail --silent \${mirrorlist} -o /etc/pacman.d/mirrorlist
|
||||
|
||||
# Check for new packages and continue if found
|
||||
newpkg+=(\$(checkupdates --nocolor | awk '{print \$1}'))
|
||||
if [ "\${newpkg}" ]
|
||||
then
|
||||
# Update archlinux-keyring first
|
||||
if [[ \${newpkg[@]} =~ "archlinux-keyring" ]]
|
||||
then
|
||||
sudo pacman --ask 4 -S archlinux-keyring
|
||||
echo
|
||||
fi
|
||||
|
||||
# Perform update if dependencies are satisfied
|
||||
if sudo pacman --ask 4 -Syu --needed
|
||||
then
|
||||
echo
|
||||
sudo pacdiff
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
syu
|
||||
;;
|
||||
esac
|
||||
echo
|
||||
|
||||
# /opt/local/bin/cacheserver
|
||||
install /dev/stdin /opt/local/bin/cacheserver <<- 'cacheserver'
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
# Enable cacheserver if active
|
||||
cacheserver=
|
||||
port=
|
||||
scheme=
|
||||
|
||||
if [ -z ${cacheserver} ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if nc -z -4 -w 3 ${cacheserver} ${port:-80} >/dev/null 2>&1
|
||||
then
|
||||
if grep -q "CacheServer" /etc/pacman.conf
|
||||
then
|
||||
sudo sed "/CacheServer/ s/^\(#\)*//g" -i /etc/pacman.conf
|
||||
else
|
||||
sudo sed "/^\[core\]$\|^\[extra\]$\|^\[myvezfs\]$/a CacheServer = ${scheme:-http}://${cacheserver}:${port:-80}" -i /etc/pacman.conf
|
||||
fi
|
||||
else
|
||||
sudo sed "/CacheServer/ s/^/#/g" -i /etc/pacman.conf
|
||||
fi
|
||||
cacheserver
|
||||
if ls -l /dev/disk/* | grep -q 'VBOX\|virtio\|QEMU'
|
||||
then
|
||||
sed -e "/^cacheserver=/c cacheserver=192.168.122.1" \
|
||||
-e "/^port=/c port=9090" \
|
||||
-i /opt/local/bin/cacheserver
|
||||
/opt/local/bin/cacheserver
|
||||
fi
|
||||
|
||||
# mkinitcpio
|
||||
say as heading 'Regenerating cpio image'
|
||||
mkinitcpio -P
|
||||
echo
|
||||
|
||||
# Install GRUB
|
||||
if [[ ${arch} = [3567] ]]
|
||||
then
|
||||
say as heading 'Installing GRUB'
|
||||
grub-install --target=x86_64-efi --bootloader-id="Arch Linux (${hostname})" --efi-directory=/boot/efi --recheck || die 'Grub installation failed'
|
||||
grub-mkconfig -o /boot/grub/grub.cfg
|
||||
echo
|
||||
fi
|
||||
|
||||
# Sysctl custom settings
|
||||
cat >/etc/sysctl.d/99-sysctl.conf <<- SYSCTL
|
||||
net.core.netdev_max_backlog = 16384
|
||||
net.core.somaxconn = 8192
|
||||
net.core.rmem_default = 1048576
|
||||
net.core.rmem_max = 16777216
|
||||
net.core.wmem_default = 1048576
|
||||
net.core.wmem_max = 16777216
|
||||
net.core.optmem_max = 65536
|
||||
net.ipv4.tcp_rmem = 4096 1048576 2097152
|
||||
net.ipv4.tcp_wmem = 4096 65536 16777216
|
||||
net.ipv4.udp_rmem_min = 8192
|
||||
net.ipv4.udp_wmem_min = 8192
|
||||
net.ipv4.tcp_fastopen = 3
|
||||
net.ipv4.tcp_timestamps = 0
|
||||
net.core.default_qdisc = cake
|
||||
net.ipv4.tcp_congestion_control = bbr
|
||||
vm.swappiness=10
|
||||
vm.vfs_cache_pressure=50
|
||||
SYSCTL
|
||||
|
||||
# iptables
|
||||
cat >/etc/iptables/userinput.rules <<- IPTABLES
|
||||
## User input
|
||||
|
||||
# SSH port
|
||||
-A INPUT -p tcp -m tcp --dport ${port:-22} -j ACCEPT -m comment --comment "SSH Port"
|
||||
|
||||
## Simple Firewall
|
||||
IPTABLES
|
||||
sed "/OUTPUT ACCEPT/r /etc/iptables/userinput.rules" /etc/iptables/simple_firewall.rules >/etc/iptables/iptables.rules
|
||||
|
||||
# zram
|
||||
echo 'zram' >/etc/modules-load.d/zram.conf
|
||||
echo 'options zram num_devices=1' >/etc/modprobe.d/zram.conf
|
||||
echo 'KERNEL=="zram0", ATTR{comp_algorithm}="lz4", ATTR{disksize}="512M" RUN="/usr/bin/mkswap /dev/zram0", TAG+="systemd"' >/etc/udev/rules.d/99-zram.rules
|
||||
echo '/dev/zram0 none swap defaults 0 0' >>/etc/fstab
|
||||
|
||||
# Configure ssh and ssh_config.d/10-global.conf
|
||||
ssh-keygen -q \
|
||||
-t ed25519 \
|
||||
-P "" \
|
||||
-C "${USER}@${hostname}" \
|
||||
-f ~/.ssh/id_ed25519
|
||||
mkdir ~/.ssh/sockets/
|
||||
cat >/etc/ssh/sshd_config.d/10-sshd.conf <<- sshd
|
||||
PermitRootLogin no
|
||||
PasswordAuthentication no
|
||||
AuthenticationMethods publickey
|
||||
sshd
|
||||
cat >/etc/ssh/ssh_config.d/10-global.conf <<- 'sshconfig'
|
||||
# Preferred ciphers
|
||||
Ciphers aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
|
||||
|
||||
# Only use ipv4
|
||||
AddressFamily inet
|
||||
|
||||
# Multiplex
|
||||
ControlMaster auto
|
||||
ControlPath ~/.ssh/sockets/%r@%h-%p
|
||||
ControlPersist 10m
|
||||
|
||||
# Ease up on local area network devices
|
||||
Host 192.168.*
|
||||
StrictHostKeyChecking no
|
||||
UserKnownHostsFile=/dev/null
|
||||
LogLevel Error
|
||||
sshconfig
|
||||
|
||||
# Polkit
|
||||
mkdir -p /etc/polkit-1/rules.d/
|
||||
cat >/etc/polkit-1/rules.d/49-nopasswd_global.rules <<- 'polkit'
|
||||
/* Allow members of the wheel group to execute any actions
|
||||
* without password authentication, similar to "sudo NOPASSWD:"
|
||||
*/
|
||||
polkit.addRule(function(action, subject) {
|
||||
if (subject.isInGroup("wheel")) {
|
||||
return polkit.Result.YES;
|
||||
}
|
||||
});
|
||||
polkit
|
||||
|
||||
# Persistent journal logging
|
||||
mkdir -p /etc/systemd/journald.conf.d/
|
||||
cat >/etc/systemd/journald.conf.d/zz-journald.conf <<- eof
|
||||
[Journal]
|
||||
Storage=persistent
|
||||
eof
|
||||
|
||||
# makepkg
|
||||
mkdir -p /etc/makepkg.conf.d/
|
||||
cat >/etc/makepkg.conf.d/zz-makepkg.conf <<- makepkg
|
||||
PKGEXT=".pkg.tar"
|
||||
MAKEFLAGS="--jobs=$(nproc)"
|
||||
COMPRESSZST=(zstd -c -T0 --auto-threads=logical -)
|
||||
makepkg
|
||||
|
||||
# Virtual machine settings
|
||||
if ls -l /dev/disk/* | grep -q 'VBOX\|virtio\|QEMU'
|
||||
then
|
||||
mv /etc/sudoers.d/.zz-NOPASSWD /etc/sudoers.d/zz-NOPASSWD
|
||||
fi
|
||||
|
||||
##
|
||||
## Hooks
|
||||
##
|
||||
|
||||
# paccache
|
||||
cat >/etc/pacman.d/hooks/zz-paccache.hook <<- paccache
|
||||
[Trigger]
|
||||
Operation = Upgrade
|
||||
Operation = Install
|
||||
Operation = Remove
|
||||
Type = Package
|
||||
Target = *
|
||||
|
||||
[Action]
|
||||
Description = Cleaning pacman cache...
|
||||
When = PostTransaction
|
||||
Exec = /usr/bin/paccache --remove
|
||||
paccache
|
||||
|
||||
# locale.gen.pacnew hook
|
||||
install /dev/stdin /opt/local/hooks/localegen <<- hook
|
||||
#!/usr/bin/env bash
|
||||
if [ -f /etc/locale.gen.pacnew ]
|
||||
then
|
||||
sed '/#en_US.UTF-8 UTF-8/ s/#//' -i /etc/locale.gen.pacnew
|
||||
mv /etc/locale.gen.pacnew /etc/locale.gen
|
||||
locale-gen >/dev/null
|
||||
fi
|
||||
hook
|
||||
# locale.gen.pacnew hook
|
||||
cat >/etc/pacman.d/hooks/100-localegen.hook <<- localegen
|
||||
[Trigger]
|
||||
Operation = Install
|
||||
Operation = Upgrade
|
||||
Type = Package
|
||||
Target = glibc
|
||||
|
||||
[Action]
|
||||
Description = Fixing locale.gen
|
||||
When = PostTransaction
|
||||
Exec = /opt/local/hooks/localegen
|
||||
localegen
|
||||
|
||||
# iptables
|
||||
cat >/etc/pacman.d/hooks/100-iptables.rules.hook <<iptables
|
||||
[Trigger]
|
||||
Operation = Install
|
||||
Operation = Upgrade
|
||||
Type = Package
|
||||
Target = iptables-nft
|
||||
|
||||
[Action]
|
||||
Description = Fixing iptables rules
|
||||
When = PostTransaction
|
||||
Exec = /opt/local/hooks/iptables.rules
|
||||
iptables
|
||||
install /dev/stdin /opt/local/hooks/iptables.rules <<hook
|
||||
#!/usr/bin/env bash
|
||||
if [ -f /etc/iptables/iptables.rules.pacsave ]
|
||||
then
|
||||
sed "/OUTPUT ACCEPT/r /etc/iptables/userinput.rules" /etc/iptables/simple_firewall.rules >/etc/iptables/iptables.rules
|
||||
rm /etc/iptables/iptables.rules.pacsave
|
||||
fi
|
||||
hook
|
||||
|
||||
su ${username} <<- "user"
|
||||
curl --fail --silent https://git.myvelabs.com/lab/archlinux/raw/branch/master/functions/user -o /tmp/user
|
||||
bash /tmp/user
|
||||
user
|
||||
670
functions/desktop
Executable file
670
functions/desktop
Executable file
|
|
@ -0,0 +1,670 @@
|
|||
#!/usr/bin/env bash
|
||||
revision='0.1f (feb 24/25)'
|
||||
set -a
|
||||
set -E
|
||||
|
||||
# Exit function
|
||||
trap '[ "${?}" -ne 77 ] || exit 77' ERR
|
||||
function die
|
||||
{
|
||||
if [ ${@} ]
|
||||
then
|
||||
echo
|
||||
echo -e "\e[1;31mError encountered for the following reason:\e[0m
|
||||
|
||||
\e[33m${@}\e[0m
|
||||
|
||||
\e[1;31mScript aborted...\e[0m"
|
||||
echo
|
||||
else
|
||||
echo
|
||||
echo -e '\e[1;31mError encountered, script aborted...\e[0m'
|
||||
echo
|
||||
fi
|
||||
exit 77
|
||||
}
|
||||
|
||||
# Internet connection check
|
||||
if nc -z -w 1 archlinux.org 443 >/dev/null 2>&1 || nc -z -w 1 google.com 443 >/dev/null 2>&1
|
||||
then
|
||||
sudo timedatectl set-ntp true
|
||||
else
|
||||
die 'No internet connectivity detected, plug in an ethernet cable or run \e[32miwd-connect\e[33m if using wifi and try again'
|
||||
fi
|
||||
|
||||
totalde=21
|
||||
cat <<- menu
|
||||
$(tput setaf 5 bold)
|
||||
Select a desktop$(tput sgr0)
|
||||
$(tput smul setaf 7 dim)# none$(tput sgr0)
|
||||
0) none
|
||||
$(tput smul setaf 7 dim)# wayland$(tput sgr0)
|
||||
1) sway
|
||||
2) hyprland
|
||||
3) qtile-wayland
|
||||
4) river
|
||||
5) plasma-wayland
|
||||
6) gnome-wayland
|
||||
7) cosmic
|
||||
$(tput smul setaf 7 dim)# x11$(tput sgr0)
|
||||
8) qtile-x11
|
||||
9) bspwm
|
||||
10) awesome
|
||||
11) i3
|
||||
12) i3-plasma
|
||||
13) plasma-x11
|
||||
14) gnome-x11
|
||||
15) xfce4
|
||||
16) budgie
|
||||
17) cinnamon
|
||||
18) deepin
|
||||
19) mate
|
||||
20) pantheon
|
||||
21) cutefish
|
||||
22) lxde
|
||||
23) lxqt
|
||||
menu
|
||||
if [ ${1} ]
|
||||
then
|
||||
desktop=${1}
|
||||
else
|
||||
desktop=-1
|
||||
fi
|
||||
until [[ ${desktop} -ge 0 && ${desktop} -le ${totalde} ]]
|
||||
do
|
||||
read -p '> ' desktop
|
||||
[[ ${desktop} -ge 0 && ${desktop} -le ${totalde} ]] ||\
|
||||
echo -e "\n\n\e[1;31mInvalid selection, type an option from 0 to ${totalde}\e[0m"
|
||||
done
|
||||
|
||||
# Configure btrfs
|
||||
if findmnt / | grep -w -q btrfs
|
||||
then
|
||||
desktop_packages+=(btrfs-progs)
|
||||
if pacman -Q | grep -q "^grub"
|
||||
then
|
||||
desktop_packages+=(grub-btrfs inotify-tools)
|
||||
systemd_services+=(grub-btrfsd.service)
|
||||
fi
|
||||
|
||||
# echo -e '\n\e[1;35mConfiguring snapper\e[0m'
|
||||
# sudo pacman --sync --ask 4 snapper snap-pac
|
||||
# echo
|
||||
# sudo umount /.snapshots /home/.snapshots
|
||||
# sudo rm -r /.snapshots /home/.snapshots
|
||||
# sudo snapper -c root create-config /
|
||||
# sudo snapper -c home create-config /home
|
||||
# sudo sed -i 's/TIMELINE_LIMIT_HOURLY="10"/TIMELINE_LIMIT_HOURLY="4"/' /etc/snapper/configs/root
|
||||
# sudo sed -i 's/TIMELINE_LIMIT_DAILY="10"/TIMELINE_LIMIT_DAILY="7"/' /etc/snapper/configs/root
|
||||
# sudo sed -i 's/TIMELINE_LIMIT_MONTHLY="10"/TIMELINE_LIMIT_MONTHLY="1"/' /etc/snapper/configs/root
|
||||
# sudo sed -i 's/TIMELINE_LIMIT_YEARLY="10"/TIMELINE_LIMIT_YEARLY="0"/' /etc/snapper/configs/root
|
||||
# sudo sed -i 's/TIMELINE_CREATE="yes"/TIMELINE_CREATE="no"/' /etc/snapper/configs/home
|
||||
# sudo btrfs subvolume delete /.snapshots
|
||||
# sudo btrfs subvolume delete /home/.snapshots
|
||||
# sudo mkdir -p --mode=750 /.snapshots /home/.snapshots
|
||||
# sudo mount -a
|
||||
# sudo systemctl --quiet enable --now snapper-cleanup.timer snapper-timeline.timer
|
||||
|
||||
# # Create snapshots for fresh installation
|
||||
# sudo snapper -c root create --description "fresh install"
|
||||
# sudo snapper -c home create --description "fresh install"
|
||||
fi
|
||||
|
||||
# Assign DE variables
|
||||
case ${desktop} in
|
||||
0)
|
||||
# TTY only
|
||||
desktop_choice=none
|
||||
echo
|
||||
;;
|
||||
*)
|
||||
systemd_user_services+=(wireplumber.service pipewire-pulse.service pipewire.service)
|
||||
desktop_packages+=(ttf-dejavu pipewire pipewire-audio pipewire-pulse pipewire-jack wireplumber)
|
||||
case ${desktop} in
|
||||
[1-7])
|
||||
# Wayland
|
||||
desktop_packages+=(wayland)
|
||||
case ${desktop} in
|
||||
1)
|
||||
desktop_choice=sway
|
||||
desktop_packages+=(sway seatd swaylock swayidle swaybg bemenu bemenu-wayland i3status foot kate dolphin konsole kompare kcalc breeze-icons kde-cli-tools brightnessctl gnome-keyring fakeroot qt5-wayland polkit-kde-agent)
|
||||
systemd_services+=(seatd.service)
|
||||
;;
|
||||
2)
|
||||
desktop_choice=hyprland
|
||||
desktop_packages+=(hyprland uwsm swaylock swayidle bemenu bemenu-wayland waybar foot kate dolphin konsole kompare kcalc breeze-icons kde-cli-tools ttf-font-awesome brightnessctl gnome-keyring fakeroot qt5-wayland polkit-kde-agent)
|
||||
systemd_user_services+=(foot-server.service)
|
||||
;;
|
||||
3)
|
||||
desktop_choice=qtile-wayland
|
||||
desktop_packages+=(qtile python-pywlroots xorg-xwayland foot)
|
||||
systemd_user_services+=(foot-server.service)
|
||||
;;
|
||||
4)
|
||||
desktop_choice=river
|
||||
desktop_packages+=(river foot)
|
||||
systemd_user_services+=(foot-server.service)
|
||||
;;
|
||||
5)
|
||||
desktop_choice=plasma-wayland
|
||||
desktop_packages+=($(pacman -Sgq plasma | grep -v 'discover\|oxygen\|plasma-nm') konsole foot kate dolphin kompare kcalc)
|
||||
systemd_services+=(sddm.service)
|
||||
systemd_user_services+=(foot-server.service)
|
||||
;;
|
||||
6)
|
||||
desktop_choice=gnome-wayland
|
||||
desktop_packages+=(gnome foot)
|
||||
systemd_services+=(gdm.service)
|
||||
systemd_user_services+=(foot-server.service)
|
||||
;;
|
||||
7)
|
||||
desktop_choice=cosmic
|
||||
desktop_packages+=(cosmic)
|
||||
systemd_services+=(cosmic-greeter.service)
|
||||
if ls -l /dev/disk/* | grep -q 'VBOX\|virtio\|QEMU'
|
||||
then
|
||||
desktop_packages+=(vulkan-virtio)
|
||||
elif lspci | grep VGA | grep -q NVIDIA
|
||||
then
|
||||
desktop_packages+=(nvidia-utils)
|
||||
elif lscpu | grep 'Model name:' | grep -q AMD
|
||||
then
|
||||
desktop_packages+=(amdvlk)
|
||||
elif lscpu | grep 'Model name:' | grep -q Intel
|
||||
then
|
||||
desktop_packages+=(vulkan-intel)
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
# Environment
|
||||
sudo tee -a /etc/environment >/dev/null <<- environment
|
||||
QT_QPA_PLATFORM=wayland
|
||||
environment
|
||||
;;
|
||||
*)
|
||||
# Xorg
|
||||
desktop_packages+=(xorg)
|
||||
case ${desktop} in
|
||||
8)
|
||||
desktop_choice=qtile-x11
|
||||
desktop_packages+=(qtile xorg-xinit konsole)
|
||||
;;
|
||||
9)
|
||||
desktop_choice=bspwm
|
||||
desktop_packages+=(bspwm sxhkd xorg-xinit polybar konsole)
|
||||
;;
|
||||
10)
|
||||
desktop_choice=awesome
|
||||
desktop_packages+=(awesome xorg-xinit konsole)
|
||||
;;
|
||||
11)
|
||||
desktop_choice=i3
|
||||
desktop_packages+=(i3-wm i3status i3lock dmenu lightdm lightdm-gtk-greeter pavucontrol konsole kate dolphin kompare breeze-icons)
|
||||
systemd_services+=(lightdm.service)
|
||||
;;
|
||||
12)
|
||||
desktop_choice=i3-plasma
|
||||
desktop_packages+=($(pacman -Sgq plasma | grep -v 'discover\|oxygen\|plasma-nm') konsole kate dolphin kompare kcalc i3-wm i3status dmenu wmctrl feh)
|
||||
systemd_services+=(sddm.service)
|
||||
;;
|
||||
13)
|
||||
desktop_choice=plasma-x11
|
||||
desktop_packages+=($(pacman -Sgq plasma | grep -v 'discover\|oxygen\|plasma-nm') konsole kate dolphin kompare kcalc)
|
||||
systemd_services+=(sddm.service)
|
||||
;;
|
||||
14)
|
||||
desktop_choice=gnome-x11
|
||||
desktop_packages+=(gnome)
|
||||
systemd_services+=(gdm.service)
|
||||
;;
|
||||
15)
|
||||
desktop_choice=xfce4
|
||||
desktop_packages+=(xfce4 lightdm lightdm-gtk-greeter)
|
||||
systemd_services+=(lightdm.service)
|
||||
;;
|
||||
16)
|
||||
desktop_choice=budgie
|
||||
desktop_packages+=(budgie lightdm lightdm-gtk-greeter tilix)
|
||||
systemd_services+=(lightdm.service)
|
||||
;;
|
||||
17)
|
||||
desktop_choice=cinnamon
|
||||
desktop_packages+=(cinnamon lightdm lightdm-gtk-greeter gnome-console)
|
||||
systemd_services+=(lightdm.service)
|
||||
;;
|
||||
18)
|
||||
desktop_choice=deepin
|
||||
desktop_packages+=(deepin deepin-kwin $(pacman -Sgq deepin-extra | grep -v deepin-reader) lightdm lightdm-gtk-greeter gnome-keyring)
|
||||
systemd_services+=(lightdm.service)
|
||||
if uname -r | grep -q 'lts\|hardened\|zen'
|
||||
then
|
||||
desktop_packages+=(deepin-anything-dkms)
|
||||
else
|
||||
desktop_packages+=(deepin-anything-arch)
|
||||
fi
|
||||
;;
|
||||
19)
|
||||
desktop_choice=mate
|
||||
desktop_packages+=(mate mate-extra lightdm lightdm-gtk-greeter)
|
||||
systemd_services+=(lightdm.service)
|
||||
;;
|
||||
20)
|
||||
desktop_choice=pantheon
|
||||
desktop_packages+=(pantheon lightdm-pantheon-greeter lightdm)
|
||||
systemd_services+=(lightdm.service)
|
||||
;;
|
||||
21)
|
||||
desktop_choice=cutefish
|
||||
desktop_packages+=(cutefish sddm)
|
||||
systemd_services+=(sddm.service)
|
||||
;;
|
||||
22)
|
||||
desktop_choice=lxde
|
||||
desktop_packages+=(lxde lxdm)
|
||||
systemd_services+=(lxdm.service)
|
||||
;;
|
||||
23)
|
||||
desktop_choice=lxqt
|
||||
desktop_packages+=(lxqt sddm breeze-icons)
|
||||
systemd_services+=(sddm.service)
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
echo
|
||||
echo -e "\t\e[1mYou have chosen \e[32m${desktop_choice}\e[0m\e[1m desktop\e[0m"
|
||||
echo
|
||||
echo -e '\e[1;35mInstalling base packages\e[0m'
|
||||
sudo pacman --sync --ask 4 ${desktop_packages[@]} || die 'Failed to install required packages'
|
||||
echo
|
||||
;;
|
||||
esac
|
||||
|
||||
case ${desktop_choice} in
|
||||
plasma-wayland)
|
||||
mkdir -p ~/.config/{autostart-scripts,foot}/
|
||||
# install /dev/stdin ~/.config/autostart-scripts/foot.sh <<- foot
|
||||
# #!/bin/sh
|
||||
# foot --server
|
||||
# foot
|
||||
cat >>~/.config/kglobalshortcutsrc <<- shortcuts
|
||||
|
||||
[services][footclient.desktop]
|
||||
_launch=Alt+Return
|
||||
|
||||
[services][org.kde.konsole.desktop]
|
||||
_launch=none
|
||||
shortcuts
|
||||
;;
|
||||
gnome-wayland)
|
||||
mkdir -p ~/.config/{autostart,foot}/
|
||||
# cat > ~/.config/autostart/foot-server.desktop <<- foot
|
||||
# [Desktop Entry]
|
||||
# Type=Application
|
||||
# Name=Foot server
|
||||
# Exec=foot --server
|
||||
# foot
|
||||
gsettings set $(gsettings list-schemas | grep terminal) exec footclient
|
||||
;;
|
||||
cosmic)
|
||||
mkdir -p ~/.config/foot/
|
||||
;;
|
||||
i3|i3-plasma)
|
||||
# i3-config
|
||||
mkdir -p ~/.config/i3/
|
||||
curl --fail -s -L https://raw.githubusercontent.com/i3/i3/next/etc/config | sed 's/exec i3-config-wizard/# &/' > ~/.config/i3/config
|
||||
case ${desktop_choice} in
|
||||
i3-plasma)
|
||||
kwriteconfig6 --file startkderc --group General --key systemdBoot false
|
||||
sudo install /dev/stdin /opt/local/bin/plasma-i3.sh <<- EOF
|
||||
#!/usr/bin/env bash
|
||||
export KDEWM=/usr/bin/i3
|
||||
/usr/bin/startplasma-x11
|
||||
EOF
|
||||
sudo tee /usr/share/xsessions/plasma-i3.desktop >/dev/null <<- EOF
|
||||
[Desktop Entry]
|
||||
Type=XSession
|
||||
Exec=/opt/local/bin/plasma-i3.sh
|
||||
DesktopNames=KDE
|
||||
Name=Plasma (i3)
|
||||
Comment=KDE Plasma with i3 as the WM
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
if ls -l /dev/disk/* | grep -q 'VBOX\|virtio\|QEMU'
|
||||
then
|
||||
cat >> ~/.config/i3/config <<- 'i3'
|
||||
|
||||
exec xrandr --output $(xrandr -q | grep -w 'connected primary' | awk '{print $1}') --mode 1920x1080
|
||||
exec xrandr --dpi 192
|
||||
|
||||
exec spice-vdagent
|
||||
exec VBoxClient-all
|
||||
i3
|
||||
fi
|
||||
;;
|
||||
qtile-x11)
|
||||
echo 'exec qtile start' >~/.xinitrc
|
||||
cat >> ~/.bash_profile <<- 'autostart'
|
||||
|
||||
if [ -z "$DISPLAY" ] && [ "$XDG_VTNR" = 1 ]
|
||||
then
|
||||
exec startx
|
||||
fi
|
||||
autostart
|
||||
;;
|
||||
qtile-wayland)
|
||||
mkdir -p ~/.config/foot/
|
||||
cat >> ~/.bash_profile <<- 'autostart'
|
||||
|
||||
# Start sway on login from tty
|
||||
if [ -z "${WAYLAND_DISPLAY}" ] && [ "${XDG_VTNR}" = 1 ]
|
||||
then
|
||||
exec qtile start -b wayland
|
||||
fi
|
||||
autostart
|
||||
;;
|
||||
river)
|
||||
mkdir -p ~/.config/foot/
|
||||
cat >> ~/.bash_profile <<- 'autostart'
|
||||
|
||||
# Start sway on login from tty
|
||||
if [ -z "${WAYLAND_DISPLAY}" ] && [ "${XDG_VTNR}" = 1 ]
|
||||
then
|
||||
exec river
|
||||
fi
|
||||
autostart
|
||||
;;
|
||||
bspwm)
|
||||
cat >> ~/.bash_profile <<- 'autostart'
|
||||
|
||||
if [ -z "$DISPLAY" ] && [ "$XDG_VTNR" = 1 ]
|
||||
then
|
||||
exec startx /usr/bin/bspwm
|
||||
fi
|
||||
autostart
|
||||
mkdir -p ~/.config/{bspwm,sxhkd,polybar}/
|
||||
install -Dm755 /usr/share/doc/bspwm/examples/bspwmrc ~/.config/bspwm/bspwmrc
|
||||
install -Dm644 /usr/share/doc/bspwm/examples/sxhkdrc ~/.config/sxhkd/sxhkdrc
|
||||
cp /etc/polybar/config.ini ~/.config/polybar/
|
||||
;;
|
||||
awesome)
|
||||
cat >> ~/.bash_profile <<- 'autostart'
|
||||
|
||||
if [ -z "$DISPLAY" ] && [ "$XDG_VTNR" = 1 ]
|
||||
then
|
||||
exec startx /usr/bin/awesome
|
||||
fi
|
||||
autostart
|
||||
mkdir -p ~/.config/awesome/
|
||||
sed -e '/^terminal =/c terminal = "konsole"' \
|
||||
-e '/^modkey =/c modkey = "Mod1"' /etc/xdg/awesome/rc.lua > ~/.config/awesome/
|
||||
;;
|
||||
sway)
|
||||
# Sway
|
||||
sudo gpasswd -a ${USER} seat >/dev/null
|
||||
|
||||
# Dolphin default apps
|
||||
mkdir -p ~/.config/menus/
|
||||
curl --fail -s -L https://raw.githubusercontent.com/KDE/plasma-workspace/master/menu/desktop/plasma-applications.menu -o ~/.config/menus/applications.menu
|
||||
kbuildsycoca6 >/dev/null 2>&1
|
||||
|
||||
# Dolphin default terminal
|
||||
cat >> ~/.config/kdeglobals <<- foot
|
||||
[General]
|
||||
TerminalApplication=footclient
|
||||
foot
|
||||
|
||||
# Create conf directories
|
||||
mkdir -p ~/.config/{sway/config.d,foot}/
|
||||
|
||||
# Identify conf locations
|
||||
cat > ~/.config/sway/config <<- 'config'
|
||||
include /etc/sway/config.d/*
|
||||
include ~/.config/sway/config.d/*
|
||||
config
|
||||
|
||||
# Default sway config
|
||||
sed -e 's/mod Mod4/mod Mod1/' \
|
||||
-e 's/term foot/&client/' \
|
||||
-e '/set $menu/c set $menu bemenu-run -p "" --no-overlap --tb "#285577" --hb "#285577" --tf "#eeeeee" --hf "#eeeeee" --nf "#bbbbbb"' \
|
||||
/etc/sway/config > ~/.config/sway/config.d/00-config
|
||||
sed -n "/^# Status Bar:$/q;p" -i ~/.config/sway/config.d/00-config
|
||||
|
||||
# Sway config
|
||||
cat > ~/.config/sway/config.d/zz-sway <<- 'config'
|
||||
# Disable xwayland
|
||||
xwayland disable
|
||||
|
||||
# Start foot terminal server
|
||||
exec foot --server
|
||||
|
||||
# Use i3status
|
||||
bar {
|
||||
status_command i3status
|
||||
}
|
||||
|
||||
# Floating windows
|
||||
for_window [window_role="About"] floating enable
|
||||
for_window [window_role="Organizer"] floating enable
|
||||
for_window [window_role="Preferences"] floating enable
|
||||
for_window [window_role="bubble"] floating enable
|
||||
for_window [window_role="page-info"] floating enable
|
||||
for_window [window_role="pop-up"] floating enable
|
||||
for_window [window_role="task_dialog"] floating enable
|
||||
for_window [window_role="toolbox"] floating enable
|
||||
for_window [window_role="webconsole"] floating enable
|
||||
for_window [window_type="dialog"] floating enable
|
||||
for_window [window_type="menu"] floating enable
|
||||
|
||||
# Floating for KCalc
|
||||
for_window [title="KCalc"] floating enable
|
||||
|
||||
# Bind keys for brightness
|
||||
bindsym XF86MonBrightnessDown exec brightnessctl set 5%-
|
||||
bindsym XF86MonBrightnessUp exec brightnessctl set 5%+
|
||||
|
||||
# Mouse and keyboard defaults
|
||||
input type:keyboard xkb_numlock enabled
|
||||
input type:touchpad {
|
||||
tap enabled
|
||||
natural_scroll enabled
|
||||
}
|
||||
config
|
||||
|
||||
# Display config
|
||||
cat > ~/.config/sway/config.d/zz-display <<- 'display'
|
||||
# # Declare output
|
||||
# set $laptop eDP-1 (swaymsg -t get_outputs)
|
||||
|
||||
# Swayidle
|
||||
exec swayidle -w \
|
||||
timeout 300 'swaylock -e -f -c 000000' \
|
||||
timeout 315 'swaymsg "output * power off"' \
|
||||
resume 'swaymsg "output * power on"' \
|
||||
timeout 600 'systemctl suspend' \
|
||||
before-sleep 'swaylock -e -f -c 000000'
|
||||
|
||||
# Laptop lid switches
|
||||
bindswitch --reload --locked lid:on output * disable
|
||||
bindswitch --reload --locked lid:off output * enable
|
||||
|
||||
# Swaylock
|
||||
bindsym Mod4+l exec swaylock -e -f -c 000000
|
||||
|
||||
# Solid black background
|
||||
output * bg #000000 solid_color
|
||||
|
||||
# Prevent swayidle when a window is in fullscreen
|
||||
for_window [class=".*"] inhibit_idle fullscreen
|
||||
for_window [app_id=".*"] inhibit_idle fullscreen
|
||||
display
|
||||
|
||||
# Polkit
|
||||
cat > ~/.config/sway/config.d/zz-polkit <<- 'polkit'
|
||||
exec "/usr/lib/polkit-kde-authentication-agent-1"
|
||||
polkit
|
||||
|
||||
# Monitor
|
||||
if ls -l /dev/disk/* | grep -q 'VBOX\|virtio\|QEMU'
|
||||
then
|
||||
cat > ~/.config/sway/config.d/zz-virtualmonitor <<- 'monitor'
|
||||
# Virtual monitor
|
||||
output Virtual-1 {
|
||||
pos 0,0
|
||||
mode 1920x1080@60Hz
|
||||
scale 1.25
|
||||
}
|
||||
monitor
|
||||
fi
|
||||
|
||||
# TTY sway autostart
|
||||
cat >> ~/.bash_profile <<- 'sway'
|
||||
|
||||
# Start sway on login from tty
|
||||
if [ -z "${WAYLAND_DISPLAY}" ] && [ "${XDG_VTNR}" = 1 ]
|
||||
then
|
||||
exec sway
|
||||
fi
|
||||
sway
|
||||
;;
|
||||
hyprland)
|
||||
# Hyprland
|
||||
mkdir -p ~/.config/{menus,hypr/scripts,foot,waybar}/
|
||||
|
||||
# Dolphin default apps
|
||||
curl --fail -s -L https://raw.githubusercontent.com/KDE/plasma-workspace/master/menu/desktop/plasma-applications.menu -o ~/.config/menus/applications.menu
|
||||
kbuildsycoca6 >/dev/null 2>&1
|
||||
|
||||
# Dolphin default terminal
|
||||
cat >> ~/.config/kdeglobals <<- foot
|
||||
[General]
|
||||
TerminalApplication=footclient
|
||||
foot
|
||||
|
||||
# Swayidle
|
||||
install /dev/stdin ~/.config/hypr/scripts/sleep.sh <<- 'swayidle'
|
||||
swayidle -w timeout 300 'swaylock -f -c 000000' \
|
||||
timeout 600 'systemctl suspend' \
|
||||
before-sleep 'swaylock -f -c 000000' &
|
||||
swayidle
|
||||
|
||||
# Config
|
||||
curl --silent --fail https://raw.githubusercontent.com/hyprwm/Hyprland/refs/heads/main/example/hyprland.conf |\
|
||||
sed -e '/Autostart/i exec-once = /usr/lib/polkit-kde-authentication-agent-1' \
|
||||
-e '/Autostart/i exec-once = waybar -c ~/.config/waybar/waybar.conf' \
|
||||
-e '/Autostart/i exec-once = ~/.config/hypr/scripts/sleep.sh' \
|
||||
-e '/^$terminal =/c $terminal = footclient' \
|
||||
-e '/gaps_in =/c gaps_in = 0' \
|
||||
-e '/gaps_out =/c gaps_out = 0' \
|
||||
-e '/^$menu =/c $menu = bemenu-run -p "" --no-overlap --tb "##285577" --hb "##285577" --tf "##eeeeee" --hf "##eeeeee" --nf "##bbbbbb"' \
|
||||
-e 's/bind = $mainMod, R, exec, $menu/bind = $mainMod, D, exec, $menu/' \
|
||||
-e 's/bind = $mainMod, Q, exec, $terminal/bind = $mainMod, RETURN, exec, $terminal/' \
|
||||
-e 's/bind = $mainMod, C, killactive/bind = $mainMod SHIFT, Q, killactive/' \
|
||||
-e '/$mainMod =/c $mainMod = ALT' \
|
||||
-e '/RETURN/a bind = SUPER, L, exec, swaylock -e -f -c 000000' \
|
||||
> ~/.config/hypr/hyprland.conf
|
||||
# -e '/Autostart/i exec-once = uwsm app -- foot --server' \
|
||||
|
||||
# QEMU monitor
|
||||
if ls -l /dev/disk/* | grep -q 'VBOX\|virtio\|QEMU'
|
||||
then
|
||||
sed -i "/^monitor/c monitor = $(hyprctl monitors all | grep "^Monitor" | awk '{print $2}'), 1920x1080@60, 0x0, 1.5" ~/.config/hypr/hyprland.conf
|
||||
fi
|
||||
|
||||
# Waybar
|
||||
sed -e 's|sway/workspaces|sway/workspaces|g' \
|
||||
-e 's|sway/mode|hyprland/submap|g' \
|
||||
-e '/position/ s|//||' \
|
||||
/etc/xdg/waybar/config.jsonc > ~/.config/waybar/waybar.conf
|
||||
|
||||
# TTY sway autostart
|
||||
cat >> ~/.bash_profile <<- 'hyprland'
|
||||
|
||||
# Start sway on login from tty
|
||||
if uwsm check may-start
|
||||
then
|
||||
exec uwsm start hyprland.desktop
|
||||
fi
|
||||
hyprland
|
||||
;;
|
||||
esac
|
||||
|
||||
# Foot terminal config (/etc/xdg/foot/foot.ini)
|
||||
if [ -d ~/.config/foot/ ]
|
||||
then
|
||||
cat > ~/.config/foot/foot.ini <<- 'foot'
|
||||
[main]
|
||||
include=/usr/share/foot/themes/kitty
|
||||
font=Source Code Pro:size=12
|
||||
workers=32
|
||||
|
||||
[scrollback]
|
||||
# lines=1000
|
||||
foot
|
||||
fi
|
||||
|
||||
# Add user to shared folder group if in virtualbox guest
|
||||
if ls -l /dev/disk/* | grep -q VBOX
|
||||
then
|
||||
sudo gpasswd -a ${USER} vboxsf >/dev/null
|
||||
echo
|
||||
fi
|
||||
|
||||
# iwd status function
|
||||
if pacman -Q | grep -w -q iwd
|
||||
then
|
||||
cat > ~/.local/functions/iwd-status <<- iwd
|
||||
#!/usr/bin/env bash
|
||||
# iwd connection status
|
||||
function iwd-status
|
||||
{
|
||||
iwctl station "$(iwctl station list | grep connected | awk '{print $(NF-1)}')" show
|
||||
}
|
||||
|
||||
alias iwctl='iwctl station $(iwctl station list | grep connected | awk '{print $(NF-1)}')'
|
||||
iwd
|
||||
fi
|
||||
|
||||
if [[ "${desktop_choice}" == "none" ]]
|
||||
then
|
||||
sudo rm -f ${0}
|
||||
echo -e '\e[1;34mSetup complete, press any key to continue\e[5m...\e[0m\n'
|
||||
read -n 1 -s -p ''
|
||||
elif ls /usr/share/*sessions | grep -q desktop
|
||||
then
|
||||
install /dev/stdin ~/.local/bin/startup <<- 'EOF'
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Internet connection check
|
||||
if nc -z -w 1 archlinux.org 443 >/dev/null 2>&1 || nc -z -w 1 google.com 443 >/dev/null 2>&1
|
||||
then
|
||||
vim ~/.local/bin/startupscript
|
||||
~/.local/bin/startupscript
|
||||
rm -f ${0}
|
||||
exit 0
|
||||
else
|
||||
echo -e '\n\e[31mNo internet connectivity detected'
|
||||
echo -e 'Connect to a network and try again'
|
||||
echo -e 'Aborting installer...\e[0m\n'
|
||||
exit 1
|
||||
fi
|
||||
EOF
|
||||
|
||||
install /dev/stdin ~/.local/bin/startupscript <<- EOF
|
||||
$(curl --fail --silent https://git.myvelabs.com/lab/archlinux/raw/branch/master/functions/startup)
|
||||
EOF
|
||||
sudo rm -f ${0}
|
||||
echo -e '\e[1;34mDesktop installed, press any key to load '${desktop_choice}'\e[5m...\e[0m'
|
||||
read -n 1 -s -p ''
|
||||
echo
|
||||
else
|
||||
die 'Something does not feel right'
|
||||
fi
|
||||
|
||||
# Systemd services
|
||||
for service in ${systemd_user_services[@]}
|
||||
do
|
||||
systemctl --quiet --user enable --now ${service}
|
||||
done
|
||||
sudo systemctl --quiet enable --now ${systemd_services[@]}
|
||||
297
functions/startup
Executable file
297
functions/startup
Executable file
|
|
@ -0,0 +1,297 @@
|
|||
#!/usr/bin/env bash
|
||||
# AUR package list
|
||||
aur_list=(
|
||||
# nomachine
|
||||
# realvnc-vnc-viewer
|
||||
# jdownloader2
|
||||
# ledger-live-bin
|
||||
# czkawka-gui-bin
|
||||
)
|
||||
|
||||
# Optional packages list
|
||||
optional=(
|
||||
firefox firefox-decentraleyes firefox-ublock-origin
|
||||
ark okular shotwell mpv ffmpegthumbs
|
||||
veracrypt keepassxc
|
||||
# nextcloud-client
|
||||
# ntfs-3g exfatprogs
|
||||
# libreoffice-fresh
|
||||
# remmina libvncserver
|
||||
# torbrowser-launcher
|
||||
# thunderbird
|
||||
# filezilla
|
||||
# chromium
|
||||
# vlc
|
||||
# gnome-disk-utility
|
||||
# xdg-user-dirs
|
||||
# noto-fonts-cjk
|
||||
# noto-fonts-emoji
|
||||
)
|
||||
|
||||
function INSTALL
|
||||
{
|
||||
sudo pacman --sync ${@} --ask 4
|
||||
echo
|
||||
}
|
||||
|
||||
# VirtualBox
|
||||
until [[ ${install_virtualbox} = [yYnN] ]]
|
||||
do
|
||||
read -n 1 -p $'\n\e[1mWould you like to install Virtualbox? (y/n): \e[0m' install_virtualbox
|
||||
[[ ${install_virtualbox} = [yYnN] ]] || echo -e -n '\n\n\e[1;31mNot a valid answer, type "y" or "n"\e[0m'
|
||||
done
|
||||
echo
|
||||
# QEMU
|
||||
until [[ ${install_qemu} = [yYnN] ]]
|
||||
do
|
||||
read -n 1 -p $'\n\e[1mWould you like to install QEMU? (y/n): \e[0m' install_qemu
|
||||
[[ ${install_qemu} = [yYnN] ]] || echo -e -n '\n\n\e[1;31mNot a valid answer, type "y" or "n"\e[0m'
|
||||
done
|
||||
|
||||
echo
|
||||
echo
|
||||
|
||||
# Package groups installation
|
||||
INSTALL ${optional[@]}
|
||||
|
||||
# Remmina
|
||||
if [[ ${optional[@]} =~ "remmina" ]] && [ -d ~/.config/sway/config.d/ ]
|
||||
then
|
||||
# Remmina passthrough
|
||||
cat > ~/.config/sway/config.d/zz-remmina <<- 'remmina'
|
||||
# VNC passthrough
|
||||
mode remmina {
|
||||
bindsym Mod4+Shift+p mode default
|
||||
}
|
||||
bindsym Mod4+Shift+p mode remmina
|
||||
remmina
|
||||
fi
|
||||
|
||||
# Tor
|
||||
if [[ ${optional[@]} =~ "torbrowser-launcher" ]]
|
||||
then
|
||||
torbrowser-launcher
|
||||
fi
|
||||
|
||||
# Bluetooth
|
||||
if pacman -Q | grep -q bluez-utils
|
||||
then
|
||||
INSTALL bluedevil
|
||||
sudo systemctl --quiet enable --now bluetooth.service
|
||||
fi
|
||||
|
||||
# AUR packages
|
||||
if [ ${#aur_list[@]} -gt 0 ]
|
||||
then
|
||||
if ! pacman -Q | grep -q -w git
|
||||
then
|
||||
INSTALL git
|
||||
fi
|
||||
echo -e '#!/usr/bin/env bash' > ~/.local/functions/aur-packages
|
||||
for aur_package in ${aur_list[@]}
|
||||
do
|
||||
cd
|
||||
git clone https://aur.archlinux.org/${aur_package}.git
|
||||
if echo ${aur_package} | grep -q nomachine
|
||||
then
|
||||
sed -i 's/_autoservice=n/_autoservice=y/' nomachine/PKGBUILD
|
||||
sed -i 's/_autofirewall=n/_autofirewall=y/' nomachine/PKGBUILD
|
||||
fi
|
||||
cd ${aur_package}/
|
||||
makepkg -csi
|
||||
echo
|
||||
cd ..
|
||||
rm -r ${aur_package}/ -f
|
||||
cat >> ~/.local/functions/aur-packages <<- aur
|
||||
function aur-${aur_package}
|
||||
{
|
||||
cd ~/
|
||||
git clone https://aur.archlinux.org/${aur_package}.git
|
||||
cd ${aur_package}/
|
||||
makepkg -csi
|
||||
echo
|
||||
cd ~/
|
||||
rm -r ${aur_package}/ -f
|
||||
}
|
||||
|
||||
aur
|
||||
done
|
||||
fi
|
||||
|
||||
# Optional AUR extras
|
||||
# freefilesync
|
||||
# pdfsam
|
||||
# fslint pygtk
|
||||
|
||||
# Printers
|
||||
# yay -S --ask 4 print-manager cups system-config-printer skanlite && echo && sudo systemctl --quiet enable --now org.cups.cupsd && sudo gpasswd -a ${USER} sys >/dev/null
|
||||
# Webcam
|
||||
# sudo gpasswd -a ${USER} video >/dev/null
|
||||
|
||||
# i3
|
||||
if [ -f ~/.config/i3/config ]
|
||||
then
|
||||
cat >> ~/.config/i3/config <<- 'config'
|
||||
|
||||
# gaps inner 8
|
||||
# gaps outer 4
|
||||
# for_window [class="^.*"] border pixel 2
|
||||
config
|
||||
|
||||
cat > ~/.local/functions/i3-config <<- 'config'
|
||||
#!/usr/bin/env bash
|
||||
# i3 config
|
||||
function i3-config
|
||||
{
|
||||
vim ~/.config/i3/config
|
||||
}
|
||||
config
|
||||
|
||||
if [ -f /usr/share/xsessions/plasma-i3.desktop ]
|
||||
then
|
||||
tee -a ~/.config/i3/config >/dev/null <<- 'integration'
|
||||
|
||||
# >>> Plasma Integration <<<
|
||||
# Try to kill the wallpaper set by Plasma (it takes up the entire workspace and hides everything)
|
||||
exec --no-startup-id wmctrl -c Plasma
|
||||
for_window [title="Desktop — Plasma"] kill; floating enable; border none
|
||||
no_focus [class=”plasmashell”]
|
||||
|
||||
# Avoid tiling popups, dropdown windows from plasma
|
||||
for_window [class="plasmashell"] floating enable
|
||||
for_window [class="Plasma"] floating enable
|
||||
for_window [class="krunner"] floating enable
|
||||
for_window [class="Kmix"] floating enable
|
||||
for_window [class="Klipper"] floating enable
|
||||
for_window [class="Plasmoidviewer"] floating enable
|
||||
|
||||
# >>> Window Rules <<<
|
||||
# >>> Avoid tiling for non-Plasma stuff <<<
|
||||
for_window [window_role="pop-up"] floating enable
|
||||
for_window [window_role="bubble"] floating enable
|
||||
for_window [window_role="task_dialog"] floating enable
|
||||
for_window [window_role="Preferences"] floating enable
|
||||
for_window [window_role="About"] floating enable
|
||||
for_window [window_type="dialog"] floating enable
|
||||
for_window [window_type="menu"] floating enable
|
||||
integration
|
||||
|
||||
install /dev/stdin ~/.local/bin/rotate-wallpapers <<- feh
|
||||
#!/usr/bin/env bash
|
||||
sleep 1
|
||||
while true
|
||||
do
|
||||
feh --bg-max --randomize /home/${USER}/Pictures
|
||||
sleep 15
|
||||
done
|
||||
feh
|
||||
else
|
||||
if ls -l /dev/disk/* | grep -q 'VBOX'
|
||||
then
|
||||
echo 'exec VBoxClient-all' >> ~/.config/i3/config
|
||||
elif ls -l /dev/disk/* | grep -q 'virtio\|QEMU'
|
||||
then
|
||||
echo 'exec spice-vdagent' >> ~/.config/i3/config
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Sway nextcloud
|
||||
if [[ ${optional[@]} =~ "nextcloud-client" ]] && [ -f ~/.config/sway/config.d/zz-sway ]
|
||||
then
|
||||
cat > ~/.config/sway/config.d/zz-nextcloud <<- 'nextcloud'
|
||||
# Nextcloud
|
||||
exec nextcloud
|
||||
for_window [title="Nextcloud Settings"] floating enable
|
||||
nextcloud
|
||||
fi
|
||||
|
||||
# Virtualbox
|
||||
if [[ ${install_virtualbox} = [yY] ]]
|
||||
then
|
||||
echo 'Installing Virtualbox'
|
||||
|
||||
if uname -r | grep -q 'lts\|hardened\|zen'
|
||||
then
|
||||
host_modules='virtualbox-host-dkms'
|
||||
else
|
||||
host_modules='virtualbox-host-modules-arch'
|
||||
fi
|
||||
|
||||
INSTALL virtualbox ${host_modules} virtualbox-guest-iso
|
||||
echo
|
||||
|
||||
sudo gpasswd -a ${USER} vboxusers >/dev/null
|
||||
echo
|
||||
|
||||
if findmnt '/' | grep -q -w 'btrfs'
|
||||
then
|
||||
mkdir ~/VirtualBox\ VMs/
|
||||
chattr +C ~/VirtualBox\ VMs/
|
||||
fi
|
||||
fi
|
||||
|
||||
# QEMU
|
||||
if [[ ${install_qemu} = [yY] ]]
|
||||
then
|
||||
echo 'Installing QEMU'
|
||||
INSTALL qemu-desktop virt-manager edk2-ovmf \
|
||||
dnsmasq dmidecode vde2 bridge-utils
|
||||
echo
|
||||
|
||||
# Make host system a pacman cache server
|
||||
sudo tee /etc/systemd/system/local-cacheserver.service >/dev/null <<- 'CACHESERVER'
|
||||
[Unit]
|
||||
Description=Python HTTP server for Pacman Cache Server
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/python3 -m http.server --directory /var/cache/pacman/pkg/ 9090
|
||||
Restart=always
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
CACHESERVER
|
||||
|
||||
# Host iptables rules as a pacman cache server
|
||||
sudo iptables -I INPUT -s 192.168.0.0/16 -p tcp -m tcp --dport 9090 -j ACCEPT -m comment --comment "Pacman cache server"
|
||||
sudo sed -i '/## Simple Firewall/i\
|
||||
# Pacman cache server\
|
||||
-A INPUT -s 192.168.0.0/16 -p tcp -m tcp --dport 9090 -j ACCEPT -m comment --comment "Pacman cache server"\n' \
|
||||
/etc/iptables/userinput.rules
|
||||
sed "/OUTPUT ACCEPT/r /etc/iptables/userinput.rules" /etc/iptables/simple_firewall.rules | sudo tee /etc/iptables/iptables.rules >/dev/null
|
||||
|
||||
# QEMU pacman cache service
|
||||
sudo tee /etc/systemd/system/local-update-virtpkg-cache.service >/dev/null <<- 'service'
|
||||
[Unit]
|
||||
Description=Refresh package cache twice daily
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/bin/bash -c "/usr/bin/pacman -Syw -d --ask 4 $(curl --fail -s -L https://git.myvelabs.com/lab/archlinux/raw/branch/master/pkg/qemu)"
|
||||
service
|
||||
|
||||
# QEMU pacman cache timer
|
||||
sudo tee /etc/systemd/system/local-update-virtpkg-cache.timer >/dev/null <<- 'timer'
|
||||
[Unit]
|
||||
Description=Refresh pacman package cache
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 00/12:00:00
|
||||
RandomizedDelaySec=12h
|
||||
Persistent=true
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
timer
|
||||
|
||||
# Enable services
|
||||
sudo systemctl --quiet enable --now libvirtd.service
|
||||
sudo systemctl --quiet enable local-cacheserver.service local-update-virtpkg-cache.timer
|
||||
sudo virsh -q net-start default
|
||||
sudo virsh -q net-autostart default
|
||||
sudo gpasswd -a ${USER} libvirt >/dev/null
|
||||
echo
|
||||
fi
|
||||
|
||||
rm -f ${0}
|
||||
echo -e '\e[1;32mSupplementary installer completed, reboot one last time\e[0m\n'
|
||||
110
functions/user
Executable file
110
functions/user
Executable file
|
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/env bash
|
||||
revision=0.1a
|
||||
set -a
|
||||
set -E
|
||||
|
||||
# Create local paths
|
||||
mkdir -p ~/.local/{bin,functions}
|
||||
|
||||
# Generate ssh identity
|
||||
ssh-keygen -q \
|
||||
-t ed25519 \
|
||||
-P "" \
|
||||
-C "${username}@${hostname}" \
|
||||
-f ~/.ssh/id_ed25519
|
||||
mkdir ~/.ssh/sockets/
|
||||
|
||||
# Custom bashrc
|
||||
cat > ~/.local/functions/bashrc <<- 'BASHRC'
|
||||
#!/usr/bin/env bash
|
||||
# Shell color
|
||||
PS1="$(tput setaf 6)[\u@\h \W \$?]\$ $(tput sgr0)"
|
||||
|
||||
# Colored prompts
|
||||
alias ll='ls --color=auto -l -a -h'
|
||||
alias egrep='egrep --color=auto'
|
||||
alias fgrep='fgrep --color=auto'
|
||||
BASHRC
|
||||
|
||||
# Btrfs functions
|
||||
if findmnt / | grep -w -q btrfs
|
||||
then
|
||||
cat > ~/.local/functions/btrfs <<- 'btrfs'
|
||||
#!/usr/bin/env bash
|
||||
# Btrfs check
|
||||
function btrfs-check
|
||||
{
|
||||
sudo dmesg | grep -i btrfs
|
||||
}
|
||||
# # Snapper
|
||||
# function snapshot-home
|
||||
# {
|
||||
# if [ "${*}" ]
|
||||
# then
|
||||
# sudo snapper -c home create --description "${*}"
|
||||
# else
|
||||
# sudo snapper -c home create --description "$(date)"
|
||||
# fi
|
||||
# }
|
||||
#
|
||||
# function snapshot-root
|
||||
# {
|
||||
# if [ "${*}" ]
|
||||
# then
|
||||
# sudo snapper -c root create --description "${*}"
|
||||
# else
|
||||
# sudo snapper -c root create --description "$(date)"
|
||||
# fi
|
||||
# }
|
||||
#
|
||||
# function snapshot-list
|
||||
# {
|
||||
# sudo -v
|
||||
# echo -e '\n\e[1;33mRoot snapshots:\e[0m'
|
||||
# sudo snapper -c root ls
|
||||
# echo -e '\n\e[1;33mHome snapshots:\e[0m'
|
||||
# sudo snapper -c home ls
|
||||
# echo
|
||||
# }
|
||||
#
|
||||
# function snapshot-delete
|
||||
# {
|
||||
# if ! grep -w -q 'root\|home' <<< "${1}" || [ -z "${2}" ]
|
||||
# then
|
||||
# echo -e '\n\t\e[1;31mInvalid option, use syntax: ${root,home} $snapshot\e[0m\n'
|
||||
# return 1
|
||||
# elif grep -w -q '1' <<< "${2}"
|
||||
# then
|
||||
# echo -e '\n\t\e[1;31mUnable to delete "fresh install" snapshot\e[0m\n'
|
||||
# return 1
|
||||
# fi
|
||||
#
|
||||
# if [[ "${1}" = "root" ]]
|
||||
# then
|
||||
# if ls /.snapshots | grep -q $(sed -e 's/-/\\\|/g' <<< "${2}")
|
||||
# then
|
||||
# sudo snapper -c root delete "${2}"
|
||||
# elif ! [ -d /.snapshots/"${2}" ]
|
||||
# then
|
||||
# echo -e '\n\t\e[1;31mSnapshot doesn't exist, try again\e[0m\n'
|
||||
# fi
|
||||
# elif [[ "${1}" = "home" ]]
|
||||
# then
|
||||
# if ls /home/.snapshots | grep -q $(sed -e 's/-/\\\|/g' <<< "${2}")
|
||||
# then
|
||||
# sudo snapper -c home delete "${2}"
|
||||
# elif ! [ -d /home/.snapshots/"${2}" ]
|
||||
# then
|
||||
# echo -e '\n\t\e[1;31mSnapshot doesn't exist, try again\e[0m\n'
|
||||
# fi
|
||||
# fi
|
||||
# }
|
||||
btrfs
|
||||
fi
|
||||
|
||||
if pacman -Q | grep -q yubikey
|
||||
then
|
||||
install /dev/stdin ~/yksetup.sh <<- 'yubikey'
|
||||
$(curl --fail --silent https://git.myvelabs.com/lab/archlinux/raw/branch/master/functions/yubikey)
|
||||
yubikey
|
||||
fi
|
||||
86
functions/yubikey
Executable file
86
functions/yubikey
Executable file
|
|
@ -0,0 +1,86 @@
|
|||
#!/usr/bin/env bash
|
||||
echo
|
||||
|
||||
[ -d ~/.config/Yubico ] || mkdir -p ~/.config/Yubico
|
||||
|
||||
sudo pacman -S --ask 4 pam-u2f yubico-pam
|
||||
|
||||
read -n 1 -s -p $'\n\e[1;33mInsert your yubikey and press the enter key to continue \e[0m'
|
||||
echo -e '\n\e[1mTouch the yubikey when it starts blinking\e[0m'
|
||||
|
||||
pamu2fcfg > ~/.config/Yubico/u2f_keys
|
||||
|
||||
read -n 1 -p $'\n\e[1mWould you like to add another yubikey? (y/n): \e[0m' YUBIKEY
|
||||
|
||||
until [[ "$YUBIKEY" = [nN] ]]
|
||||
do
|
||||
if [[ "$YUBIKEY" != [yYnN] ]]
|
||||
then
|
||||
echo -e '\n\n\e[1;31mNot a valid answer, type "y" or "n"\e[0m'
|
||||
read -n 1 -p $'\e[1mWould you like to add another yubikey? (y/n): \e[0m' YUBIKEY
|
||||
elif [[ "$YUBIKEY" = [yY] ]]
|
||||
then
|
||||
read -n 1 -s -p $'\n\n\e[1;33mInsert the next yubikey and press the enter key to continue \e[0m'
|
||||
echo -e '\n\e[1mTouch the yubikey when it starts blinking\e[0m'
|
||||
|
||||
pamu2fcfg -n >> ~/.config/Yubico/u2f_keys
|
||||
|
||||
read -n 1 -p $'\n\e[1mWould you like to add another yubikey? (y/n): \e[0m' YUBIKEY
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e '\n\n\e[1;33mUpdating pam configs'
|
||||
echo -e 'Open another terminal or tty and login as sudo in case an issue comes up'
|
||||
read -n 1 -s -p $'Press the enter key once logged in as sudo in another terminal or tty \e[0m\n'
|
||||
|
||||
# System wide user authentication
|
||||
sudo sed -i '/^auth .* required .* pam_faillock.so .* authsucc/a\
|
||||
auth required pam_u2f.so' /etc/pam.d/system-auth
|
||||
|
||||
# Polkit authentication
|
||||
sudo sed -i '/^#%PAM.*/a\
|
||||
auth sufficient pam_u2f.so' /etc/pam.d/polkit-1
|
||||
|
||||
# Sudo authentication
|
||||
sudo sed -i '/^#%PAM.*/a\
|
||||
auth sufficient pam_u2f.so' /etc/pam.d/sudo
|
||||
|
||||
# KDE lockscreen authentication
|
||||
sudo sed -i '/^#%PAM.*/a\
|
||||
auth required pam_u2f.so' /etc/pam.d/kde
|
||||
|
||||
cat > ~/.local/functions/add-yubikey <<- 'ADDYUBIKEY'
|
||||
# Add a new yubikey
|
||||
function add-yubikey
|
||||
{
|
||||
read -n 1 -s -p $'\n\e[1;33mInsert your yubikey and press the enter key to continue \e[0m'
|
||||
echo -e '\n\e[1mTouch the yubikey when it starts blinking\e[0m'
|
||||
|
||||
pamu2fcfg -n >> ~/.config/Yubico/u2f_keys
|
||||
|
||||
read -n 1 -p $'\n\e[1mWould you like to add another yubikey? (y/n): \e[0m' YUBIKEY
|
||||
until [[ "$YUBIKEY" = [nN] ]]
|
||||
do
|
||||
if [[ "$YUBIKEY" != [yYnN] ]]
|
||||
then
|
||||
echo -e '\n\n\e[1;31mNot a valid answer, type "y" or "n"\e[0m'
|
||||
read -n 1 -p $'\e[1mWould you like to add another yubikey? (y/n): \e[0m' YUBIKEY
|
||||
elif [[ "$YUBIKEY" = [yY] ]]
|
||||
then
|
||||
read -n 1 -s -p $'\n\n\e[1;33mInsert the next yubikey and press the enter key to continue \e[0m'
|
||||
echo -e '\n\e[1mTouch the yubikey when it starts blinking\e[0m'
|
||||
|
||||
pamu2fcfg -n >> ~/.config/Yubico/u2f_keys
|
||||
|
||||
read -n 1 -p $'\n\e[1mWould you like to add another yubikey? (y/n): \e[0m' YUBIKEY
|
||||
fi
|
||||
done
|
||||
echo -e '\n\n\e[1;34mYubikeys updated'
|
||||
echo -e 'Exiting...\e[0m\n'
|
||||
}
|
||||
ADDYUBIKEY
|
||||
|
||||
echo -e '\n\e[1;34mYubikey setup completed'
|
||||
echo -e 'To update your saved yubikeys, run "add-yubikey" in the terminal'
|
||||
echo -e 'Exiting...\e[0m\n'
|
||||
rm -f ${0}
|
||||
Loading…
Add table
Add a link
Reference in a new issue