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.

128 lines
3.5 KiB

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