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.

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