code-server.sh 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/env bash
  2. # Copyright (c) 2021-2023 tteck
  3. # Author: tteck (tteckster)
  4. # License: MIT
  5. # https://github.com/tteck/Proxmox/raw/main/LICENSE
  6. function header_info {
  7. cat <<"EOF"
  8. ______ __ _____
  9. / ____/___ ____/ /__ / ___/___ ______ _____ _____
  10. / / / __ \/ __ / _ \ \__ \/ _ \/ ___/ | / / _ \/ ___/
  11. / /___/ /_/ / /_/ / __/ ___/ / __/ / | |/ / __/ /
  12. \____/\____/\__,_/\___/ /____/\___/_/ |___/\___/_/
  13. EOF
  14. }
  15. IP=$(hostname -I | awk '{print $1}')
  16. YW=$(echo "\033[33m")
  17. BL=$(echo "\033[36m")
  18. RD=$(echo "\033[01;31m")
  19. BGN=$(echo "\033[4;92m")
  20. GN=$(echo "\033[1;92m")
  21. DGN=$(echo "\033[32m")
  22. CL=$(echo "\033[m")
  23. BFR="\\r\\033[K"
  24. HOLD="-"
  25. CM="${GN}✓${CL}"
  26. APP="Code Server"
  27. hostname="$(hostname)"
  28. set -o errexit
  29. set -o errtrace
  30. set -o nounset
  31. set -o pipefail
  32. shopt -s expand_aliases
  33. alias die='EXIT=$? LINE=$LINENO error_exit'
  34. trap die ERR
  35. function error_exit() {
  36. trap - ERR
  37. local reason="Unknown failure occured."
  38. local msg="${1:-$reason}"
  39. local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
  40. echo -e "$flag $msg" 1>&2
  41. exit $EXIT
  42. }
  43. clear
  44. header_info
  45. if command -v pveversion >/dev/null 2>&1; then echo -e "⚠️ Can't Install on Proxmox "; exit; fi
  46. while true; do
  47. read -p "This will Install ${APP} on $hostname. Proceed(y/n)?" yn
  48. case $yn in
  49. [Yy]*) break ;;
  50. [Nn]*) exit ;;
  51. *) echo "Please answer yes or no." ;;
  52. esac
  53. done
  54. function msg_info() {
  55. local msg="$1"
  56. echo -ne " ${HOLD} ${YW}${msg}..."
  57. }
  58. function msg_ok() {
  59. local msg="$1"
  60. echo -e "${BFR} ${CM} ${GN}${msg}${CL}"
  61. }
  62. msg_info "Installing Dependencies"
  63. apt-get install -y curl &>/dev/null
  64. apt-get install -y sudo &>/dev/null
  65. apt-get install -y git &>/dev/null
  66. msg_ok "Installed Dependencies"
  67. VERSION=$(curl -s https://api.github.com/repos/coder/code-server/releases/latest |
  68. grep "tag_name" |
  69. awk '{print substr($2, 3, length($2)-4) }')
  70. msg_info "Installing Code-Server v${VERSION}"
  71. curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_amd64.deb &>/dev/null
  72. sudo dpkg -i code-server_${VERSION}_amd64.deb &>/dev/null
  73. rm -rf code-server_${VERSION}_amd64.deb
  74. mkdir -p ~/.config/code-server/
  75. sudo systemctl enable --now code-server@$USER &>/dev/null
  76. cat <<EOF >~/.config/code-server/config.yaml
  77. bind-addr: 0.0.0.0:8680
  78. auth: none
  79. password:
  80. cert: false
  81. EOF
  82. sudo systemctl restart code-server@$USER
  83. msg_ok "Installed Code-Server v${VERSION} on $hostname"
  84. echo -e "${APP} should be reachable by going to the following URL.
  85. ${BL}http://$IP:8680${CL} \n"