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.

223 lines
6.2 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
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" && cd "$HOME/repos/pfetch" && doas make install
  89. git clone https://github.com/dylanaraps/neofetch "$HOME/repos/neofetch" && cd "$HOME/repos/neofetch" && doas make install
  90. git clone https://github.com/dylanaraps/fff "$HOME/repos/fff" && cd "$HOME/repos/fff" && doas make install
  91. cd "$HOME" || exit 1;
  92. }
  93. dotfiles() {
  94. echo "Adding zsh and tmux configs"
  95. # zsh plugins
  96. doas apk add zsh zsh-vcs tmux shellcheck fzf
  97. export RUNZSH=no
  98. sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  99. git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
  100. # dotfiles
  101. if ! test -d "$DIR/dots"; then
  102. echo "$DIR/dots folder not found.";
  103. exit 1;
  104. fi
  105. cp "$DIR/dots/zshrc" "$HOME/.zshrc"
  106. cp "$DIR/dots/tmux.conf" "$HOME/.tmux.conf"
  107. # install tpm and plugins
  108. git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm || exit 1
  109. tmux start \; \
  110. new -d \; \
  111. run "$HOME/.tmux/plugins/tpm/scripts/install_plugins.sh" \; \
  112. kill-session || exit 1
  113. mkdir -p "$HOME/.local/bin" || exit 1
  114. cp -r "$DIR/scripts/." "$HOME/.local/bin/" || exit 1
  115. }
  116. neovim() {
  117. # install neovim
  118. doas apk add neovim tree-sitter tree-sitter-cli
  119. git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim || exit 1
  120. git clone https://git.junickim.me/junikimm717/nvim2023 ~/.config/nvim || exit 1
  121. nvim -c PackerSync -c 'sleep 10' -c qa --headless
  122. echo "sleeping to compile"
  123. nvim -c 'sleep 60' -c qa --headless
  124. }
  125. vimconfigs() {
  126. doas apk add vim
  127. wget https://git.junickim.me/junikimm717/vim2023/raw/branch/master/lsp.vimrc -O .vimrc
  128. }
  129. competitiveprogramming() {
  130. echo "CP..."
  131. doas apk add clang15-extra-tools openjdk17
  132. git clone https://git.junickim.me/junikimm717/linuxcp "$HOME/cp"
  133. go install git.junickim.me/junikimm717/cpgo@latest
  134. }
  135. nfs() {
  136. doas apk add nfs-utils samba cifs-utils
  137. mkdir -p "$HOME/nfs/rpi" && mkdir -p "$HOME/nfs/d2"
  138. echo 'export WORKSPACES=$HOME/nfs/d2/ohsg11/s2:$HOME/nfs/rpi/ohsg11/s2:$WORKSPACES' >> ~/.zshrc
  139. echo "alias schoolmount='doas mount 192.168.1.179:/srv/nfs ~/nfs/rpi'" >> ~/.zshrc
  140. cat <<EOF >> ~/.zshrc
  141. alias d2mount='doas mount.cifs -o username=junikim,uid=\$(id -u),gid=\$(id -g) //157.245.86.196/d2nas ~/nfs/d2'
  142. EOF
  143. }
  144. graphical() {
  145. # xorg and drivers
  146. doas setup-xorg-base
  147. doas apk add xf86-video-qxl xf86-video-vmware virtualbox-guest-additions-x11 mesa-egl xrandr xf86-input-evdev xsel
  148. # wm applications
  149. doas apk add i3wm alacritty polybar i3lock feh picom firefox stow
  150. # rofi dependencies
  151. doas apk add papairus-icon-theme librsvg gdk-pixbuf-dev rofi
  152. mkdir -p "$HOME/.config/alacritty" || exit 1
  153. cp "$DIR/dots/alacritty.yml" "$HOME/.config/alacritty/alacritty.yml" || exit 1
  154. echo "exec i3" > "$HOME/.xinitrc"
  155. # wallpaper
  156. mkdir -p "$HOME/wallpaper"
  157. wget https://alpinelinux.org/banner.jpg -O "$HOME/wallpaper/banner.jpg"
  158. sed -i "s|exec --no-startup-id nitrogen --restore|exec --no-startup-id feh --bg-fill ~/wallpaper/banner.jpg|" "$HOME/.config/i3/config"
  159. # fonts
  160. doas apk add font-jetbrains-mono-nerd terminus-font ttf-inconsolata ttf-dejavu font-noto font-noto-cjk ttf-font-awesome font-noto-extra font-arimo
  161. mkdir -p "$HOME/.local/share/fonts" || exit 1
  162. wget https://github.com/fauno/siji/raw/master/ttf/siji.ttf -O "$HOME/.local/share/fonts/siji.ttf" || exit 1
  163. fc-cache -rv
  164. "$DIR/dots/i3rice/stow" wm
  165. sed -i "s/brave-browser/firefox/" "$HOME/.config/i3/config"
  166. }
  167. (dev && sysinfo && dotfiles && vimconfigs) || exit 1
  168. if ! test -z "$NVIM"; then
  169. neovim || exit 1
  170. fi
  171. if ! test -z "$CP"; then
  172. competitiveprogramming || exit 1
  173. fi
  174. if ! test -z "$GRAPHICAL"; then
  175. graphical || exit 1
  176. fi
  177. if ! test -z "$NFS"; then
  178. nfs || exit 1
  179. fi
  180. }
  181. if test $# -eq 0; then
  182. echo "at least one argument: root or user" && exit 1
  183. fi
  184. case $1 in
  185. root|r)
  186. shift
  187. root_setup "$@"
  188. ;;
  189. user|u)
  190. shift
  191. user_setup "$@"
  192. ;;
  193. *)
  194. echo "Invalid option $1"
  195. exit 1
  196. ;;
  197. esac