sxbith/code
0
1#!/bin/bash2 3START_DIR="${START_DIR:-/home/coder/project}"4 5PREFIX="deploy-code-server"6 7mkdir -p $START_DIR8 9# function to clone the git repo or add a user's first file if no repo was specified.10project_init () {11 [ -z "${GIT_REPO}" ] && echo "[$PREFIX] No GIT_REPO specified" && echo "Example file. Have questions? Join us at https://community.coder.com" > $START_DIR/coder.txt || git clone $GIT_REPO $START_DIR12}13 14# add rclone config and start rclone, if supplied15if [[ -z "${RCLONE_DATA}" ]]; then16 echo "[$PREFIX] RCLONE_DATA is not specified. Files will not persist"17 18 # start the project19 project_init20 21else22 echo "[$PREFIX] Copying rclone config..."23 mkdir -p /home/coder/.config/rclone/24 touch /home/coder/.config/rclone/rclone.conf25 echo $RCLONE_DATA | base64 -d > /home/coder/.config/rclone/rclone.conf26 27 # default to true28 RCLONE_VSCODE_TASKS="${RCLONE_VSCODE_TASKS:-true}"29 RCLONE_AUTO_PUSH="${RCLONE_AUTO_PUSH:-true}"30 RCLONE_AUTO_PULL="${RCLONE_AUTO_PULL:-true}"31 32 if [ $RCLONE_VSCODE_TASKS = "true" ]; then33 # copy our tasks config to VS Code34 echo "[$PREFIX] Applying VS Code tasks for rclone"35 cp /tmp/rclone-tasks.json /home/coder/.local/share/code-server/User/tasks.json36 # install the extension to add to menu bar37 code-server --install-extension actboy168.tasks&38 else39 # user specified they don't want to apply the tasks40 echo "[$PREFIX] Skipping VS Code tasks for rclone"41 fi42 43 44 45 # Full path to the remote filesystem46 RCLONE_REMOTE_PATH=${RCLONE_REMOTE_NAME:-code-server-remote}:${RCLONE_DESTINATION:-code-server-files}47 RCLONE_SOURCE_PATH=${RCLONE_SOURCE:-$START_DIR}48 echo "rclone sync $RCLONE_SOURCE_PATH $RCLONE_REMOTE_PATH $RCLONE_FLAGS -vv" > /home/coder/push_remote.sh49 echo "rclone sync $RCLONE_REMOTE_PATH $RCLONE_SOURCE_PATH $RCLONE_FLAGS -vv" > /home/coder/pull_remote.sh50 chmod +x push_remote.sh pull_remote.sh51 52 if rclone ls $RCLONE_REMOTE_PATH; then53 54 if [ $RCLONE_AUTO_PULL = "true" ]; then55 # grab the files from the remote instead of running project_init()56 echo "[$PREFIX] Pulling existing files from remote..."57 /home/coder/pull_remote.sh&58 else59 # user specified they don't want to apply the tasks60 echo "[$PREFIX] Auto-pull is disabled"61 fi62 63 else64 65 if [ $RCLONE_AUTO_PUSH = "true" ]; then66 # we need to clone the git repo and sync67 echo "[$PREFIX] Pushing initial files to remote..."68 project_init69 /home/coder/push_remote.sh&70 else71 # user specified they don't want to apply the tasks72 echo "[$PREFIX] Auto-push is disabled"73 fi74 75 fi76 77fi78 79# Add dotfiles, if set80if [ -n "$DOTFILES_REPO" ]; then81 # grab the files from the remote instead of running project_init()82 echo "[$PREFIX] Cloning dotfiles..."83 mkdir -p $HOME/dotfiles84 git clone $DOTFILES_REPO $HOME/dotfiles85 86 DOTFILES_SYMLINK="${RCLONE_AUTO_PULL:-true}"87 88 # symlink repo to $HOME89 if [ $DOTFILES_SYMLINK = "true" ]; then90 shopt -s dotglob91 ln -sf source_file $HOME/dotfiles/* $HOME92 fi93 94 # run install script, if it exists95 [ -f "$HOME/dotfiles/install.sh" ] && $HOME/dotfiles/install.sh96fi97 98echo "[$PREFIX] Starting code-server..."99# Now we can run code-server with the default entrypoint100/usr/bin/entrypoint.sh --bind-addr 0.0.0.0:8080 $START_DIR