norisa.sh 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #!/bin/bash
  2. # ASSUMED STATE OF TARGET SYSTEM:
  3. # - internet access
  4. # - root user login
  5. # - ~30 GB of free disk space
  6. # working 1.) base 2.) linux packages
  7. # Install opendoas and (base-devel, devtools minus sudo), libxft
  8. echo -e "\e[0;30;34mInstalling some initial packages ...\e[0m"
  9. pacman -Sy --noconfirm --needed archlinux-keyring opendoas autoconf automake binutils bison debugedit fakeroot file findutils flex gawk gcc gettext grep groff gzip libtool m4 make pacman patch pkgconf sed texinfo which libxft breezy coreutils curl diffutils expac git glow gum jq mercurial openssh parallel reuse rsync subversion util-linux || {
  10. echo -e "\e[0;30;101m Error at script start:\n\nAre you sure you're running this as the root user?\n\t(Tip: run 'whoami' to check)\n\nAre you sure you have an internet connection?\n\t(Tip: run 'ip a' to check)\n\e[0m"
  11. exit 1
  12. }
  13. pacman_error_exit() {
  14. echo -e "\e[0;30;101m Error: Pacman command was not successfull. Exiting ...\e[0m"
  15. exit 1
  16. }
  17. compile_error_exit() {
  18. echo -e "\e[0;30;101m Error: Compilation command was not successfull. Exiting ...\e[0m"
  19. exit 1
  20. }
  21. cd_into() {
  22. cd "$1" || cd_error_exit "$1"
  23. }
  24. cd_error_exit() {
  25. echo -e "\e[0;30;46m Current working directory: \e[0m"
  26. pwd
  27. echo -e "\e[0;30;101m Error: Could not change into '$1'. Exiting ...\e[0m"
  28. exit 1
  29. }
  30. setup_temporary_doas() {
  31. echo -e "\e[0;30;34mSetting up temporary doas config ...\e[0m"
  32. printf "permit nopass :wheel
  33. permit nopass root as $username\n" >/etc/doas.conf
  34. chown -c root:root /etc/doas.conf
  35. chmod -c 0400 /etc/doas.conf
  36. }
  37. setup_final_doas() {
  38. echo -e "\e[0;30;34mSetting up final doas config ...\e[0m"
  39. printf "permit persist :wheel
  40. permit nopass $username as root cmd mount
  41. permit nopass $username as root cmd umount
  42. permit nopass root as $username\n" >/etc/doas.conf
  43. chown -c root:root /etc/doas.conf
  44. chmod -c 0400 /etc/doas.conf
  45. }
  46. create_new_user() {
  47. echo -e "\e[0;30;42m Enter your desired username \e[0m"
  48. read -rp " >>> " username
  49. useradd -m -g users -G wheel "$username"
  50. while true; do
  51. passwd "$username" && break
  52. done
  53. }
  54. choose_user() {
  55. echo -e "\e[0;30;46m Available users: \e[0m"
  56. ls /home
  57. while true; do
  58. echo -e "\e[0;30;42m Enter in your chosen user \e[0m"
  59. read -rp " >>> " username
  60. ls /home/ | grep -q "^$username$" && break
  61. done
  62. }
  63. add_user_to_groups() {
  64. if ! groups "$username" | grep "input" | grep -q "video"; then
  65. echo -e "\e[0;30;34mAdding $username to video and input groups ... \e[0m"
  66. usermod -aG video "$username"
  67. usermod -aG input "$username"
  68. fi
  69. }
  70. ensure_history_file_exists() {
  71. if ! [ -f /home/"$username"/.cache/zsh/history ]; then
  72. echo -e "\e[0;30;34mEnsuring initial zsh history file exists ...\e[0m"
  73. mkdir -vp /home/"$username"/.cache/zsh
  74. touch /home/"$username"/.cache/zsh/history
  75. fi
  76. }
  77. change_login_shell_to_zsh() {
  78. if ! grep "^$username.*::/home/$username" /etc/passwd | sed 's/^.*://' |
  79. grep -q "^$(which zsh)$"; then
  80. echo -e "\e[0;30;34mSetting default shell to $(which zsh)...\e[0m"
  81. chsh -s "$(which zsh)" "$username" || exit 1
  82. fi
  83. }
  84. make_user_owner_of_HOME_and_mnt_dirs() {
  85. echo -e "\e[0;30;34mChanging ownership of /home/$username + /mnt ...\e[0m"
  86. chown -R "$username":users /home/"$username"/
  87. chown -R "$username":users /mnt/
  88. }
  89. # Check if /home is not empty
  90. if [ -d /home ]; then
  91. mapfile -t home_users < <(ls -A /home)
  92. user_count=${#home_users[@]}
  93. else
  94. user_count=0
  95. fi
  96. if [ "$user_count" -eq 1 ]; then
  97. username="${home_users[0]}"
  98. echo -e "\e[0;30;46m A single user was found: $username \e[0m"
  99. elif [ "$user_count" -gt 1 ]; then
  100. echo -e "\e[0;30;46m /home/ not empty, $user_count users already available \e[0m"
  101. while true; do
  102. echo -e "\e[0;30;42m Do you want to create another user? [y/n] \e[0m"
  103. read -rp " >>> " want_new_user
  104. if [[ "$want_new_user" =~ ^[yY]$ ]]; then
  105. create_new_user
  106. break
  107. elif [[ "$want_new_user" =~ ^[nN]$ ]]; then
  108. choose_user
  109. break
  110. fi
  111. done
  112. else
  113. want_new_user=y
  114. create_new_user
  115. fi
  116. # Create ~/ Directories
  117. echo -e "\e[0;30;34mCreating ~/ directories ...\e[0m"
  118. mkdir -vp /home/"$username"/dox /home/"$username"/pix /home/"$username"/dl
  119. mkdir -vp /home/"$username"/vids /home/"$username"/mus
  120. mkdir -vp /home/"$username"/.local/bin /home/"$username"/.config
  121. mkdir -vp /home/"$username"/.local/share /home/"$username"/.local/src
  122. if [[ "$want_new_user" =~ ^[yY]$ ]]; then
  123. echo -e "\e[0;30;34mChanging ownership of /home/$username ...\e[0m"
  124. chown -R "$username":users /home/"$username"/* /home/"$username"/.*
  125. fi
  126. setup_temporary_doas
  127. add_user_to_groups
  128. # add xdg-repo
  129. # if ! grep -q "^\s*\[xdg-repo\]\s*$" /etc/pacman.conf; then
  130. # echo -e "\e[0;30;34mAdding Noah's xdg-repo ...\e[0m"
  131. # pacman-key --recv-keys 7FA7BB604F2A4346 --keyserver keyserver.ubuntu.com
  132. # pacman-key --lsign-key 7FA7BB604F2A4346
  133. # echo "[xdg-repo]
  134. # Server = https://git.noahvogt.com/noah/\$repo/raw/master/\$arch" >> /etc/pacman.conf
  135. # fi
  136. # Add chaotic-aur
  137. if ! grep -q "^\s*\[chaotic-aur\]\s*$" /etc/pacman.conf; then
  138. echo -e "\e[0;30;34mAdding the chaotic aur repo ...\e[0m"
  139. pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
  140. pacman-key --lsign-key 3056513887B78AEB
  141. pacman -U --noconfirm 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst'
  142. pacman -U --noconfirm 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'
  143. echo "[chaotic-aur]
  144. Include = /etc/pacman.d/chaotic-mirrorlist" >>/etc/pacman.conf
  145. fi
  146. # Sync all Package db's
  147. pacman -Syyy
  148. # Install AUR Helper (paru as paru-bin is out-of-date)
  149. if ! pacman -Q | grep -q paru; then
  150. echo -e "\e[0;30;34mInstalling AUR helper (paru) ...\e[0m"
  151. pacman -S --noconfirm paru
  152. fi
  153. # Symlink sudo to doas for Compatibility with paru and hardcoded PKGBUILDs
  154. echo -e "\e[0;30;34mSymlinking sudo to doas ...\e[0m"
  155. if [ ! -f /usr/bin/sudo ]; then
  156. ln -s /usr/bin/doas /usr/bin/sudo
  157. fi
  158. # Fetch + Apply Dotfiles
  159. if [ ! -d /home/"$username"/.local/src/dotfiles ]; then
  160. echo -e "\e[0;30;34mFetching dotfiles ...\e[0m"
  161. cd_into /home/"$username"/.local/src
  162. while true; do
  163. git clone https://git.noahvogt.com/noah/dotfiles.git && break
  164. done
  165. fi
  166. cd_into /home/"$username"/.local/src/dotfiles
  167. echo -e "\e[0;30;34mApplying dotfiles ...\e[0m"
  168. doas -u "$username" /home/"$username"/.local/src/dotfiles/apply-dotfiles
  169. # Download Packages from the Official Repos
  170. # TODO: add element-desktop back
  171. echo -e "\e[0;30;34mInstalling packages from official repos ...\e[0m"
  172. pacman -S --noconfirm --needed xorg-server xf86-video-vesa xf86-video-fbdev shellcheck neovim ranger xournalpp ffmpeg obs-studio sxiv arandr man-db brightnessctl unzip python mupdf-gl mediainfo highlight pulseaudio-alsa pulsemixer pamixer ttf-linux-libertine calcurse xclip noto-fonts-emoji imagemagick gimp xorg-setxkbmap wavemon texlive dash unifetch htop wireless_tools alsa-utils acpi zip libreoffice nm-connection-editor dunst libnotify dosfstools mpv xorg-xinput cpupower zsh zsh-syntax-highlighting newsboat nomacs pcmanfm openbsd-netcat powertop mupdf-tools nomacs stow zsh-autosuggestions xf86-video-amdgpu xf86-video-intel xf86-video-nouveau npm fzf unclutter ccls mpd mpc ncmpcpp pavucontrol strawberry smartmontools firefox python-pynvim python-pylint tesseract-data-deu tesseract-data-eng keepassxc ueberzug img2pdf dust ctags python-wand python-termcolor python-black jdk-openjdk ripgrep lf ungoogled-chromium-bin ttf-jetbrains-mono-nerd foliate coreutils curl fish foot fuzzel gjs gnome-bluetooth-3.0 gnome-control-center gnome-keyring gobject-introspection grim gtk3 gtk-layer-shell libdbusmenu-gtk3 meson nlohmann-json plasma-browser-integration playerctl polkit-gnome python-pywal sassc slurp swayidle typescript xorg-xrandr webp-pixbuf-loader wireplumber yad ydotool gojq hyprland python-poetry python-build python-pillow ttf-material-symbols-variable-git ttf-space-mono-nerd wlogout kitty shfmt ruff luarocks rust-analyzer hyprland-guiutils waybar socat hyprlock brave-bin clang swaync bat wl-clipboard syncthing python-debug ghostty awww kitty tokei gemini-cli hypridle tlp || pacman_error_exit
  173. # Install AUR Packages
  174. echo -e "\e[0;30;34mInstalling packages from AUR ...\e[0m"
  175. doas -u "$username" paru -S --noconfirm --needed simple-mtpfs redshift dashbinsh cspell-lsp doasedit nodejs-cspell nvim-lazy google-java-format lexend-fonts-git || pacman_error_exit
  176. # Set Global zshenv
  177. echo -e "\e[0;30;34mSetting global zshenv ...\e[0m"
  178. mkdir -vp /etc/zsh
  179. echo "export ZDOTDIR=\$HOME/.config/zsh" >/etc/zsh/zshenv
  180. ensure_history_file_exists
  181. make_user_owner_of_HOME_and_mnt_dirs
  182. change_login_shell_to_zsh
  183. setup_final_doas
  184. # ~/ Cleanup
  185. echo -e "\e[0;30;34mCleaning up \$HOME ...\e[0m"
  186. for f in /home/"$username"/.bash*; do
  187. [ -f "$f" ] && rm "$f"
  188. done
  189. for f in /home/"$username"/.less*; do
  190. [ -f "$f" ] && rm "$f"
  191. done