summaryrefslogtreecommitdiffstats
path: root/update-scripts
blob: 0bda7a50ebf45c75d39b600129d4e1a77eb5690c (plain)
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/bin/bash

usage () {
    printf "\nUsage:\n"
    printf "\t update-scripts [options]\n\n"
    printf "Options:\n\n"
    printf "\t -c, --check    Don't actually apply any changes.\n"
    printf "\t -n, --nodown   Don't download any scripts.\n"
    printf "\t -h, --help     Print this help text.\n\n"
}

parse () {
    while read -r col1 col2; do
	case $col1 in
	    script)
		if [[ $scrdup = no && $scrpack = yes ]]; then
		    if [ "$urlfnd" = "no" ]; then
			echo "$script has no upstream source."
			printf "url\t\tNo upstream source.\n" >> INDEX
		    fi
		    if [ "$descfnd" = "no" ]; then
			echo "$script has no description."
			printf "description\tNo description.\n\n" >> INDEX
			printf "%-29s No description.\n" "$script" >> debian/description-list
		    fi
		fi
		script="$col2"
		urlfnd="no"
		descfnd="no"
		if ! grep -q "^$script$" .scriptlist; then
		    scrdup="no"
		    echo "$script --------------------"
		    echo "$script" >> .scriptlist
		    if grep -q "^$script$" .packagedlist; then
		    	scrpack="yes"
			printf "script\t\t%s\n" "$script" >> INDEX
		    else
		    	scrpack="no"
			echo "$script is not included yet, skipping."
			echo "$script" >> .nonincludes
		    fi
		else
		    scrdup="yes"
		fi
		;;
	    url)
		urlfnd="yes"
		url="$col2"
		if [[ $scrdup = no && $scrpack = yes ]]; then
		    if [[ $url =~ ^(https?|ftps?):// ]]; then
			printf "url\t\t%s\n" "$url" >> INDEX
			if [ "$nodown" != "yes" ]; then
			    get_new "$script" "$url"
			fi
		    else
			echo "$script has no upstream source."
			printf "url\t\tNo upstream source.\n" >> INDEX
		    fi
		fi
		;;
	    description)
		descfnd="yes"
		desc="$col2"
		if [[ $scrdup = no && $scrpack = yes ]]; then
		    if [ "$urlfnd" = "no" ]; then
			urlfnd="yes"
			echo "$script has no upstream source."
			printf "url\t\tNo upstream source.\n" >> INDEX
		    fi
		    if [ -z "$desc" ]; then
			echo "$script has no description."
			desc="No description."
		    fi
		    printf "description\t%s\n\n" "$desc" >> INDEX
		    printf "%-29s %s\n" "$script" "$desc" >> debian/description-list
		fi
		;;
	esac
    done <<< "$1" | tee -a update-scripts.log
}

get_new () {
    script="$1"
    url="$2"
    wget -t 5 -T 10 -qO "scripts/$script.new" "$url" || {
	echo "$script failed to download."
	rm "scripts/$script.new"
	return
    }
    if diff "scripts/$script" "scripts/$script.new" > /dev/null; then
	echo "$script is up to date."
	rm "scripts/$script.new"
    else
	echo "$script needs updating."
	echo "$script" >> .changes
	if [ "$noapply" != "yes" ]; then
	    mv "scripts/$script.new" "scripts/$script"
	else
	    rm "scripts/$script.new"
	fi
    fi
}

opts=$(getopt -o "cnh" -l "check,nodown,help" -- "$@")
eval set -- "$opts"

while true; do
    case $1 in
	-c|--check)
	    noapply="yes"
	    shift
	    ;;
	-n|--nodown)
	    nodown="yes"
	    shift
	    ;;
	-h|--help)
	    usage
	    exit 0
	    ;;
	--)
	    shift
	    break
	    ;;
    esac
done

shopt -s extglob

debclean > /dev/null 2>&1 || exit 1

### Main

