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.

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