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.

241 lines
6.5 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
  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. git clone https://git.junickim.me/junikimm717/linuxcp "$HOME/cp"
  140. go install git.junickim.me/junikimm717/cpgo@latest
  141. }
  142. nfs() {
  143. doas apk add nfs-utils samba cifs-utils
  144. mkdir -p "$HOME/nfs/rpi" && mkdir -p "$HOME/nfs/d2"
  145. echo 'export WORKSPACES=$HOME/nfs/d2/ohsg11/s2:$HOME/nfs/rpi/ohsg11/s2:$WORKSPACES' >> ~/.zshrc
  146. echo "alias schoolmount='doas mount 192.168.1.34:/srv/nfs ~/nfs/rpi'" >> ~/.zshrc
  147. cat <<EOF >> ~/.zshrc
  148. alias d2mount='doas mount.cifs -o username=junikim,uid=\$(id -u),gid=\$(id -g) //157.245.86.196/d2nas ~/nfs/d2'
  149. EOF
  150. }
  151. graphical() {
  152. # xorg and drivers
  153. doas setup-xorg-base
  154. doas apk add xf86-video-qxl xf86-video-vmware virtualbox-guest-additions-x11 mesa-egl xrandr
  155. doas apk add xf86-input-evdev
  156. # wm applications
  157. doas apk add i3wm alacritty polybar i3lock rofi feh picom firefox
  158. # misc
  159. doas apk add xsel
  160. # fonts
  161. doas apk add font-jetbrains-mono-nerd terminus-font ttf-inconsolata ttf-dejavu font-noto font-noto-cjk ttf-font-awesome font-noto-extra
  162. mkdir -p "$HOME/.local/share/fonts" || exit 1
  163. wget https://github.com/fauno/siji/raw/master/ttf/siji.ttf -O "$HOME/.local/share/fonts/siji.ttf" || exit 1
  164. fc-cache -rv
  165. mkdir -p "$HOME/.config/polybar" || exit 1
  166. mkdir -p "$HOME/.config/i3" || exit 1
  167. mkdir -p "$HOME/.config/picom" || exit 1
  168. cp "$DIR/dots/polybar.ini" "$HOME/.config/polybar/config" || exit 1
  169. cp "$DIR/dots/i3config" "$HOME/.config/i3/config" || exit 1
  170. sed -i "s/brave-browser/firefox/" "$HOME/.config/i3/config"
  171. cp "$DIR/dots/picom.conf" "$HOME/.config/picom/picom.conf" || exit 1
  172. mkdir -p "$HOME/.config/alacritty" || exit 1
  173. cp "$DIR/dots/alacritty.yml" "$HOME/.config/alacritty/alacritty.yml" || exit 1
  174. echo "exec i3" > "$HOME/.xinitrc"
  175. # wallpaper
  176. mkdir -p "$HOME/wallpaper"
  177. wget https://alpinelinux.org/banner.jpg -o "$HOME/wallpaper/banner.jpg"
  178. sed -i "s|exec --no-startup-id nitrogen --restore|exec --no-startup-id feh --bg-fill ~/wallpaper/banner.jpg|" "$HOME/.config/i3/config"
  179. }
  180. (dev && sysinfo && dotfiles && vimconfigs) || exit 1
  181. if ! test -z "$NVIM"; then
  182. neovim || exit 1
  183. fi
  184. if ! test -z "$CP"; then
  185. competitiveprogramming || exit 1
  186. fi
  187. if ! test -z "$GRAPHICAL"; then
  188. graphical || exit 1
  189. fi
  190. if ! test -z "$NFS"; then
  191. nfs || exit 1
  192. fi
  193. }
  194. if test $# -eq 0; then
  195. echo "at least one argument: root or user" && exit 1
  196. fi
  197. case $1 in
  198. root|r)
  199. shift
  200. root_setup "$@"
  201. ;;
  202. user|u)
  203. shift
  204. user_setup "$@"
  205. ;;
  206. *)
  207. echo "Invalid option $1"
  208. exit 1
  209. ;;
  210. esac