videopc-bootstrap.sh 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #!/bin/bash
  2. # ASSUMED STATE OF TARGET SYSTEM:
  3. # - internet access
  4. # - root user login
  5. # - ~10 GB of free disk space
  6. # working 1.) base 2.) linux/kernel packages
  7. # install git, vim, stow, opendoas and (base-devel minus sudo)
  8. echo -e "\e[0;30;34mInstalling some initial packages ...\e[0m"
  9. 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 stow || { 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; }
  10. pacman_error_exit() {
  11. echo -e "\e[0;30;101m Error: Pacman command was not successfull. Exiting ...\e[0m"
  12. exit 1
  13. }
  14. compile_error_exit() {
  15. echo -e "\e[0;30;101m Error: Compilation command was not successfull. Exiting ...\e[0m"
  16. exit 1
  17. }
  18. cd_into() {
  19. cd "$1" || cd_error_exit "$1"
  20. }
  21. cd_error_exit() {
  22. echo -e "\e[0;30;46m Current working directory: \e[0m"
  23. pwd
  24. echo -e "\e[0;30;101m Error: Could not change into '$1'. Exiting ...\e[0m"
  25. exit 1
  26. }
  27. setup_temporary_doas() {
  28. echo -e "\e[0;30;34mSetting up temporary doas config ...\e[0m"
  29. printf "permit nopass :wheel
  30. permit nopass root as %s\n" "$username" > /etc/doas.conf
  31. chown -c root:root /etc/doas.conf
  32. chmod -c 0400 /etc/doas.conf
  33. }
  34. create_videopc_user() {
  35. if ls /home/ | grep -q "^$username$"; then
  36. return
  37. fi
  38. echo -e "\e[0;30;34mCreating videopc user ...\e[0m"
  39. username="videopc"
  40. useradd -m -g users -G wheel "$username"
  41. while true; do
  42. passwd "$username" && break
  43. done
  44. }
  45. choose_user() {
  46. echo -e "\e[0;30;46m Available users: \e[0m"
  47. ls /home
  48. while true; do
  49. echo -e "\e[0;30;42m Enter in your chosen user \e[0m"
  50. read -rp " >>> " username
  51. ls /home/ | grep -q "^$username$" && break
  52. done
  53. }
  54. set_rtmp_key() {
  55. echo -e "\e[0;30;34mSetting rtmp key... \e[0m"
  56. while true; do
  57. echo -e "\e[0;30;42m Enter in your RTMP key \e[0m"
  58. read -rp " >>> " rtmp_key
  59. echo "$rtmp_key" > /etc/videopc_rtmp_key
  60. [ -n "$rtmp_key" ] && break
  61. done
  62. }
  63. set_api_key() {
  64. echo -e "\e[0;30;34mSetting api key... \e[0m"
  65. while true; do
  66. echo -e "\e[0;30;42m Enter in your API key \e[0m"
  67. read -rp " >>> " api_key
  68. echo "$api_key" > /etc/videopc_api_key
  69. [ -n "$api_key" ] && break
  70. done
  71. }
  72. add_user_to_groups() {
  73. if ! groups "$username" | grep "input" | grep -q "video"; then
  74. echo -e "\e[0;30;34mAdding $username to video and input groups ... \e[0m"
  75. usermod -aG video "$username"
  76. usermod -aG input "$username"
  77. fi
  78. }
  79. ensure_history_file_exists() {
  80. if ! [ -f /home/"$username"/.cache/zsh/history ]; then
  81. echo -e "\e[0;30;34mEnsuring initial zsh history file exists ...\e[0m"
  82. mkdir -vp /home/"$username"/.cache/zsh
  83. touch /home/"$username"/.cache/zsh/history
  84. fi
  85. }
  86. change_login_shell_to_zsh() {
  87. if ! grep "^$username.*::/home/$username" /etc/passwd | sed 's/^.*://' | \
  88. grep -q "^$(which zsh)$"; then
  89. echo -e "\e[0;30;34mSetting default shell to $(which zsh)...\e[0m"
  90. chsh -s "$(which zsh)" "$username" || exit 1
  91. fi
  92. }
  93. make_user_owner_of_HOME_and_mnt_dirs() {
  94. echo -e "\e[0;30;34mChanging ownership of /home/$username + /mnt ...\e[0m"
  95. chown -R "$username":users /home/"$username"/
  96. chown -R "$username":users /mnt/
  97. }
  98. create_videopc_user
  99. # create ~/ directories
  100. echo -e "\e[0;30;34mCreating ~/ directories ...\e[0m"
  101. mkdir -vp /home/"$username"/dox /home/"$username"/pix /home/"$username"/dl
  102. mkdir -vp /home/"$username"/vids /home/"$username"/mus
  103. mkdir -vp /home/"$username"/.local/bin /home/"$username"/.config
  104. mkdir -vp /home/"$username"/.local/share /home/"$username"/.local/src
  105. echo -e "\e[0;30;34mChanging ownership of /home/$username ...\e[0m"
  106. chown -R "$username":users /home/"$username"/* /home/"$username"/.*
  107. setup_temporary_doas
  108. add_user_to_groups
  109. # add xdg-repo
  110. if ! grep -q "^\s*\[xdg-repo\]\s*$" /etc/pacman.conf; then
  111. echo -e "\e[0;30;34mAdding Noah's xdg-repo ...\e[0m"
  112. pacman-key --recv-keys 7FA7BB604F2A4346 --keyserver keyserver.ubuntu.com
  113. pacman-key --lsign-key 7FA7BB604F2A4346
  114. echo "[xdg-repo]
  115. Server = https://git.noahvogt.com/noah/\$repo/raw/master/\$arch" >> /etc/pacman.conf
  116. fi
  117. # add chaotic-aur
  118. if ! grep -q "^\s*\[chaotic-aur\]\s*$" /etc/pacman.conf; then
  119. echo -e "\e[0;30;34mAdding the chaotic aur repo ...\e[0m"
  120. pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
  121. pacman-key --lsign-key 3056513887B78AEB
  122. pacman -U --noconfirm --needed 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst'
  123. pacman -U --noconfirm --needed 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'
  124. echo "[chaotic-aur]
  125. Include = /etc/pacman.d/chaotic-mirrorlist" >> /etc/pacman.conf
  126. fi
  127. # sync all pkg db's
  128. pacman -Syyy
  129. # install aur helper (paru)
  130. if ! pacman -Q | grep -q paru; then
  131. echo -e "\e[0;30;34mInstalling AUR helper (paru) ...\e[0m"
  132. cd_into /home/"$username"/.local/src
  133. pacman -S --noconfirm --needed bat devtools || pacman_error_exit
  134. curl -sO https://aur.archlinux.org/cgit/aur.git/snapshot/paru-bin.tar.gz &&
  135. tar xvf paru-bin.tar.gz
  136. cd_into /home/"$username" && chown -R "$username":wheel /home/"$username"/.local/src/ && cd_into .local/src
  137. cd_into paru-bin
  138. while true; do
  139. # TODO: split command into makepkg and pacman -U, only loop 2nd one
  140. doas -u "$username" makepkg --noconfirm -si && break
  141. done
  142. rm /home/"$username"/.local/src/paru-bin.tar.gz
  143. fi
  144. # fetch + apply dotfiles
  145. if [ ! -d /home/"$username"/.local/src/dotfiles ]; then
  146. echo -e "\e[0;30;34mFetching dotfiles ...\e[0m"
  147. cd_into /home/"$username"/.local/src
  148. while true; do
  149. git clone https://git.noahvogt.com/noah/videopc-dotfiles.git && break
  150. done
  151. else
  152. echo -e "\e[0;30;34mUpdating dotfiles ...\e[0m"
  153. cd_into /home/"$username"/.local/src/dotfiles
  154. while true; do
  155. git pull && break
  156. done
  157. fi
  158. mv /home/"$username"/.local/src/videopc-dotfiles /home/"$username"/.local/src/dotfiles
  159. cd_into /home/"$username"/.local/src/dotfiles
  160. echo -e "\e[0;30;34mApplying dotfiles ...\e[0m"
  161. doas -u "$username" /home/"$username"/.local/src/dotfiles/apply-dotfiles
  162. set_rtmp_key
  163. set_api_key
  164. # download packages from the official repos
  165. # TODO: remove uneeded pkg's
  166. echo -e "\e[0;30;34mInstalling packages from repos ...\e[0m"
  167. pacman -S --noconfirm --needed xf86-video-vesa xf86-video-fbdev neovim ffmpeg arandr man-db python mediainfo pulseaudio-alsa ttf-linux-libertine noto-fonts-emoji xorg-setxkbmap dash neofetch htop wireless_tools mpv xorg-xinput cpupower zsh zsh-syntax-highlighting powertop zsh-autosuggestions xf86-video-amdgpu xf86-video-intel xf86-video-nouveau fzf dust lf ttf-jetbrains-mono-nerd foliate coreutils curl xorg-xrandr webp-pixbuf-loader wireplumber hyprland-git ttf-space-mono-nerd kitty opendoas-sudo adwaita-fake-cursors greetd-agreety openssh uvicorn python-fastapi wlr-randr || pacman_error_exit
  168. # install aur packages
  169. echo -e "\e[0;30;34mInstalling packages from AUR ...\e[0m"
  170. doas -u "$username" paru -S --noconfirm --needed dashbinsh doasedit mediamtx-bin || pacman_error_exit
  171. # enable mediamtx service
  172. echo -e "\e[0;30;34mEnabling mediamtx daemon ...\e[0m"
  173. systemctl enable mediamtx
  174. # set global zshenv
  175. echo -e "\e[0;30;34mSetting global zshenv ...\e[0m"
  176. mkdir -vp /etc/zsh
  177. echo "export ZDOTDIR=\$HOME/.config/zsh" > /etc/zsh/zshenv
  178. ensure_history_file_exists
  179. make_user_owner_of_HOME_and_mnt_dirs
  180. change_login_shell_to_zsh
  181. # setup autologin
  182. echo -e "\e[0;30;34mSetting up Autologin ...\e[0m"
  183. systemctl enable greetd
  184. if ! grep -q "\[initial_session\]" /etc/greetd/config.toml; then
  185. echo '[initial_session]
  186. command = "Hyprland"
  187. user = "videopc"' >> /etc/greetd/config.toml
  188. fi
  189. # enable sshd daemon
  190. echo -e "\e[0;30;34mEnabling sshd daemon ...\e[0m"
  191. systemctl enable sshd
  192. # ~ cleanup
  193. echo -e "\e[0;30;34mCleaning up \$HOME ...\e[0m"
  194. for f in /home/"$username"/.bash*; do
  195. [ -f "$f" ] && rm "$f"
  196. done
  197. for f in /home/"$username"/.less*; do
  198. [ -f "$f" ] && rm "$f"
  199. done