-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.sh
executable file
·100 lines (77 loc) · 3.4 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
START_DIR="${START_DIR:-/home/coder/project}"
PREFIX="deploy-code-server"
mkdir -p $START_DIR
# function to clone the git repo or add a user's first file if no repo was specified.
project_init () {
[ -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_DIR
}
# add rclone config and start rclone, if supplied
if [[ -z "${RCLONE_DATA}" ]]; then
echo "[$PREFIX] RCLONE_DATA is not specified. Files will not persist"
# start the project
project_init
else
echo "[$PREFIX] Copying rclone config..."
mkdir -p /home/coder/.config/rclone/
touch /home/coder/.config/rclone/rclone.conf
echo $RCLONE_DATA | base64 -d > /home/coder/.config/rclone/rclone.conf
# default to true
RCLONE_VSCODE_TASKS="${RCLONE_VSCODE_TASKS:-true}"
RCLONE_AUTO_PUSH="${RCLONE_AUTO_PUSH:-true}"
RCLONE_AUTO_PULL="${RCLONE_AUTO_PULL:-true}"
if [ $RCLONE_VSCODE_TASKS = "true" ]; then
# copy our tasks config to VS Code
echo "[$PREFIX] Applying VS Code tasks for rclone"
cp /tmp/rclone-tasks.json /home/coder/.local/share/code-server/User/tasks.json
# install the extension to add to menu bar
code-server --install-extension actboy168.tasks&
else
# user specified they don't want to apply the tasks
echo "[$PREFIX] Skipping VS Code tasks for rclone"
fi
# Full path to the remote filesystem
RCLONE_REMOTE_PATH=${RCLONE_REMOTE_NAME:-code-server-remote}:${RCLONE_DESTINATION:-code-server-files}
RCLONE_SOURCE_PATH=${RCLONE_SOURCE:-$START_DIR}
echo "rclone sync $RCLONE_SOURCE_PATH $RCLONE_REMOTE_PATH $RCLONE_FLAGS -vv" > /home/coder/push_remote.sh
echo "rclone sync $RCLONE_REMOTE_PATH $RCLONE_SOURCE_PATH $RCLONE_FLAGS -vv" > /home/coder/pull_remote.sh
chmod +x push_remote.sh pull_remote.sh
if rclone ls $RCLONE_REMOTE_PATH; then
if [ $RCLONE_AUTO_PULL = "true" ]; then
# grab the files from the remote instead of running project_init()
echo "[$PREFIX] Pulling existing files from remote..."
/home/coder/pull_remote.sh&
else
# user specified they don't want to apply the tasks
echo "[$PREFIX] Auto-pull is disabled"
fi
else
if [ $RCLONE_AUTO_PUSH = "true" ]; then
# we need to clone the git repo and sync
echo "[$PREFIX] Pushing initial files to remote..."
project_init
/home/coder/push_remote.sh&
else
# user specified they don't want to apply the tasks
echo "[$PREFIX] Auto-push is disabled"
fi
fi
fi
# Add dotfiles, if set
if [ -n "$DOTFILES_REPO" ]; then
# grab the files from the remote instead of running project_init()
echo "[$PREFIX] Cloning dotfiles..."
mkdir -p $HOME/dotfiles
git clone $DOTFILES_REPO $HOME/dotfiles
DOTFILES_SYMLINK="${RCLONE_AUTO_PULL:-true}"
# symlink repo to $HOME
if [ $DOTFILES_SYMLINK = "true" ]; then
shopt -s dotglob
ln -sf source_file $HOME/dotfiles/* $HOME
fi
# run install script, if it exists
[ -f "$HOME/dotfiles/install.sh" ] && $HOME/dotfiles/install.sh
fi
echo "[$PREFIX] Starting code-server..."
# Now we can run code-server with the default entrypoint
/usr/bin/entrypoint.sh --bind-addr 0.0.0.0:8080 $START_DIR