dev-setup.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. #
  4. # This script provisions a working Wormhole dev environment on a minimally provisioned VM.
  5. # It expects to run as a user without root permissions.
  6. #
  7. # Can safely run multiple times to update to the latest versions.
  8. #
  9. # Make sure this is a supported OS.
  10. DISTRO="$(lsb_release --id --short)-$(lsb_release --release --short)"
  11. case "$DISTRO" in
  12. Debian-10 | Debian-11 | RedHatEnterprise-8.*) true ;; # okay (no operation)
  13. *)
  14. echo "This script is only for Debian 10 or 11, or RHEL 8"
  15. exit 1
  16. ;;
  17. esac
  18. # Refuse to run as root
  19. if [[ $EUID -eq 0 ]]; then
  20. echo "This script must not be run as root" 1>&2
  21. exit 1
  22. fi
  23. # Check if we can use sudo to get root
  24. if ! sudo -n true; then
  25. echo "This script requires sudo to run."
  26. exit 1
  27. fi
  28. # Make sure OS-provided Docker package isn't installed
  29. case "$DISTRO" in
  30. Debian-*)
  31. if dpkg -s docker.io &>/dev/null; then
  32. echo "Docker is already installed from Debian's repository. Please uninstall it first."
  33. exit 1
  34. fi
  35. ;;
  36. RedHatEnterprise-8.*)
  37. if rpm -q podman-docker &>/dev/null; then
  38. echo "podman-docker is installed. Please uninstall it first."
  39. exit 1
  40. fi
  41. ;;
  42. *) echo "Internal error: $DISTRO not matched in case block." && exit 1 ;;
  43. esac
  44. # Upgrade everything
  45. # (this ensures that an existing Docker CE installation is up to date before continuing)
  46. case "$DISTRO" in
  47. Debian-*) sudo apt-get update && sudo apt-get upgrade -y ;;
  48. RedHatEnterprise-8.*) sudo dnf upgrade -y ;;
  49. *) echo "Internal error: $DISTRO not matched in case block." && exit 1 ;;
  50. esac
  51. # Install dependencies
  52. case "$DISTRO" in
  53. Debian-*) sudo apt-get -y install bash-completion git git-review vim ;;
  54. RedHatEnterprise-8.*) sudo dnf -y install bash-completion git git-review vim ;;
  55. *) echo "Internal error: $DISTRO not matched in case block." && exit 1 ;;
  56. esac
  57. # Install Go
  58. ARCH=amd64
  59. GO=1.19.3
  60. (
  61. if [[ -d /usr/local/go ]]; then
  62. sudo rm -rf /usr/local/go
  63. fi
  64. TMP=$(mktemp -d)
  65. (
  66. cd "$TMP"
  67. curl -OJ "https://dl.google.com/go/go${GO}.linux-${ARCH}.tar.gz"
  68. sudo tar -C /usr/local -xzf "go${GO}.linux-${ARCH}.tar.gz"
  69. echo 'PATH=/usr/local/go/bin:$PATH' | sudo tee /etc/profile.d/local_go.sh
  70. )
  71. rm -rf "$TMP"
  72. )
  73. . /etc/profile.d/local_go.sh
  74. # Install Docker and add ourselves to Docker group
  75. if [[ ! -f /usr/bin/docker ]]; then
  76. TMP=$(mktemp -d)
  77. (
  78. cd "$TMP"
  79. case "$DISTRO" in
  80. Debian-*)
  81. curl -fsSL https://get.docker.com -o get-docker.sh
  82. sudo sh get-docker.sh
  83. ;;
  84. RedHatEnterprise-8.*)
  85. # get-docker.sh doesn't support RHEL x86_64.
  86. curl -fsSL https://download.docker.com/linux/centos/docker-ce.repo -o docker-ce.repo
  87. sudo cp docker-ce.repo /etc/yum.repos.d/docker-ce.repo
  88. # This is a no-op if the packages are already installed, but the "upgrade everything" step above will keep them up to date.
  89. sudo dnf -y install docker-ce docker-ce-cli containerd.io
  90. ;;
  91. esac
  92. )
  93. rm -rf "$TMP"
  94. sudo gpasswd -a $USER docker
  95. fi
  96. sudo systemctl enable --now docker
  97. # Install Minikube
  98. # Use 1.24 until this regression is resolved:
  99. # https://github.com/kubernetes/minikube/issues/13542
  100. case "$DISTRO" in
  101. Debian-*)
  102. TMP=$(mktemp -d)
  103. (
  104. cd "$TMP"
  105. curl -LO https://github.com/kubernetes/minikube/releases/download/v1.24.0/minikube_1.24.0-0_amd64.deb
  106. sudo dpkg -i minikube_1.24.0-0_amd64.deb
  107. )
  108. rm -rf "$TMP"
  109. ;;
  110. RedHatEnterprise-*)
  111. sudo dnf -y install https://github.com/kubernetes/minikube/releases/download/v1.24.0/minikube-1.24.0-0.x86_64.rpm
  112. ;;
  113. *) echo "Internal error: $DISTRO not matched in case block." && exit 1 ;;
  114. esac
  115. # Install tilt.
  116. # This script places the binary at /usr/local/bin/tilt and then self-tests by trying to execute it from PATH.
  117. # So we need to ensure that PATH contains /usr/local/bin, which is not the case in the environment created by sudo by default on RHEL.
  118. case "$DISTRO" in
  119. Debian-*) true ;;
  120. RedHatEnterprise-*)
  121. echo -e "Defaults\tsecure_path=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin" | sudo tee /etc/sudoers.d/tilt_installer_path
  122. ;;
  123. *) echo "Internal error: $DISTRO not matched in case block." && exit 1 ;;
  124. esac
  125. curl -fsSL https://raw.githubusercontent.com/tilt-dev/tilt/master/scripts/install.sh | sudo bash
  126. # Shell aliases
  127. cat <<'EOF' | sudo tee /etc/profile.d/wormhole_aliases.sh
  128. alias kubectl="minikube kubectl --"
  129. alias vi=vim
  130. alias kc=kubectl
  131. . <(kubectl completion bash)
  132. . <(minikube completion bash)
  133. complete -F __start_kubectl kc
  134. function use-namespace {
  135. kubectl config set-context --current --namespace=$1
  136. }
  137. export DOCKER_BUILDKIT=1
  138. alias start-recommended-minikube="minikube start --driver=docker --kubernetes-version=v1.22.3 --cpus=$(nproc) --memory=16G --disk-size=120g --namespace=wormhole"
  139. EOF
  140. cat <<EOF
  141. ┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┑
  142. │ │
  143. │ SUCCESS │
  144. │ │
  145. │ Re-log into your session to apply changes. │
  146. │ │
  147. └━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┘
  148. EOF