norisa.sh 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 libxft || { 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. # give info 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. fi
  59. while true; do
  60. echo -e "\e[0;30;42m Do you want to create a new user? [y/n] \e[0m"
  61. read -rp " >>> " want_new_user
  62. if echo "$want_new_user" | grep -q "y\|Y"; then
  63. create_new_user; break
  64. elif echo "$want_new_user" | grep -q "n\|N"; then
  65. choose_user; break
  66. fi
  67. done
  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. # fetch dotfiles repo + apply dotfiles
  90. if [ ! -d /home/"$username"/.local/src/dotfiles ]; then
  91. echo -e "\e[0;30;34mFetching dotfiles ...\e[0m"
  92. cd_into /home/"$username"/.local/src
  93. git clone https://github.com/noahvogt/dotfiles.git
  94. fi
  95. c
  96. d_into /home/"$username"/.local/src/dotfiles
  97. echo -e "\e[0;30;34mApplying dotfiles ...\e[0m"
  98. doas -u "$username" /home/"$username"/.local/src/dotfiles/apply-dotfiles
  99. # download packages from the official repos
  100. echo -e "\e[0;30;34mInstalling packages from official repos ...\e[0m"
  101. 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 keepassxc ueberzug img2pdf dust ctags python-wand python-termcolor python-black jdk-openjdk ripgrep || pacman_error_exit
  102. # install aur packages
  103. echo -e "\e[0;30;34mInstalling packages from AUR ...\e[0m"
  104. doas -u "$username" paru -S --noconfirm --needed betterlockscreen simple-mtpfs redshift dashbinsh devour vim-plug lf-bin picom-jonaburg-fix doasedit openssh-dotconfig wget-xdg networkmanager-openvpn-xdg abook-configdir ungoogled-chromium-xdg-bin nerd-fonts-jetbrains-mono-160 electron-xdg-bin yarn-xdg-bin chromium-extension-clearurls chromium-extension-copy-url-on-hover-bin chromium-extension-decentraleyes chromium-extension-history-disabler-bin chromium-extension-https-everywhere chromium-extension-keepassxc-browser-bin chromium-extension-return-youtube-dislike chromium-extension-rggl-bin chromium-extension-ublock-origin-bin || pacman_error_exit
  105. suckless_build() {
  106. if [ ! -d /home/"$username"/.local/src/"$1" ]; then
  107. echo -e "\e[0;30;34mFetching "$1" ...\e[0m"
  108. cd_into /home/"$username"/.local/src
  109. git clone https://github.com/noahvogt/"$1".git
  110. fi
  111. cd_into /home/"$username"/.local/src/"$1"
  112. if ! command -v "$1" > /dev/null; then
  113. echo -e "\e[0;30;34mCompiling "$1" ...\e[0m"
  114. make install || compile_error_exit
  115. fi
  116. }
  117. dwm_build() {
  118. if [ ! -d /home/"$username"/.local/src/"$1" ]; then
  119. echo -e "\e[0;30;34mFetching "$1" ...\e[0m"
  120. cd_into /home/"$username"/.local/src
  121. git clone https://github.com/noahvogt/"$1".git --depth 1
  122. fi
  123. mv /home/"$username"/.local/src/"$1" /home/"$username"/.config
  124. cd_into /home/"$username"/.config/"$1"
  125. if ! command -v "$1" > /dev/null; then
  126. echo -e "\e[0;30;34mCompiling "$1" ...\e[0m"
  127. make install || compile_error_exit
  128. fi
  129. }
  130. suckless_build st
  131. suckless_build dwmblocks
  132. suckless_build dmenu
  133. # set global zshenv
  134. echo -e "\e[0;30;34mSetting global zshenv ...\e[0m"
  135. mkdir -vp /etc/zsh
  136. echo "export ZDOTDIR=\$HOME/.config/zsh" > /etc/zsh/zshenv
  137. # make initial history file
  138. echo -e "\e[0;30;34mSetting initial zsh history file ...\e[0m"
  139. mkdir -vp /home/"$username"/.cache/zsh
  140. [ -f /home/"$username"/.cache/zsh/history ] ||
  141. touch /home/"$username"/.cache/zsh/history
  142. # make user to owner of ~/ and /mnt/
  143. echo -e "\e[0;30;34mChanging ownership of /home/$username + /mnt ...\e[0m"
  144. chown -R "$username":users /home/"$username"/
  145. chown -R "$username":users /mnt/
  146. # change shell to zsh
  147. echo -e "\e[0;30;34mSetting default shell to $(which zsh)...\e[0m"
  148. if ! grep "^$username.*::/home/$username" /etc/passwd | sed 's/^.*://' | \
  149. grep -q "^$(which zsh)$"; then
  150. while true; do
  151. doas -u "$username" chsh -s "$(which zsh)" && break
  152. done
  153. fi
  154. # enable tap to click
  155. echo -e "\e[0;30;34mEnabling tap to click ...\e[0m"
  156. [ ! -f /etc/X11/xorg.conf.d/40-libinput.conf ] && printf 'Section "InputClass"
  157. Identifier "libinput touchpad catchall"
  158. MatchIsTouchpad "on"
  159. MatchDevicePath "/dev/input/event*"
  160. Driver "libinput"
  161. # Enable left mouse button by tapping
  162. Option "Tapping" "on"
  163. EndSection' > /etc/X11/xorg.conf.d/40-libinput.conf
  164. setup_final_doas
  165. # cleanup
  166. echo -e "\e[0;30;34mCleaning up ...\e[0m"
  167. ls -A /home/"$username" | grep -q "\.bash" && rm /home/"$username"/.bash*
  168. ls -A /home/"$username" | grep -q "\.less" && rm /home/"$username"/.less*