You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
6.6 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. #!/bin/sh
  2. DIR="$(realpath "$(dirname "$0")")"
  3. root_setup() {
  4. # script must start at home directory
  5. cd "$HOME" || exit 1;
  6. usertest() {
  7. if test "$(id -u)" -ne 0; then
  8. echo "You must run this script as root.";
  9. exit 1;
  10. fi
  11. }
  12. createuser() {
  13. printf 'full name: ' >&2
  14. read -r NAME
  15. printf 'login: ' >&2
  16. read -r LOGIN
  17. adduser -g "$NAME" "$LOGIN" || exit 1
  18. adduser "$LOGIN" video || exit 1
  19. adduser "$LOGIN" input || exit 1
  20. adduser "$LOGIN" wheel || exit 1
  21. adduser root wheel || exit 1
  22. }
  23. installdoas() {
  24. apk add doas alpine-conf
  25. echo "permit nopass :wheel" >> /etc/doas.d/doas.conf
  26. }
  27. if test -z "$DOCKERBUILD"; then
  28. usertest && createuser && installdoas
  29. else
  30. usertest && installdoas
  31. fi
  32. }
  33. user_setup() {
  34. cd "$HOME" || exit 1;
  35. help_text() {
  36. cat <<EOF
  37. ./install_alpine.sh user [options]
  38. Options:
  39. -F,--nfs install aliases for connecting to nases
  40. -G,--graphical install xorg and wm
  41. -N,--nvim install neovim
  42. -C,--cp install competitive programming scripts
  43. EOF
  44. }
  45. GRAPHICAL=
  46. CP=
  47. NVIM=
  48. NFS=
  49. while test $# -ne 0; do
  50. case $1 in
  51. -G|--graphical)
  52. GRAPHICAL=1
  53. ;;
  54. -C|--cp)
  55. CP=1
  56. ;;
  57. -N|--nvim)
  58. NVIM=1
  59. ;;
  60. -F|--nfs)
  61. NFS=1
  62. ;;
  63. *)
  64. echo "invalid option $1"
  65. help_text
  66. exit
  67. ;;
  68. esac
  69. shift
  70. done
  71. if ! (apk list | grep 'doas' 2>&1) > /dev/null; then
  72. echo "doas is not installed.";
  73. exit 1
  74. fi
  75. dev() {
  76. echo "Developer tools..."
  77. doas sed -i "s|#http|http|g" /etc/apk/repositories
  78. doas apk update
  79. doas apk add build-base python3 nodejs npm go curl bash shadow git || exit 1
  80. if ! test -z "$NVIM"; then
  81. doas apk add cargo
  82. fi
  83. }
  84. sysinfo() {
  85. echo "Dylan Araps scripts"
  86. cd "$HOME" || exit 1;
  87. mkdir -p repos
  88. git clone https://github.com/dylanaraps/pfetch "$HOME/repos/pfetch"
  89. git clone https://github.com/dylanaraps/neofetch "$HOME/repos/neofetch"
  90. git clone https://github.com/dylanaraps/fff "$HOME/repos/fff"
  91. cd "$HOME/repos/pfetch" || exit 1;
  92. doas make install || exit 2;
  93. cd "$HOME" || exit 1;
  94. cd "$HOME/repos/neofetch" || exit 1;
  95. doas make install || exit 2;
  96. cd "$HOME" || exit 1;
  97. cd "$HOME/repos/fff" || exit 1;
  98. doas make install || exit 2;
  99. cd "$HOME" || exit 1;
  100. }
  101. dotfiles() {
  102. echo "Adding zsh and tmux configs"
  103. # zsh plugins
  104. doas apk add zsh zsh-vcs tmux shellcheck fzf
  105. export RUNZSH=no
  106. sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  107. git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
  108. # dotfiles
  109. if ! test -d "$DIR/dots"; then
  110. echo "$DIR/dots folder not found.";
  111. exit 1;
  112. fi
  113. cp "$DIR/dots/zshrc" "$HOME/.zshrc"
  114. cp "$DIR/dots/tmux.conf" "$HOME/.tmux.conf"
  115. # install tpm and plugins
  116. git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm || exit 1
  117. tmux start \; \
  118. new -d \; \
  119. run "$HOME/.tmux/plugins/tpm/scripts/install_plugins.sh" \; \
  120. kill-session || exit 1
  121. mkdir -p "$HOME/.local/bin" || exit 1
  122. cp -r "$DIR/scripts/." "$HOME/.local/bin/" || exit 1
  123. }
  124. neovim() {
  125. # install neovim
  126. doas apk add neovim tree-sitter tree-sitter-cli
  127. git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim || exit 1
  128. git clone https://git.junickim.me/junikimm717/nvim2023 ~/.config/nvim || exit 1
  129. nvim -c PackerSync -c 'sleep 10' -c qa --headless
  130. echo "sleeping to compile"
  131. nvim -c 'sleep 60' -c qa --headless
  132. }
  133. vimconfigs() {
  134. doas apk add vim
  135. wget https://git.junickim.me/junikimm717/vim2023/raw/branch/master/lsp.vimrc -O .vimrc
  136. }
  137. competitiveprogramming() {
  138. echo "CP..."
  139. doas apk add clang15-extra-tools openjdk17
  140. git clone https://git.junickim.me/junikimm717/linuxcp "$HOME/cp"
  141. go install git.junickim.me/junikimm717/cpgo@latest
  142. }
  143. nfs() {
  144. doas apk add nfs-utils samba cifs-utils
  145. mkdir -p "$HOME/nfs/rpi" && mkdir -p "$HOME/nfs/d2"
  146. echo 'export WORKSPACES=$HOME/nfs/d2/ohsg11/s2:$HOME/nfs/rpi/ohsg11/s2:$WORKSPACES' >> ~/.zshrc
  147. echo "alias schoolmount='doas mount 192.168.1.34:/srv/nfs ~/nfs/rpi'" >> ~/.zshrc
  148. cat <<EOF >> ~/.zshrc
  149. alias d2mount='doas mount.cifs -o username=junikim,uid=\$(id -u),gid=\$(id -g) //157.245.86.196/d2nas ~/nfs/d2'
  150. EOF
  151. }
  152. graphical() {
  153. # xorg and drivers
  154. doas setup-xorg-base
  155. doas apk add xf86-video-qxl xf86-video-vmware virtualbox-guest-additions-x11 mesa-egl xrandr
  156. doas apk add xf86-input-evdev
  157. # wm applications
  158. doas apk add i3wm alacritty polybar i3lock rofi feh picom firefox
  159. # misc
  160. doas apk add xsel
  161. # fonts
  162. doas apk add font-jetbrains-mono-nerd terminus-font ttf-inconsolata ttf-dejavu font-noto font-noto-cjk ttf-font-awesome font-noto-extra
  163. mkdir -p "$HOME/.local/share/fonts" || exit 1
  164. wget https://github.com/fauno/siji/raw/master/ttf/siji.ttf -O "$HOME/.local/share/fonts/siji.ttf" || exit 1
  165. fc-cache -rv
  166. mkdir -p "$HOME/.config/polybar" || exit 1
  167. mkdir -p "$HOME/.config/i3" || exit 1
  168. mkdir -p "$HOME/.config/picom" || exit 1
  169. cp "$DIR/dots/polybar.ini" "$HOME/.config/polybar/config" || exit 1
  170. cp "$DIR/dots/i3config" "$HOME/.config/i3/config" || exit 1
  171. sed -i "s/brave-browser/firefox/" "$HOME/.config/i3/config"
  172. cp "$DIR/dots/picom.conf" "$HOME/.config/picom/picom.conf" || exit 1
  173. mkdir -p "$HOME/.config/alacritty" || exit 1
  174. cp "$DIR/dots/alacritty.yml" "$HOME/.config/alacritty/alacritty.yml" || exit 1
  175. echo "exec i3" > "$HOME/.xinitrc"
  176. # wallpaper
  177. mkdir -p "$HOME/wallpaper"
  178. wget https://alpinelinux.org/banner.jpg -O "$HOME/wallpaper/banner.jpg"
  179. sed -i "s|exec --no-startup-id nitrogen --restore|exec --no-startup-id feh --bg-fill ~/wallpaper/banner.jpg|" "$HOME/.config/i3/config"
  180. }
  181. (dev && sysinfo && dotfiles && vimconfigs) || exit 1
  182. if ! test -z "$NVIM"; then
  183. neovim || exit 1
  184. fi
  185. if ! test -z "$CP"; then
  186. competitiveprogramming || exit 1
  187. fi
  188. if ! test -z "$GRAPHICAL"; then
  189. graphical || exit 1
  190. fi
  191. if ! test -z "$NFS"; then
  192. nfs || exit 1
  193. fi
  194. }
  195. if test $# -eq 0; then
  196. echo "at least one argument: root or user" && exit 1
  197. fi
  198. case $1 in
  199. root|r)
  200. shift
  201. root_setup "$@"
  202. ;;
  203. user|u)
  204. shift
  205. user_setup "$@"
  206. ;;
  207. *)
  208. echo "Invalid option $1"
  209. exit 1
  210. ;;
  211. esac