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.

213 lines
5.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
  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. -G,--graphical install xorg and wm
  40. -N,--nvim install neovim
  41. -C,--cp install competitive programming scripts
  42. EOF
  43. }
  44. GRAPHICAL=
  45. CP=
  46. NVIM=
  47. while test $# -ne 0; do
  48. case $1 in
  49. -G|--graphical)
  50. GRAPHICAL=1
  51. ;;
  52. -C|--cp)
  53. CP=1
  54. ;;
  55. -N|--nvim)
  56. NVIM=1
  57. ;;
  58. *)
  59. echo "invalid option $1"
  60. help_text
  61. exit
  62. ;;
  63. esac
  64. shift
  65. done
  66. if ! (apk list | grep 'doas' 2>&1) > /dev/null; then
  67. echo "doas is not installed.";
  68. exit 1
  69. fi
  70. dev() {
  71. echo "Developer tools..."
  72. doas apk add git make python3 nodejs npm go g++ gcc curl bash shadow || exit 1
  73. if ! test -z "$NVIM"; then
  74. doas apk add cargo
  75. fi
  76. }
  77. sysinfo() {
  78. echo "Dylan Araps scripts"
  79. cd "$HOME" || exit 1;
  80. mkdir -p repos
  81. git clone https://github.com/dylanaraps/pfetch "$HOME/repos/pfetch"
  82. git clone https://github.com/dylanaraps/neofetch "$HOME/repos/neofetch"
  83. git clone https://github.com/dylanaraps/fff "$HOME/repos/fff"
  84. cd "$HOME/repos/pfetch" || exit 1;
  85. doas make install || exit 2;
  86. cd "$HOME" || exit 1;
  87. cd "$HOME/repos/neofetch" || exit 1;
  88. doas make install || exit 2;
  89. cd "$HOME" || exit 1;
  90. cd "$HOME/repos/fff" || exit 1;
  91. doas make install || exit 2;
  92. cd "$HOME" || exit 1;
  93. }
  94. dotfiles() {
  95. echo "Adding zsh and tmux configs"
  96. # zsh plugins
  97. doas apk add zsh tmux shellcheck fzf
  98. export RUNZSH=no
  99. sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  100. git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
  101. # dotfiles
  102. if ! test -d "$DIR/dots"; then
  103. echo "$DIR/dots folder not found.";
  104. exit 1;
  105. fi
  106. cp "$DIR/dots/zshrc" "$HOME/.zshrc"
  107. cp "$DIR/dots/tmux.conf" "$HOME/.tmux.conf"
  108. # install tpm and plugins
  109. git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm || exit 1
  110. tmux start \; \
  111. new -d \; \
  112. run "$HOME/.tmux/plugins/tpm/scripts/install_plugins.sh" \; \
  113. kill-session || exit 1
  114. mkdir -p "$HOME/.local/bin" || exit 1
  115. cp -r "$DIR/scripts/." "$HOME/.local/bin/" || exit 1
  116. }
  117. neovim() {
  118. # install neovim
  119. doas apk add neovim tree-sitter tree-sitter-cli
  120. git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim || exit 1
  121. git clone https://git.junickim.me/junikimm717/nvim2023 ~/.config/nvim || exit 1
  122. nvim -c PackerSync -c 'sleep 10' -c qa --headless
  123. echo "sleeping to compile"
  124. nvim -c 'sleep 60' -c qa --headless
  125. }
  126. vimconfigs() {
  127. doas apk add vim
  128. wget https://git.junickim.me/junikimm717/vim2023/raw/branch/master/lsp.vimrc -O .vimrc
  129. }
  130. competitiveprogramming() {
  131. echo "CP..."
  132. git clone https://git.junickim.me/junikimm717/linuxcp "$HOME/cp"
  133. go install git.junickim.me/junikimm717/cpgo@latest
  134. }
  135. graphical() {
  136. # xorg and drivers
  137. doas setup-xorg-base
  138. doas apk add xf86-video-qxl mesa-egl xrandr
  139. doas apk add xf86-input-evdev
  140. # wm applications
  141. doas apk add i3wm alacritty polybar i3lock feh
  142. # fonts
  143. doas apk add font-jetbrains-mono-nerd terminus-font ttf-inconsolata ttf-dejavu font-noto font-noto-cjk ttf-font-awesome font-noto-extra
  144. doas apk add firefox-esr
  145. mkdir -p "$HOME/repos/siji"
  146. cd "$HOME/repos/siji" || exit 1
  147. curl -LJO https://github.com/fauno/siji/archive/master.tar.gz || exit 1
  148. tar -xzvf ./siji-master.tar.gz || exit 1
  149. mkdir -p "$HOME/.local/share/fonts" || exit 1
  150. cp ./siji-master/ttf/siji.ttf "$HOME/.local/share/fonts/" || exit 1
  151. fc-cache -rv
  152. mkdir -p "$HOME/.config/polybar" || exit 1
  153. mkdir -p "$HOME/.config/i3" || exit 1
  154. mkdir -p "$HOME/.config/picom" || exit 1
  155. cp "$DIR/dots/polybar.ini" "$HOME/.config/polybar/config" || exit 1
  156. cp "$DIR/dots/i3config" "$HOME/.config/i3/config" || exit 1
  157. cp "$DIR/dots/picom.conf" "$HOME/.config/picom/picom.conf" || exit 1
  158. }
  159. (dev && sysinfo && dotfiles && vimconfigs) || exit 1
  160. if ! test -z "$NVIM"; then
  161. neovim || exit 1
  162. fi
  163. if ! test -z "$CP"; then
  164. competitiveprogramming || exit 1
  165. fi
  166. if ! test -z "$GRAPHICAL"; then
  167. graphical || exit 1
  168. fi
  169. }
  170. if test $# -eq 0; then
  171. echo "at least one argument: root or user" && exit 1
  172. fi
  173. case $1 in
  174. root|r)
  175. shift
  176. root_setup "$@"
  177. ;;
  178. user|u)
  179. shift
  180. user_setup "$@"
  181. ;;
  182. *)
  183. echo "Invalid option $1"
  184. exit 1
  185. ;;
  186. esac