-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup.sh
44 lines (38 loc) · 1.01 KB
/
setup.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
#!/bin/bash
set -e
SCRIPT_DIR=$( cd $( dirname $(readlink -f ${BASH_SOURCE[0]}) ) && pwd )
CONFIG_DIR=${SCRIPT_DIR}/.obsidian
helpFunc(){
echo ""
echo "Usage: ./setup.sh backup/restore"
echo ""
echo -e " ./setup.sh backup \t Back up config files before open"
echo -e " \t the vault for the first time"
echo -e " ./setup.sh restore \t Restore config files with backup"
exit 1
}
backup(){
for entry in $(ls ${CONFIG_DIR}); do
if (test -f ${CONFIG_DIR}/${entry}) ; then
cp "${CONFIG_DIR}/${entry}" "${CONFIG_DIR}/${entry}.bak"
fi
done
}
restore(){
for entry in $(ls ${CONFIG_DIR}); do
if (test -f ${CONFIG_DIR}/${entry}.bak) ; then
mv "${CONFIG_DIR}/${entry}.bak" "${CONFIG_DIR}/${entry}"
fi
done
}
setup() {
if [ $# = 0 ] || [ $1 = "-h" ] || [ $1 = "--help" ]; then
helpFunc
fi
case $1 in
"backup" ) backup;;
"restore" ) restore;;
?) helpFunc;;
esac
}
setup $@