forked from KD4Z/md380tools-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rotatebins
54 lines (49 loc) · 1.52 KB
/
rotatebins
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
#!/bin/bash
# rotatebins
# KD4Z
# Version: 3.14
# Rotates archive directory 2-9 iterations
# previous is really number 1
F0="../archive/firmware-OLD.bin"
F1="../archive/firmware-noGPS.bin"
F2="../archive/firmware-GPS.bin"
F3="../archive/user.bin"
D0="$(dirname "$F0")"
E0=${F0##*.}
B0="$(basename "$F0" ."$E0")"
D1="$(dirname "$F1")"
E1=${F1##*.}
B1="$(basename "$F1" ."$E1")"
D2="$(dirname "$F2")"
E2=${F2##*.}
B2="$(basename "$F2" ."$E2")"
D3="$(dirname "$F3")"
E3=${F3##*.}
B3="$(basename "$F3" ."$E3")"
if [ -e "$F1" ] ; then
echo -e "${YELLOW}Rotating firmware binaries${GREEN}"
for i in 8 7 6 5 4 3 2; do
s="$D0/$B0.$E0.$i"
echo -e "$s"
test -e "$s" && mv $s "$D0/$B0.$E0.$((i+1))"
s="$D1/$B1.$E1.$i"
echo -e "$s"
test -e "$s" && mv $s "$D1/$B1.$E1.$((i+1))"
s="$D2/$B2.$E2.$i"
test -e "$s" && mv $s "$D2/$B2.$E2.$((i+1))"
s="$D3/$B3.$E3.$i"
test -e "$s" && mv $s "$D3/$B3.$E3.$((i+1))"
:;
done &&
test -e "$D0/$B0.$E0.previous" && mv "$D0/$B0.$E0.previous" "$D0/$B0.$E0.2"
test -e "$D1/$B1.$E1.previous" && mv "$D1/$B1.$E1.previous" "$D1/$B1.$E1.2"
test -e "$D2/$B2.$E2.previous" && mv "$D2/$B2.$E2.previous" "$D2/$B2.$E2.2"
test -e "$D3/$B3.$E3.previous" && mv "$D3/$B3.$E3.previous" "$D3/$B3.$E3.2"
mv "$F0" "$D0/$B0.$E0.previous"
mv "$F1" "$D1/$B1.$E1.previous"
mv "$F2" "$D2/$B2.$E2.previous"
mv "$F3" "$D3/$B3.$E3.previous"
else
echo "File $F1 does not exist"
fi
echo -e "{NC}"