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.

124 lines
3.4 KiB

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. usertest && createuser && installdoas
  28. }
  29. user_setup() {
  30. cd "$HOME" || exit 1;
  31. if ! (apk list | grep 'doas' 2>&1) > /dev/null; then
  32. echo "doas is not installed.";
  33. exit 1
  34. fi
  35. dev() {
  36. echo "Developer tools..."
  37. doas apk add git make python3 nodejs npm go cargo g++ gcc curl bash shadow || exit 1
  38. }
  39. sysinfo() {
  40. echo "Dylan Araps scripts"
  41. cd "$HOME" || exit 1;
  42. mkdir -p repos
  43. git clone https://github.com/dylanaraps/pfetch "$HOME/repos/pfetch"
  44. git clone https://github.com/dylanaraps/neofetch "$HOME/repos/neofetch"
  45. git clone https://github.com/dylanaraps/fff "$HOME/repos/fff"
  46. cd "$HOME/repos/pfetch" || exit 1;
  47. doas make install || exit 2;
  48. cd "$HOME" || exit 1;
  49. cd "$HOME/repos/neofetch" || exit 1;
  50. doas make install || exit 2;
  51. cd "$HOME" || exit 1;
  52. cd "$HOME/repos/fff" || exit 1;
  53. doas make install || exit 2;
  54. cd "$HOME" || exit 1;
  55. }
  56. dotfiles() {
  57. echo "Adding zsh and tmux configs"
  58. # zsh plugins
  59. doas apk add zsh tmux shellcheck fzf
  60. sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  61. git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
  62. # dotfiles
  63. if ! test -d "$DIR/dots"; then
  64. echo "$DIR/dots folder not found.";
  65. exit 1;
  66. fi
  67. cp "$DIR/dots/zshrc" "$HOME/.zshrc"
  68. cp "$DIR/dots/tmux.conf" "$HOME/.tmux.conf"
  69. # install tpm and plugins
  70. git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm || exit 1
  71. tmux start \; \
  72. new -d \; \
  73. run "$HOME/.tmux/plugins/tpm/scripts/install_plugins.sh" \; \
  74. kill-session || exit 1
  75. mkdir -p "$HOME/.local/bin" || exit 1
  76. cp -r "$DIR/scripts/." "$HOME/.local/bin/" || exit 1
  77. }
  78. neovim() {
  79. # install neovim
  80. doas apk add neovim tree-sitter tree-sitter-cli
  81. git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim || exit 1
  82. git clone https://git.junickim.me/junikimm717/nvim2023 ~/.config/nvim || exit 1
  83. nvim -c PackerSync -c 'sleep 10' -c qa --headless
  84. echo "sleeping to compile"
  85. nvim -c 'sleep 60' -c qa --headless
  86. }
  87. competitiveprogramming() {
  88. echo "CP..."
  89. git clone https://git.junickim.me/junikimm717/linuxcp "$HOME/cp"
  90. go install git.junickim.me/junikimm717/cpgo@latest
  91. }
  92. (dev && sysinfo && dotfiles && neovim) || exit 1
  93. }
  94. if test $# -eq 0; then
  95. echo "at least one argument: root or user" && exit 1
  96. fi
  97. case $1 in
  98. root|r)
  99. root_setup
  100. ;;
  101. user|u)
  102. user_setup
  103. ;;
  104. *)
  105. echo "Invalid option $1"
  106. exit 1
  107. ;;
  108. esac