-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.sh
executable file
·98 lines (82 loc) · 2.11 KB
/
cleanup.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
#!/bin/bash
##
## Cleanup script, removes orphaned bouquet files
##
## (c) 2019 PLi Association, WanWizard
##
## 20190911 - Initial version
##
################################################################################
# Function: clean a direcory based on an index file
################################################################################
function cleanup
{
# array for the userbouquets
BOUQUETS=()
# make sure we have all arguments
if [ "$#" -ne "2" ]; then
echo "Incorrect number of arguments to cleanup()!"
exit 1
fi
# validate arguments
if [ ! -d $1 ]; then
echo "cleanup() : $1 is not a valid directory"
exit 1
fi
if [ "$2" != "tv" -a "$2" != "radio" ]; then
echo "cleanup() : second parameter must be either \"tv\" or \"radio\"!"
exit 1
fi
echo "- Processing $2 in $1..."
# loop over the index file
while IFS="" read -r line || [ -n "$line" ]; do
line=`echo $line | cut -d'"' -f 2`
# add it to the list if it is a userbouquet
if [[ $line = userbouquet* ]]; then
BOUQUETS+=($line)
if [ ! -f $1/$line ]; then
echo " Missing bouquet: $line"
fi
fi
done < $1/bouquets.$2
# loop over the userbouquet files
cd $1
for f in userbouquet.*.$2; do
if [[ ! " ${BOUQUETS[@]} " =~ " ${f} " ]]; then
echo " Orphaned bouquet: $f"
rm -f $f
fi
done
cd - > /dev/null
}
################################################################################
# Variables controlling the process.
################################################################################
CHECK=0
# check if we're in the right repo directory
if [ -f .git/config ]; then
if grep -q "technl/Hanssettings" .git/config ; then
CHECK=1
fi
fi
# bail out if we're not
if [ $CHECK -eq 0 ]; then
echo "This directory doesn't contain the HansSettings repository!"
exit 1
fi
# iterate over the directory
for d in *; do
# we're only intrested in directories
if [ -d $d ]; then
# does it have a TV bouquets index file
if [ -f $d/bouquets.tv ]; then
cleanup $d tv
fi
# does it have a radio bouquets index file
if [ -f $d/bouquets.radio ]; then
cleanup $d radio
fi
fi
done
# done
exit 0