-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackUp_restore_ML_AI.sh
executable file
·97 lines (79 loc) · 1.98 KB
/
backUp_restore_ML_AI.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
#! /bin/sh
pwd=$PWD
ai_resources_dir="out/production/tank_AI_-_Battle_City/resources/ai_resources/"
ai_file="tank_ai.bin"
ml_file="tanks_ml_ai.bin"
can_be_restored=0
can_be_backed_up=0
if [ -f $ai_file ] || [ -f $ml_file ] ; then
can_be_restored=1
fi
if [ -f "$ai_resources_dir$ai_file" ] || [ -f "$ai_resources_dir$ml_file" ] ; then
can_be_backed_up=1
fi
if [ $can_be_restored -eq 0 ] && [ $can_be_backed_up -eq 0 ] ; then
echo "There are no ML/AI files to back up or restore"
exit 1
fi
back_up () {
echo "Back up ML/AI data"
if [ -f "$ai_file" ] ; then
rm "$ai_file"
fi
if [ -f "$ml_file" ] ; then
rm "$ml_file"
fi
cd $ai_resources_dir
if [ -f "$ai_file" ] ; then
cp "$ai_file" "$pwd/"
fi
if [ -f "$ml_file" ] ; then
cp "$ml_file" "$pwd/"
fi
}
restore () {
echo "Restore ML/AI data"
cd "$ai_resources_dir"
if [ -f "$ai_file" ] ; then
rm "$ai_file"
fi
if [ -f "$ml_file" ] ; then
rm "$ml_file"
fi
cd "$pwd"
if [ -f "$ai_file" ] ; then
cp "$ai_file" "$ai_resources_dir"
fi
if [ -f "$ml_file" ] ; then
cp "$ml_file" "$ai_resources_dir"
fi
}
if [ $can_be_restored -eq 1 ] && [ $can_be_backed_up -eq 1 ] ; then
# selection=`zenity --list "Option 1" "Option 2" "Option 3" --column="commands: " --text="Select command" --title="Backup / restore ML-AI")`
echo "1) Back up ML and/or AI files"
echo "2) Back up ML and/or AI files"
echo "*) Quit"
read -p "Please select an option (type number) " -r opt # -n 1
if [ $opt -eq 1 ] ; then
back_up
elif [ $opt -eq 1 ] ; then
restore
else
echo "Operation cancelled"
exit 0
fi
elif [ $can_be_backed_up -eq 1 ] ; then
read -p "Do you want to back up ML/AI files? (yes/no) " -r opt # -n 1
if [ ! "$opt" = "y" ] && [ ! "$opt" = "Y" ] && [ ! "$opt" = "yes" ] ; then
echo "Operation cancelled"
exit 0
fi
back_up
else
read -p "Do you want to restore ML/AI files? (yes/no) " -r opt # -n 1
if [ ! "$opt" = "y" ] && [ ! "$opt" = "Y" ] && [ ! "$opt" = "yes" ] ; then
echo "Operation cancelled"
exit 0
fi
restore
fi