-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath_config.sh
More file actions
executable file
·125 lines (100 loc) · 4.71 KB
/
math_config.sh
File metadata and controls
executable file
·125 lines (100 loc) · 4.71 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
#START_DIR="${START_DIR:-/home/coder/project}"
PREFIX="deploy-code-server"
# RCLONE_FLAGS=--exclude "node_modules/**" --exclude ".git/**"
# function to clone the git repo or add a user's first file if no repo was specified.
project_init () {
[ -z "${MATHG_REPO}" ] && echo "[$PREFIX] No MATHG_REPO specified" && echo "Example file. Have questions? Join us at https://community.coder.com" > $START_DIR/coder.txt || git clone $MATHG_REPO $START_DIR
}
# add rclone config and start rclone, if supplied
if [[ -z "${MATHR_DATA}" ]]; then
echo "[$PREFIX] MATHR_DATA is not specified. Files will not persist"
# start the project
project_init
else
echo "[$PREFIX] Copying rclone config..."
mkdir -p ~/.config/rclone/
touch ~/.config/rclone/rclone.conf
echo $MATHR_DATA | base64 -d > ~/.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 /rclone-tasks.json ~/.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
mkdir -p /home/coder
# Full path to the remote filesystem
# RCLONE_REMOTE_PATH_2=${RCLONE_REMOTE_NAME:-onedrive_imath}:${RCLONE_DESTINATION:-Projects}
RCLONE_REMOTE_PATH=${RCLONE_REMOTE_NAME:-gdrive_small}:${RCLONE_DESTINATION:-Projects}
RCLONE_SOURCE_PATH=${RCLONE_SOURCE:-$START_DIR}
echo "cd ${START_DIR}" >> /home/coder/pull_remote.sh
echo "git pull origin main" >> /home/coder/pull_remote.sh
echo "# rclone sync $RCLONE_REMOTE_PATH $RCLONE_SOURCE_PATH --exclude \"node_modules/**\" --exclude \".git/**\" --progress" >> /home/coder/pull_remote.sh
echo "cd ${START_DIR}" >> /home/coder/push_remote.sh
echo "git config --global user.email \"mather@example.com\"" >> /home/coder/push_remote.sh
echo "git config --global user.name \"mather\"" >> /home/coder/push_remote.sh
echo "git add ." >> /home/coder/push_remote.sh
echo "git commit -m \"ok\"" >> /home/coder/push_remote.sh
echo "git push origin main" >> /home/coder/push_remote.sh
echo "rclone sync $RCLONE_SOURCE_PATH $RCLONE_REMOTE_PATH --exclude \"node_modules/**\" --exclude \".git/**\" --progress" >> /home/coder/push_remote.sh
# echo "rclone sync $RCLONE_SOURCE_PATH $RCLONE_REMOTE_PATH_2 --exclude \"node_modules/**\" --exclude \".git/**\" -vv" >> /home/coder/push_remote.sh
chmod a+rx /home/coder/push_remote.sh
chmod a+rx /home/coder/pull_remote.sh
project_init
# 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..."
# while true
# do
# echo "Press [CTRL+C] to stop.."
# time2=$(date "+%Y-%m-%d %H:%M:%S")
# echo "${time2}"
# sleep 60
# # Full path to the remote filesystem
# time=$(date "+%Y-%m-%d_%H-%M-%S")
# RCLONE_REMOTE_PATH_B=${RCLONE_REMOTE_NAME:-gdrive_small}:${RCLONE_DESTINATION:-Docker_Backup/Heroku/${time}}
# RCLONE_SOURCE_PATH_B=${RCLONE_SOURCE:-$START_DIR}
# rclone sync $RCLONE_SOURCE_PATH_B $RCLONE_REMOTE_PATH_B $RCLONE_FLAGS -vv
# done