-
Notifications
You must be signed in to change notification settings - Fork 0
/
SistemRestore.sh
106 lines (98 loc) · 2.55 KB
/
SistemRestore.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
#! /bin/sh
###Begin Info
# Name : Sisrestore
# Required software : tar, lzma
# Short-Description : Make deepfreezed like system
# Author / Copyright : Gian Giovani <wejick@gmail.com> wejick.wordpress.com
# License : GPL
### END Info
PATH="/:$PATH"; export PATH
. /etc/sisrestore.conf
# Function
stat_en() {
echo "ENABLED" > $status_file
echo "Backup file : $(ls -l $srpath | grep kodinbak)" >> $status_file
echo "Work mode : $wmode" >> $status_file
echo "Action Mode : $amode" >> $status_file
echo "target : $target" >> $status_file
}
do_res() {
if [ -r $srpath/kodinbak.tar ] || [ -r $srpath/kodinbak.tar.lzma ]; then
rm -rf $target
else
echo "$(date +%F===%H:%m:%S) You must create backup file before. See the documentation" >> $log_file
echo "You must create backup file before. See the documentation"
fi
rsarchive
}
# Function switcher
# Make Archive
if [ $amode -eq 1 ]; then
mkarchive() {
cd /
tar -cf kodinbak.tar $target
mv /kodinbak.tar $srpath
if [ $? -eq 0 ]; then
echo "$(date +%F===%H:%m:%S) backup file created" >> $log_file
echo " $(ls -a $srpath/kodinbak.tar)" >> $log_file
else
echo "$(date +%F===%H:%m:%S) failed to create backup file" >> $log_file
fi
}
elif [ $amode -eq 2 ]; then
mkarchive() {
cd /
tar --lzma -cf kodinbak.tar.lzma $target
mv /kodinbak.tar.lzma $srpath
if [ $? -eq 0 ]; then
echo "$(date +%F===%H:%m:%S) backup file created" >> $log_file
echo " $(ls -a $srpath/kodinbak.tar.lzma)" >> $log_file
else
echo "$(date +%F===%H:%m:%S) failed to create backup file" >> $log_file
fi
}
else
echo "$(date +%F===%H:%m:%S) Archive Mode not supported" >> $log_file
echo "Archive Mode not supported"
fi
# Restore Archive
if [ $amode -eq 1 ]; then
rsarchive() {
cd /
tar -xf $srpath/kodinbak.tar
}
elif [ $amode -eq 2 ]; then
rsarchive() {
cd /
tar --lzma -xf $srpath/kodinbak.tar.lzma
}
else
echo "$(date +%F===%H:%m:%S) Archive Mode not supported" >> $log_file
echo "Archive Mode not supported"
fi
###Text ui###
# Act as text ui
# May I separate it?
if [ "$1" = "enable" ]; then
mkarchive
ls -l $srpath | grep kodinbak
sh /usr/share/kompudini/sr/srsetinit.sh
stat_en
elif [ "$1" = "disable" ]; then
rm -rf $srpath/kodinbak.ta*
ls -l $srpath | grep kodinbak
echo "DISABLED" > $status_file
chmod -x /$INITPATH/sisrestore
elif [ "$1" = "reload" ]; then
sh /usr/share/kompudini/sr/srsetinit.sh
stat_en
elif [ "$1" = "restore" ]; then
do_res
echo "Working"
sleep 3
echo "finnish"
elif [ "$1" = "help" ]; then
cat /usr/share/kompudini/sr/srhelp
else
echo "try help"
fi