indexweb=$(wget -t 5 -T 10 -qO - http://scripts.irssi.org/) && {
    wording="Downloaded"
    indexweb=$(sed -ne '/<tr>/,/<\tr>/ {/<tr>/h; /<tr>/!H; /<\/tr>/ {g; /<td class="filename">.*<small>.*<td class="description">/ '\
'{s/[[:space:]]\+/ /g;s/[^[:print:]]//g;s@^.*<td class="filename">.*<a href="[^"]*/\([^/"]\+\)".*<small>.*<a href="\([^"]\+\)"'\
'.*<td class="description">\([^<]*\)</td>.*$@script\t\t\1\nurl\t\t\2\ndescription\t\3\n@;s|\(github.com/.*\)/blob/|\1/raw/|g;p}}}' <<< "$indexweb" \
    | perl -MHTML::Entities -ne 'print decode_entities($_)')
} || wording="Could not download"
printf "\n%s web index.\n\n" "$wording" | tee update-scripts.log

indexcurr=$(sed -n 's/^\(script\|\url\)[ \t]\+/\1\t\t/p;s/^\(description\)[ \t]\+\(.*\)$/\1\t\2\n/p' INDEX)
touch $(awk -F '[\t]+' '$1 == "script" {print "scripts/" $2}' <<< "$indexcurr")

packlist=(scripts/!(*.asc|*.new|XMMSInfo.pm))
packlist=("${packlist[@]##*/}")
printf "%s\n" "${packlist[@]}" > .packagedlist

mv INDEX INDEX.orig
mv debian/description-list debian/description-list.orig
> .scriptlist
> .changes
> .nonincludes

parse "$indexweb"
parse "$indexcurr"

buffer=$(sort .scriptlist)
echo "$buffer" > .scriptlist

### Index

if ! diff INDEX.orig INDEX > /dev/null; then
    if [ "$noapply" != "yes" ]; then
	wording="has been updated"
	rm INDEX.orig
    else
    	wording="needs updating"
	mv INDEX.orig INDEX
    fi
    printf "\nThe index file %s.\n" "$wording" | tee -a update-scripts.log
fi

### Descriptions

buffer=$(sort -t ' ' -k 1,1 debian/description-list)
echo "$buffer" > debian/description-list

buffer=$(debian/rewrap.pl)
echo "$buffer" > debian/description-list

if ! diff debian/description-list.orig debian/description-list > /dev/null; then
    if [ "$noapply" != "yes" ]; then
	wording="has been updated"
	rm debian/description-list.orig
    else
    	wording="needs updating"
	mv debian/description-list.orig debian/description-list
    fi
    printf "\nThe description list %s.\n" "$wording" | tee -a update-scripts.log
fi

### Missing

diff .scriptlist .packagedlist | awk '/^>/ {print $2}' > .missinglist
rm .scriptlist .packagedlist

sed -n '/^Known-Missing:/ {s/^Known-Missing: //;s/, /\n/g;p}' debian/copyright | sort > .knownlist
missdiff=$(diff .knownlist .missinglist | grep '^[><]')
if [ -n "$missdiff" ]; then
    printf "\nThese are the differences between the known missing\nupstreams and the discovered missing upstreams:\n%s\n" "$missdiff" \
    	| tee -a update-scripts.log
fi
rm .missinglist .knownlist

### Changes

changes=$(sed -n '1 h; 2,$ {s/^.\+$/, &/;H}; $ {g;s/\n//g;p}' .changes)
if [ -n "$changes" ]; then
    if [ "$noapply" != "yes" ]; then
    	wording="Updated"
	dch "Update: $changes"
    else
    	wording="Updating needed"
    fi
    printf "\n%s: %s\n" "$wording" "$changes" | tee -a update-scripts.log
fi
rm .changes

### Non-includes

nonincludes=$(sed -n '1 h; 2,$ {s/^.\+$/, &/;H}; $ {g;s/\n//g;p}' .nonincludes)
if [ -n "$nonincludes" ]; then
    printf "\nNot included: %s\n" "$nonincludes" | tee -a update-scripts.log
fi
rm .nonincludes