norisa.sh 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 root as $username\n" > /etc/doas.conf
  33. chown -c root:root /etc/doas.conf
  34. chmod -c 0400 /etc/doas.conf
  35. }
  36. create_new_user() {
  37. echo -e "\e[0;30;42m Enter your desired username \e[0m"
  38. read -rp " >>> " username
  39. useradd -m -g users -G wheel "$username"
  40. while true; do
  41. passwd "$username" && break
  42. done
  43. }
  44. choose_user() {
  45. echo -e "\e[0;30;46m Available users: \e[0m"
  46. ls /home
  47. while true; do
  48. echo -e "\e[0;30;42m Enter in your chosen user \e[0m"
  49. read -rp " >>> " username
  50. ls /home/ | grep -q "^$username$" && break
  51. done
  52. }
  53. # ask for new user if /home is not empty
  54. if [ "$(ls -A /home)" ]; then
  55. echo -e "\e[0;30;46m /home/ not empty, human users already available \e[0m"
  56. while true; do
  57. echo -e "\e[0;30;42m Do you want to create a new user? [y/n] \e[0m"
  58. read -rp " >>> " want_new_user
  59. if echo "$want_new_user" | grep -q "y\|Y"; then
  60. create_new_user; break
  61. elif echo "$want_new_user" | grep -q "n\|N"; then
  62. choose_user; break
  63. fi
  64. done
  65. fi
  66. # create ~/ directories
  67. echo -e "\e[0;30;34mCreating ~/ directories ...\e[0m"
  68. mkdir -vp /home/"$username"/dox /home/"$username"/pix /home/"$username"/dl
  69. mkdir -vp /home/"$username"/vids /home/"$username"/mus
  70. mkdir -vp /home/"$username"/.local/bin /home/"$username"/.config
  71. mkdir -vp /home/"$username"/.local/share /home/"$username"/.local/src
  72. echo -e "\e[0;30;34mChanging ownership of /home/$username ...\e[0m"
  73. chown -R "$username":users /home/"$username"/* /home/"$username"/.*
  74. setup_temporary_doas
  75. # install aur helper (paru)
  76. if ! pacman -Q | grep -q paru; then
  77. echo -e "\e[0;30;34mInstalling AUR helper (paru) ...\e[0m"
  78. cd_into /home/"$username"/.local/src
  79. pacman -S --noconfirm --needed asp bat devtools || pacman_error_exit
  80. curl -sO https://aur.archlinux.org/cgit/aur.git/snapshot/paru-bin.tar.gz &&
  81. tar xvf paru-bin.tar.gz
  82. cd_into /home/"$username" && chown -R "$username":wheel /home/"$username"/.local/src/ && cd_into .local/src
  83. cd_into paru-bin
  84. doas -u "$username" makepkg --noconfirm -si || pacman_error_exit
  85. rm /home/"$username"/.local/src/paru-bin.tar.gz
  86. fi
  87. # need to use piped yes as --noconfirm doesn't work with package conflicts
  88. if ! pacman -Q | grep -q libxft-bgra; then
  89. echo -e "\e[0;30;34mInstalling libxft-bgra ...\e[0m"
  90. yes | doas -u "$username" paru -S --needed libxft-bgra || pacman_error_exit
  91. fi
  92. # fetch dotfiles repo + apply dotfiles
  93. if [ ! -d /home/"$username"/.local/src/dotfiles ]; then
  94. echo -e "\e[0;30;34mFetching dotfiles ...\e[0m"
  95. cd_into /home/"$username"/.local/src
  96. git clone https://github.com/noahvogt/dotfiles.git
  97. fi
  98. c
  99. d_into /home/"$username"/.local/src/dotfiles
  100. echo -e "\e[0;30;34mApplying dotfiles ...\e[0m"
  101. doas -u "$username" /home/"$username"/.local/src/dotfiles/apply-dotfiles
  102. # download packages from the official repos
  103. echo -e "\e[0;30;34mInstalling packages from official repos ...\e[0m"
  104. 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 || pacman_error_exit
  105. # install aur packages
  106. echo -e "\e[0;30;34mInstalling packages from AUR ...\e[0m"
  107. doas -u "$username" paru -S --noconfirm --needed betterlockscreen simple-mtpfs redshift dashbinsh devour vim-plug lf-bin brave-bin picom-ibhagwan-git doasedit jdk-openjdk-xdg openssh-dotconfig wget-xdg networkmanager-openvpn-xdg abook-configdir || pacman_error_exit
  108. suckless_build() {
  109. if [ ! -d /home/"$username"/.local/src/"$1" ]; then
  110. echo -e "\e[0;30;34mFetching "$1" ...\e[0m"
  111. cd_into /home/"$username"/.local/src
  112. git clone https://github.com/noahvogt/"$1".git
  113. fi
  114. cd_into /home/"$username"/.local/src/"$1"
  115. if ! command -v "$1" > /dev/null; then
  116. echo -e "\e[0;30;34mCompiling "$1" ...\e[0m"
  117. make install || compile_error_exit
  118. fi
  119. }
  120. suckless_build dwm
  121. suckless_build st
  122. suckless_build dwmblocks
  123. suckless_build dmenu
  124. # set global zshenv
  125. echo -e "\e[0;30;34mSetting global zshenv ...\e[0m"
  126. mkdir -vp /etc/zsh
  127. echo "export ZDOTDIR=\$HOME/.config/zsh" > /etc/zsh/zshenv
  128. # make initial history file
  129. echo -e "\e[0;30;34mSetting initial zsh history file ...\e[0m"
  130. mkdir -vp /home/"$username"/.cache/zsh
  131. [ -f /home/"$username"/.cache/zsh/history ] ||
  132. touch /home/"$username"/.cache/zsh/history
  133. # make user to owner of ~/ and /mnt/
  134. echo -e "\e[0;30;34mChanging ownership of /home/$username + /mnt ...\e[0m"
  135. chown -R "$username":users /home/"$username"/
  136. chown -R "$username":users /mnt/
  137. # change shell to zsh
  138. echo -e "\e[0;30;34mSetting default shell to $(which zsh)...\e[0m"
  139. if ! grep "^$username.*::/home/$username" /etc/passwd | sed 's/^.*://' | \
  140. grep -q "^$(which zsh)$"; then
  141. while true; do
  142. doas -u "$username" chsh -s "$(which zsh)" && break
  143. done
  144. fi
  145. # enable tap to click
  146. echo -e "\e[0;30;34mEnabling tap to click ...\e[0m"
  147. [ ! -f /etc/X11/xorg.conf.d/40-libinput.conf ] && printf 'Section "InputClass"
  148. Identifier "libinput touchpad catchall"
  149. MatchIsTouchpad "on"
  150. MatchDevicePath "/dev/input/event*"
  151. Driver "libinput"
  152. # Enable left mouse button by tapping
  153. Option "Tapping" "on"
  154. EndSection' > /etc/X11/xorg.conf.d/40-libinput.conf
  155. setup_final_doas
  156. # cleanup
  157. echo -e "\e[0;30;34mCleaning up ...\e[0m"
  158. ls -A /home/"$username" | grep -q "\.bash" && rm /home/"$username"/.bash*
  159. ls -A /home/"$username" | grep -q "\.less" && rm /home/"$username"/.less*