videopc-bootstrap.sh 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. set_rtmp_key() {
  46. echo -e "\e[0;30;34mSetting rtmp key... \e[0m"
  47. while true; do
  48. echo -e "\e[0;30;42m Enter in your RTMP key \e[0m"
  49. read -rp " >>> " rtmp_key
  50. echo "$rtmp_key" > /etc/videopc_rtmp_key
  51. [ -n "$rtmp_key" ] && break
  52. done
  53. }
  54. set_api_key() {
  55. echo -e "\e[0;30;34mSetting api key... \e[0m"
  56. while true; do
  57. echo -e "\e[0;30;42m Enter in your API key \e[0m"
  58. read -rp " >>> " api_key
  59. echo "$api_key" > /etc/videopc_api_key
  60. [ -n "$api_key" ] && 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. make_user_owner_of_HOME_and_mnt_dirs() {
  71. echo -e "\e[0;30;34mChanging ownership of /home/$username + /mnt ...\e[0m"
  72. chown -R "$username":users /home/"$username"/
  73. chown -R "$username":users /mnt/
  74. }
  75. create_videopc_user
  76. # create ~/ directories
  77. echo -e "\e[0;30;34mCreating ~/ directories ...\e[0m"
  78. mkdir -vp /home/"$username"/dox /home/"$username"/pix /home/"$username"/dl
  79. mkdir -vp /home/"$username"/vids /home/"$username"/mus
  80. mkdir -vp /home/"$username"/.local/bin /home/"$username"/.config
  81. mkdir -vp /home/"$username"/.local/share /home/"$username"/.local/src
  82. echo -e "\e[0;30;34mChanging ownership of /home/$username ...\e[0m"
  83. chown -R "$username":users /home/"$username"/* /home/"$username"/.*
  84. setup_temporary_doas
  85. add_user_to_groups
  86. # add xdg-repo
  87. if ! grep -q "^\s*\[xdg-repo\]\s*$" /etc/pacman.conf; then
  88. echo -e "\e[0;30;34mAdding Noah's xdg-repo ...\e[0m"
  89. pacman-key --recv-keys 7FA7BB604F2A4346 --keyserver keyserver.ubuntu.com
  90. pacman-key --lsign-key 7FA7BB604F2A4346
  91. echo "[xdg-repo]
  92. Server = https://noahvogt.com/\$repo/\$arch" >> /etc/pacman.conf
  93. fi
  94. # add chaotic-aur
  95. if ! grep -q "^\s*\[chaotic-aur\]\s*$" /etc/pacman.conf; then
  96. echo -e "\e[0;30;34mAdding the chaotic aur repo ...\e[0m"
  97. pacman-key --recv-key 3056513887B78AEB --keyserver keyserver.ubuntu.com
  98. pacman-key --lsign-key 3056513887B78AEB
  99. pacman -U --noconfirm --needed 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-keyring.pkg.tar.zst'
  100. pacman -U --noconfirm --needed 'https://cdn-mirror.chaotic.cx/chaotic-aur/chaotic-mirrorlist.pkg.tar.zst'
  101. echo "[chaotic-aur]
  102. Include = /etc/pacman.d/chaotic-mirrorlist" >> /etc/pacman.conf
  103. fi
  104. # fetch + apply dotfiles
  105. if [ ! -d /home/"$username"/.local/src/dotfiles ]; then
  106. echo -e "\e[0;30;34mFetching dotfiles ...\e[0m"
  107. cd_into /home/"$username"/.local/src
  108. while true; do
  109. git clone https://git.noahvogt.com/noah/videopc-infra.git && break
  110. done
  111. else
  112. echo -e "\e[0;30;34mUpdating dotfiles ...\e[0m"
  113. cd_into /home/"$username"/.local/src/dotfiles
  114. while true; do
  115. git pull && break
  116. done
  117. fi
  118. mv /home/"$username"/.local/src/videopc-infra /home/"$username"/.local/src/dotfiles
  119. cd_into /home/"$username"/.local/src/dotfiles
  120. echo -e "\e[0;30;34mApplying dotfiles ...\e[0m"
  121. doas -u "$username" /home/"$username"/.local/src/dotfiles/apply-dotfiles
  122. set_rtmp_key
  123. set_api_key
  124. # download packages from the official repos
  125. echo -e "\e[0;30;34mInstalling packages from repos ...\e[0m"
  126. pacman -Sy --noconfirm --needed neovim ffmpeg pulseaudio-alsa mpv xf86-video-amdgpu xf86-video-intel xf86-video-nouveau coreutils curl hyprland kitty opendoas-sudo adwaita-fake-cursors greetd-agreety openssh uvicorn python-fastapi paru || pacman_error_exit
  127. # install aur packages
  128. echo -e "\e[0;30;34mInstalling packages from AUR ...\e[0m"
  129. doas -u "$username" paru -S --noconfirm --needed mediamtx-bin || pacman_error_exit
  130. # enable mediamtx service
  131. echo -e "\e[0;30;34mEnabling mediamtx daemon ...\e[0m"
  132. systemctl enable mediamtx
  133. make_user_owner_of_HOME_and_mnt_dirs
  134. # setup autologin
  135. echo -e "\e[0;30;34mSetting up Autologin ...\e[0m"
  136. systemctl enable greetd
  137. if ! grep -q "\[initial_session\]" /etc/greetd/config.toml; then
  138. echo '[initial_session]
  139. command = "Hyprland"
  140. user = "videopc"' >> /etc/greetd/config.toml
  141. fi
  142. # enable sshd daemon
  143. echo -e "\e[0;30;34mEnabling sshd daemon ...\e[0m"
  144. systemctl enable sshd
  145. # ~ cleanup
  146. echo -e "\e[0;30;34mCleaning up \$HOME ...\e[0m"
  147. for f in /home/"$username"/.bash*; do
  148. [ -f "$f" ] && rm "$f"
  149. done
  150. for f in /home/"$username"/.less*; do
  151. [ -f "$f" ] && rm "$f"
  152. done