norisa.sh 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/bin/bash
  2. # install git, vim, opendoas and (base-devel minus sudo)
  3. echo -e "\e[0;30;34mInstalling some packages ...\e[0m"
  4. pacman -Sy --noconfirm --needed git vim opendoas autoconf automake binutils bison fakeroot file findutils flex gawk gcc gettext grep groff gzip libtool m4 make pacman patch pkgconf sed texinfo which || { 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"; exit 1; }
  5. pacman_error_exit() {
  6. echo -e "\e[0;30;101m Error: Pacman command was not successfull. Exiting ...\e[0m"
  7. exit 1
  8. }
  9. compile_error_exit() {
  10. echo -e "\e[0;30;101m Error: Compilation command was not successfull. Exiting ...\e[0m"
  11. exit 1
  12. }
  13. cd_into() {
  14. cd "$1" || cd_error_exit "$1"
  15. }
  16. cd_error_exit() {
  17. echo -e "\e[0;30;46m Current working directory: \e[0m"
  18. pwd
  19. echo -e "\e[0;30;101m Error: Could not change into '$1'. Exiting ...\e[0m"
  20. exit 1
  21. }
  22. setup_temporary_doas() {
  23. echo -e "\e[0;30;34mSetting up temporary doas config ...\e[0m"
  24. printf "permit nopass :wheel
  25. permit nopass root as $username\n" > /etc/doas.conf
  26. chown -c root:root /etc/doas.conf
  27. chmod -c 0400 /etc/doas.conf
  28. }
  29. setup_final_doas() {
  30. echo -e "\e[0;30;34mSetting up final doas config ...\e[0m"
  31. printf "permit persist :wheel
  32. permit nopass $username as root cmd mount
  33. permit nopass $username as root cmd umount
  34. permit nopass root as $username\n" > /etc/doas.conf
  35. chown -c root:root /etc/doas.conf
  36. chmod -c 0400 /etc/doas.conf
  37. }
  38. create_new_user() {
  39. echo -e "\e[0;30;42m Enter your desired username \e[0m"
  40. read -rp " >>> " username
  41. useradd -m -g users -G wheel "$username"
  42. while true; do
  43. passwd "$username" && break
  44. done
  45. }
  46. choose_user() {
  47. echo -e "\e[0;30;46m Available users: \e[0m"
  48. ls /home
  49. while true; do
  50. echo -e "\e[0;30;42m Enter in your chosen user \e[0m"
  51. read -rp " >>> " username
  52. ls /home/ | grep -q "^$username$" && break
  53. done
  54. }
  55. # ask for new user if /home is not empty
  56. if [ "$(ls -A /home)" ]; then
  57. echo -e "\e[0;30;46m /home/ not empty, human users already available \e[0m"
  58. while true; do
  59. echo -e "\e[0;30;42m Do you want to create a new user? [y/n] \e[0m"
  60. read -rp " >>> " want_new_user
  61. if echo "$want_new_user" | grep -q "y\|Y"; then
  62. create_new_user; break
  63. elif echo "$want_new_user" | grep -q "n\|N"; then
  64. choose_user; break
  65. fi
  66. done
  67. fi
  68. # create ~/ directories
  69. echo -e "\e[0;30;34mCreating ~/ directories ...\e[0m"
  70. mkdir -vp /home/"$username"/dox /home/"$username"/pix /home/"$username"/dl
  71. mkdir -vp /home/"$username"/vids /home/"$username"/mus
  72. mkdir -vp /home/"$username"/.local/bin /home/"$username"/.config
  73. mkdir -vp /home/"$username"/.local/share /home/"$username"/.local/src
  74. echo -e "\e[0;30;34mChanging ownership of /home/$username ...\e[0m"
  75. chown -R "$username":users /home/"$username"/* /home/"$username"/.*
  76. setup_temporary_doas
  77. # install aur helper (paru)
  78. if ! pacman -Q | grep -q paru; then
  79. echo -e "\e[0;30;34mInstalling AUR helper (paru) ...\e[0m"
  80. cd_into /home/"$username"/.local/src
  81. pacman -S --noconfirm --needed asp bat devtools || pacman_error_exit
  82. curl -sO https://aur.archlinux.org/cgit/aur.git/snapshot/paru-bin.tar.gz &&
  83. tar xvf paru-bin.tar.gz
  84. cd_into /home/"$username" && chown -R "$username":wheel /home/"$username"/.local/src/ && cd_into .local/src
  85. cd_into paru-bin
  86. doas -u "$username" makepkg --noconfirm -si || pacman_error_exit
  87. rm /home/"$username"/.local/src/paru-bin.tar.gz
  88. fi
  89. # need to use piped yes as --noconfirm doesn't work with package conflicts
  90. if ! pacman -Q | grep -q libxft-bgra; then
  91. echo -e "\e[0;30;34mInstalling libxft-bgra ...\e[0m"
  92. yes | doas -u "$username" paru -S --needed libxft-bgra || pacman_error_exit
  93. fi
  94. # fetch dotfiles repo + apply dotfiles
  95. if [ ! -d /home/"$username"/.local/src/dotfiles ]; then
  96. echo -e "\e[0;30;34mFetching dotfiles ...\e[0m"
  97. cd_into /home/"$username"/.local/src
  98. git clone https://github.com/noahvogt/dotfiles.git
  99. fi
  100. c
  101. d_into /home/"$username"/.local/src/dotfiles
  102. echo -e "\e[0;30;34mApplying dotfiles ...\e[0m"
  103. doas -u "$username" /home/"$username"/.local/src/dotfiles/apply-dotfiles
  104. # download packages from the official repos
  105. echo -e "\e[0;30;34mInstalling packages from official repos ...\e[0m"
  106. pacman -S --noconfirm --needed xorg-server xorg-xinit xorg-xwininfo xorg-xprop xorg-xbacklight xorg-xdpyinfo xorg-xsetroot xbindkeys xf86-video-vesa xf86-video-fbdev libxinerama geogebra 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-most dash neofetch htop wireless_tools alsa-utils acpi zip libreoffice nm-connection-editor dunst libnotify dosfstools tlp 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 tlp ccls mpd mpc ncmpcpp pavucontrol strawberry smartmontools firefox python-pynvim python-pylint element-desktop tesseract-data-deu tesseract-data-eng || pacman_error_exit
  107. # install aur packages
  108. echo -e "\e[0;30;34mInstalling packages from AUR ...\e[0m"
  109. doas -u "$username" paru -S --noconfirm --needed betterlockscreen simple-mtpfs redshift dashbinsh devour vim-plug lf-bin picom-jonaburg-fix doasedit jdk-openjdk-xdg openssh-dotconfig wget-xdg networkmanager-openvpn-xdg abook-configdir ungoogled-chromium-xdg-bin nerd-fonts-jetbrains-mono-160 electron-xdg-bin yarn-xdg-bin || pacman_error_exit
  110. suckless_build() {
  111. if [ ! -d /home/"$username"/.local/src/"$1" ]; then
  112. echo -e "\e[0;30;34mFetching "$1" ...\e[0m"
  113. cd_into /home/"$username"/.local/src
  114. git clone https://github.com/noahvogt/"$1".git
  115. fi
  116. cd_into /home/"$username"/.local/src/"$1"
  117. if ! command -v "$1" > /dev/null; then
  118. echo -e "\e[0;30;34mCompiling "$1" ...\e[0m"
  119. make install || compile_error_exit
  120. fi
  121. }
  122. dwm_build() {
  123. if [ ! -d /home/"$username"/.local/src/"$1" ]; then
  124. echo -e "\e[0;30;34mFetching "$1" ...\e[0m"
  125. cd_into /home/"$username"/.local/src
  126. git clone https://github.com/noahvogt/"$1".git --depth 1
  127. fi
  128. mv /home/"$username"/.local/src/"$1" /home/"$username"/.config
  129. cd_into /home/"$username"/.config/"$1"
  130. if ! command -v "$1" > /dev/null; then
  131. echo -e "\e[0;30;34mCompiling "$1" ...\e[0m"
  132. make install || compile_error_exit
  133. fi
  134. }
  135. dwm_build chadwm
  136. suckless_build st
  137. suckless_build dwmblocks
  138. suckless_build dmenu
  139. # set global zshenv
  140. echo -e "\e[0;30;34mSetting global zshenv ...\e[0m"
  141. mkdir -vp /etc/zsh
  142. echo "export ZDOTDIR=\$HOME/.config/zsh" > /etc/zsh/zshenv
  143. # make initial history file
  144. echo -e "\e[0;30;34mSetting initial zsh history file ...\e[0m"
  145. mkdir -vp /home/"$username"/.cache/zsh
  146. [ -f /home/"$username"/.cache/zsh/history ] ||
  147. touch /home/"$username"/.cache/zsh/history
  148. # make user to owner of ~/ and /mnt/
  149. echo -e "\e[0;30;34mChanging ownership of /home/$username + /mnt ...\e[0m"
  150. chown -R "$username":users /home/"$username"/
  151. chown -R "$username":users /mnt/
  152. # change shell to zsh
  153. echo -e "\e[0;30;34mSetting default shell to $(which zsh)...\e[0m"
  154. if ! grep "^$username.*::/home/$username" /etc/passwd | sed 's/^.*://' | \
  155. grep -q "^$(which zsh)$"; then
  156. while true; do
  157. doas -u "$username" chsh -s "$(which zsh)" && break
  158. done
  159. fi
  160. # enable tap to click
  161. echo -e "\e[0;30;34mEnabling tap to click ...\e[0m"
  162. [ ! -f /etc/X11/xorg.conf.d/40-libinput.conf ] && printf 'Section "InputClass"
  163. Identifier "libinput touchpad catchall"
  164. MatchIsTouchpad "on"
  165. MatchDevicePath "/dev/input/event*"
  166. Driver "libinput"
  167. # Enable left mouse button by tapping
  168. Option "Tapping" "on"
  169. EndSection' > /etc/X11/xorg.conf.d/40-libinput.conf
  170. setup_final_doas
  171. # cleanup
  172. echo -e "\e[0;30;34mCleaning up ...\e[0m"
  173. ls -A /home/"$username" | grep -q "\.bash" && rm /home/"$username"/.bash*
  174. ls -A /home/"$username" | grep -q "\.less" && rm /home/"$username"/.less*