-
Notifications
You must be signed in to change notification settings - Fork 1
/
DotKraken.sh
executable file
·207 lines (156 loc) · 4.94 KB
/
DotKraken.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
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#!/bin/bash
# Change working directory to direcory of this script
DKRK_DIR=$(dirname "$(readlink -f "$0")")
cd $DKRK_DIR
# Source print script
source bin/prnt.sh
# Source prompt scripts
source bin/prmpt.sh
# Source git functions
source bin/git.sh
# Show header
echo""
prnt_line HEADING "▀██▀▀█▄ ▄ ▀██▀ █▀ ▀██ "
prnt_line HEADING " ██ ██ ▄▄▄ ▄██▄ ██ ▄▀ ▄▄▄ ▄▄ ▄▄▄▄ ██ ▄▄ ▄▄▄▄ ▄▄ ▄▄▄ "
prnt_line HEADING " ██ ██ ▄█ ▀█▄ ██ ██▀█▄ ██▀ ▀▀ ▀▀ ▄██ ██ ▄▀ ▄█▄▄▄██ ██ ██ "
prnt_line HEADING " ██ ██ ██ ██ ██ ██ ██ ██ ▄█▀ ██ ██▀█▄ ██ ██ ██ "
prnt_line HEADING "▄██▄▄▄█▀ ▀█▄▄█▀ ▀█▄▀ ▄██▄ ██▄ ▄██▄ ▀█▄▄▀█▀ ▄██▄ ██▄ ▀█▄▄▄▀ ▄██▄ ██▄ "
prnt_line DEFAULT "Checking given parameters ..."
echo""
# Change user permissions to make DotKraken available for crontabs
prnt_line HEADING "Setting permissions for DotKraken.sh to chmmod ugo+x"
chmod ugo+x DotKraken.sh
echo""
# If no parameters are provided is provided
if (( $# == 0 )); then
# Output error
prnt_line ERROR "Path to config-file is not provided as parameter!"
# Exit with error
exit 1
fi
# Check if parameter points to existing file
if ! [[ -f $1 ]]; then
# Output error
prnt_line ERROR "Parameter does not point to file"
# Exit with error
exit 1
fi
# Write config file path to variable
CONF_PATH=$(realpath $1)
CONF_DIR=$(dirname $CONF_PATH)
CONF_FILE=$(basename $CONF_PATH)
# Print found config file
prnt_line HEADING "Config found"
prnt_line DEFAULT "File: $CONF_FILE"
prnt_line DEFAULT "Directory: $CONF_DIR"
echo""
# Load default configuration
prnt_line HEADING "Loading default config"
source default.conf
if [[ $LOG == true ]]; then
echo "TIMESTAMP: $(date)" > $LOG_PATH
fi
prnt_line DEFAULT "default.config"
echo""
# Load custom configuration
prnt_line HEADING "Loading custom config"
source $CONF_PATH
prnt_line DEFAULT "$CONF_PATH"
echo ""
# Show parameters
prnt_line HEADING "Parameters for Backup"
prnt_line DEFAULT "DotKraken directory: $GSHLT_DIR"
prnt_line DEFAULT "Config file: $CONF_FILE"
prnt_line DEFAULT "Config directory: $CONF_DIR"
prnt_line DEFAULT "Backup destination: $BUP_PATH"
prnt_line DEFAULT "Log file: $LOG_PATH"
echo""
# Show file definition
prnt_line DEFAULT "Defined Backup Files:"
for i in ${!BUP_FILES[@]}; do
prnt_line DEFAULT "$i: ${BUP_FILES[$i]}"
done
echo ""
# Prompt parameters
prnt_line QUESTION "Proceed with this config? [y/n]"
prmpt_read
prmpt_yes
# Output message
echo ""
prnt_line HEADING "1st Step: Backup files (full path)"
# Iterate through all files
for i in "${!BUP_FILES[@]}" ; do
# Get realpath
REALPATH=$(eval "realpath ${BUP_FILES[$i]}")
# Store realpath
BUP_FILES[$i]=$REALPATH
# Output
prnt_line DEFAULT $REALPATH
done
# Output message
echo ""
prnt_line HEADING "2nd Step: Files will be deleted from Backup Directory (full path)"
# Iterate through all files
for i in "${!DEL_FILES[@]}" ; do
# Get realpath
REALPATH=$(eval "realpath ${DEL_FILES[$i]}")
# Store realpath
DEL_FILES[$i]=$REALPATH
# Output
prnt_line DEFAULT $BUP_PATH$REALPATH
done
# Prompt files
echo ""
prnt_line QUESTION "Listed files are correct? [y/n]"
prmpt_read
prmpt_yes
echo ""
# Notify on creating directory
prnt_line HEADING "Preparing destination folder"
# Check if target directory exists
if ! [[ -d $BUP_PATH ]]; then
# Output that directory will be created
prnt_line DEFAULT "Target directory does not exist"
else
# Output that directory will be cleared
prnt_line DEFAULT "Target directory exists"
rm -f -r $BUP_PATH
prnt_line DEFAULT "Target directory has been erased"
fi
# Create Backup directory
mkdir -p $BUP_PATH
prnt_line DEFAULT "Target directory has been created"
echo ""
# Copying files
prnt_line HEADING "Backup"
# Iterate through all files
for i in "${!BUP_FILES[@]}" ; do
# Copy file
mkdir -p $(eval "dirname $BUP_PATH${BUP_FILES[$i]}")
cp -r ${BUP_FILES[$i]} $BUP_PATH${BUP_FILES[$i]}
# Output
prnt_line DEFAULT "copied ${BUP_FILES[$i]}"
prnt_line DEFAULT "to $BUP_PATH${BUP_FILES[$i]}"
echo ""
done
echo ""
# Deleting files
prnt_line HEADING "Delete"
# Iterate through all files
for i in "${!DEL_FILES[@]}" ; do
# Delete file
rm -f -r $BUP_PATH${DEL_FILES[$i]}
# Output
prnt_line DEFAULT "deleted $BUP_PATH${DEL_FILES[$i]}"
done
echo ""
# Backup done
prnt_line HEADING "Backup files prepared!"
prnt_line DEFAULT "in $BUP_PATH"
# Prompt GitPush
echo ""
prnt_line QUESTION "Shall backup immediately be pushed to GitHub? [y/n]"
git_read
prmpt_yes
git_push
echo ""