-
Notifications
You must be signed in to change notification settings - Fork 0
/
srb
executable file
·173 lines (152 loc) · 5.55 KB
/
srb
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
#!/bin/bash
# $Id$
#
# SystemRescue-Backup
#
# SystemRescue-Backup is free software; you can distribut it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the license, or
# (at your option) any later version.
#
# SystemRescue-Backup is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with SystemRescue-Backup; it not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors:
# See https://github.com/erenfro/systemrescue-backup/graphs/contributors
scriptPath="$(dirname "$(readlink -f "$0")")"
#configPath="$(dirname "$(readlink -f "${scriptPath}/../config")")"
if [[ -r "${scriptPath}/functions.sh" ]]; then
source "${scriptPath}/functions.sh"
else
echo "FATAL: Cannot find installed engine."
exit 255
fi
showHelp() {
local section="$1"
echo "No help yet"
echo "Usage: $0 [global-options] <command> [options]"
echo
echo "Commands:"
echo " backup Perform system backup"
echo " restore Perform system restore"
echo " recovery Update/Generate system recovery disc image"
echo
echo "Global Options:"
echo " --debug, -d Enable Debug Logging"
echo " --help, -h Show this help"
echo " --version, -v Show current SystemRescue Backup version"
echo
echo "Options (per command):"
if [[ -z "$section" || "$section" == "backup" ]]; then
echo "backup:"
echo " --exclude=<pattern> Exclude devices matching the pattern from backup"
echo " --exclude-file=<file> Exclude devices listed in the specified file from backup"
echo
fi
if [[ -z "$section" || "$section" == "restore" ]]; then
echo "restore:"
echo " --exclude=<pattern> Exclude devices matching the pattern from restore"
echo " --exclude-file=<file> Exclude devices listed in the specified file from restore"
echo " --rename=\"<old> <new>\" Rename a device during the restore process"
echo " --no-uuid Disable restoring of UUIDs during restore"
echo " --no-partition Disable restoring of disk partitions during restore"
echo
fi
if [[ -z "$section" || "$section" == "recovery" ]]; then
echo "recovery:"
echo " --cd-version=ver System Rescue CD version to use: $systemrescue_cd_version"
echo
fi
echo "Examples:"
echo " $0 backup --exclude=/dev/sda1"
echo " $0 restore --rename=\"/dev/sda /dev/sdb\""
echo
}
# Main function to handle command-line arguments and invoke appropriate functions
main() {
local help=false
local -a positional_args
while [[ $# -gt 0 ]]; do
case $1 in
-h|--help)
help=true
shift
#showHelp
#exit 0
;;
-d|--debug)
debug=true;
shift
;;
-v|--version)
echo "SystemRescue Backup version v${systemrescue_version}"
exit 0
;;
*)
positional_args+=("$1") # save positional arg
shift
;;
esac
done
set -- "${positional_args[@]}" # restore positional args
if $help; then
showHelp "$1"
exit 0
fi
case "$1" in
backup)
echo "SystemRescue Backup -- Backup Mode"
;;
restore)
echo "SystemRescue Backup -- Restore Mode"
;;
recovery)
shift
while [[ "$#" -gt 0 ]]; do
case "$1" in
--cd-version=*)
systemrescue_cd_version="${1#*=}"
echoreg -d "Args: SystemRescueCD Version = $systemrescue_cd_version"
shift
;;
--cd-url=*)
systemrescue_cd_url="${1#*=}"
echoreg -d "Args: SystemRescueCD Download url = $systemrescue_cd_url"
shift
;;
*)
echo "Invalid option: $1"
echo "Use --help to display the help message."
exit 1
;;
esac
done
echo "SystemRescue Backup -- Recovery CD"
echoreg -d "opt: $*"
run_modules recovery
# if ! load_module recovery init; then
# exit_fail 200 "FATAL: Failed to load recovery init module. ($?)"
# fi
# if ! load_module "$backup_engine" init; then
# exit_fail 201 "FATAL: Failed to load '$backup_engine' init module. ($?)"
# fi
# load_config
# if ! load_module "$backup_engine" prepare; then
# exit_fail 202 "FATAL Failed to load '$backup_engine' prepare module. ($?)"
# fi
;;
*)
echo "Invalid command: $1"
echo "Use --help to display the help message."
exit 1
;;
esac
}
# Call the main function with all arguments
main "$@"