code-server.sh 2.4 KB

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