-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathbackup-config-files.sh
executable file
·65 lines (55 loc) · 1.67 KB
/
backup-config-files.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
#!/bin/bash
REPO_LOC="$HOME"
REPO_NAME="canvas-config-bk"
color_restore='\033[0m'
color_green='\033[0;32m'
color_yellow='\033[1;33m'
die ()
{
echo "Error: $1"
exit 1
}
[ -d config ] || die "Must be run in the root of your canvas checkout"
read -r -d '' VAR << __EOF__
${color_green}
Each time you run this script, your current canvas config files will be backed up to
a git repo located at ${REPO_LOC}/${REPO_NAME}. If the repo doesn't exist yet, it
will be created. Each running of this script will result in a new commit to the repo
containing any changes to your config files from the last time you ran it.
${color_restore}
__EOF__
echo -e "$VAR"
prevdir=$(pwd)
cd $REPO_LOC
mkdir -p $REPO_NAME
cd $REPO_NAME
$(git status >/dev/null 2>&1) || git init
cd $prevdir
cp -v config/*.yml "${REPO_LOC}/${REPO_NAME}/"
cd "${REPO_LOC}/${REPO_NAME}"
git add .
git ci -m "Add config files as of $(date)"
# If the user doesn't have a remote repo, tell them how to add one
if [[ "$(git remote -v | wc -l | xargs)" = "0" ]]; then
read -r -d '' VAR << __EOF__
${color_green}
Your canvas config files are backup up into a git repo located at ${REPO_LOC}/${REPO_NAME}
${color_yellow}
You can push this to a remote private repo using:
git remote add origin <origin-url>
pit push -u origin
${color_green}
For example, to back it up to bitbucket.org, it would be:
git remote add origin [email protected]:<username>/${REPO_NAME}.git
git push -u origin
${color_restore}
__EOF__
echo -e "$VAR"
else
read -p "Do you want me to push the changes to your remote repository?" PUSH
if [[ $PUSH =~ [Yy] ]]; then
git push
else
echo "Ok, not pushing"
fi
fi