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.

129 lines
3.5 KiB

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. 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. export RUNZSH=no
  65. sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
  66. git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting"
  67. # dotfiles
  68. if ! test -d "$DIR/dots"; then
  69. echo "$DIR/dots folder not found.";
  70. exit 1;
  71. fi
  72. cp "$DIR/dots/zshrc" "$HOME/.zshrc"
  73. cp "$DIR/dots/tmux.conf" "$HOME/.tmux.conf"
  74. # install tpm and plugins
  75. git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm || exit 1
  76. tmux start \; \
  77. new -d \; \
  78. run "$HOME/.tmux/plugins/tpm/scripts/install_plugins.sh" \; \
  79. kill-session || exit 1
  80. mkdir -p "$HOME/.local/bin" || exit 1
  81. cp -r "$DIR/scripts/." "$HOME/.local/bin/" || exit 1
  82. }
  83. neovim() {
  84. # install neovim
  85. doas apk add neovim tree-sitter tree-sitter-cli
  86. git clone --depth 1 https://github.com/wbthomason/packer.nvim ~/.local/share/nvim/site/pack/packer/start/packer.nvim || exit 1
  87. git clone https://git.junickim.me/junikimm717/nvim2023 ~/.config/nvim || exit 1
  88. nvim -c PackerSync -c 'sleep 10' -c qa --headless
  89. echo "sleeping to compile"
  90. nvim -c 'sleep 60' -c qa --headless
  91. }
  92. competitiveprogramming() {
  93. echo "CP..."
  94. git clone https://git.junickim.me/junikimm717/linuxcp "$HOME/cp"
  95. go install git.junickim.me/junikimm717/cpgo@latest
  96. }
  97. (dev && sysinfo && dotfiles && neovim) || exit 1
  98. }
  99. if test $# -eq 0; then
  100. echo "at least one argument: root or user" && exit 1
  101. fi
  102. case $1 in
  103. root|r)
  104. root_setup
  105. ;;
  106. user|u)
  107. user_setup
  108. ;;
  109. *)
  110. echo "Invalid option $1"
  111. exit 1
  112. ;;
  113. esac