-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitback.sh
More file actions
executable file
·66 lines (61 loc) · 1.59 KB
/
gitback.sh
File metadata and controls
executable file
·66 lines (61 loc) · 1.59 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
#!/bin/bash
# Variables:
backup_repo=$(cat ~/.gitback/backuprepo)
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Functions:
temp_dir_setup() {
mkdir $TMPDIR/gitback-temp
# Broken code DO NOT UNCOMMENT UNTIL FIXED :pray::pray::pray:
# if [ $# -lt 1 ]
# then
# basename "$PWD" > $TMPDIR/gitback-temp/dirname
# dirname=$(cat $TMPDIR/gitback-temp/dirname)
# pwd > $TMPDIR/gitback-temp/backupdir
# backupdir=$(cat $TMPDIR/gitback-temp/backupdir)
# else
# echo $1 > $TMPDIR/gitback-temp/backupdir
# backupdir=$(cat $TMPDIR/gitback-temp/backupdir)
# basename $backupdir > $TMPDIR/gitback-temp/dirname
# dirname=$(cat $TMPDIR/gitback-temp/dirname)
# fi
basename "$PWD" > $TMPDIR/gitback-temp/dirname
dirname=$(cat $TMPDIR/gitback-temp/dirname)
pwd > $TMPDIR/gitback-temp/backupdir
backupdir=$(cat $TMPDIR/gitback-temp/backupdir)
}
user_info() {
echo -e "${YELLOW}Backing up... (This may take a while)${NC} "
}
update_repo() {
cd $TMPDIR/gitback-temp
git clone --quiet $backup_repo backup_repo
rm -rf backup_repo/$dirname
cp -r "${backupdir}" "backup_repo/"
}
push_changes() {
cd backup_repo
git add . &> /dev/null
commit_message=$(date)
git commit -m "gitback backup at: ${commit_message}" &> /dev/null
git push origin main &> /dev/null
}
cleanup() {
cd ..
rm -rf $TMPDIR/gitback-temp
}
# Main Script
# Setup the temporary directory
temp_dir_setup
# Show info about the backup to the user
user_info
# Update the repository with the new folder
update_repo
# Push the changes
push_changes
# Cleanup our giant mess.
cleanup
# Print a finished message
echo -e "${GREEN}Finished!${NC} "