File: update-scripts

package info (click to toggle)
irssi-scripts 20131030
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,532 kB
  • ctags: 2,548
  • sloc: perl: 60,241; sh: 146; makefile: 6
file content (168 lines) | stat: -rwxr-xr-x 4,929 bytes parent folder | download | duplicates (3)
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
#!/bin/bash

if [ -f ~/.bashrc ]; then
    . ~/.bashrc # for DEBMAIL and such settings when calling dch later on
fi

ARG1="$1"

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

mysponge() {
    cat - > .tmp
    mv .tmp "$1"
}

if [ "$ARG1" != "check" ]; then
    echo -n "" > .to_dch
fi
wget -q -O .scripts.irssi.org http://scripts.irssi.org/
for i in $(sed -r -n '/NAME=/ {s,.*NAME="([^"]+)".*,\1,; p;}' .scripts.irssi.org); do
    echo script $i
    echo normal
    echo
done > INDEX.scripts.irssi.org

get_new(){
	script="$1"
	url="$2"
        echo $script >> .scriptlist
        if [ "$PARSING" != "INDEX.scripts.irssi.org" ]; then
	    sed -i "/^script ${script}$/ {N; N; d;}" INDEX.scripts.irssi.org
        fi
	if [ ! -f scripts/$script ]; then
                if [ "$ARG1" != "check" ]; then
		    echo "$script is not currently in scripts/, skipping"
                fi
		return
	fi
        if [ "$ARG1" = "nodownload" ]; then
            cp scripts/$script scripts/$script.new
        else
	    wget -q -O scripts/$script.new "$url"
        fi
        if [ "$?" != "0" ]; then
		echo "$script failed to download"
                rm -f scripts/$script.new
		return
        fi
	if diff -up scripts/$script scripts/$script.new >/dev/null; then
                if [ "$ARG1" != "check" ]; then
		    echo "$script is up to date"
                fi
		rm scripts/$script.new
	else
	        echo "$script needs updating"
                if [ "$ARG1" = "check" ]; then
                    rm scripts/$script.new
                else
                    mv scripts/$script.new scripts/$script
                    echo "$script" >> .to_dch
                fi
	fi
}

get_description() {
    sed -n "/<A NAME=\"$1\"/ {n;n;n;p}" .scripts.irssi.org | sed -r 's/.*<td>(.*)<\/td>/\1/' | perl -M"CGI qw/unescapeHTML/" -n -e 'print unescapeHTML($_);'
}

strip() {
    echo "$@" | sed -e 's/^\s*//' -e 's/\s*$//'
}

set_description() {
    scriptname=$1
    shift
    echo "$scriptname" "$(strip "$@")" >> .descriptions
}

get_description_from_dot_descriptions() {
    grep "^$1 " .descriptions | tail -1 | cut -d ' ' -f 2-
}

echo -n > .scriptlist
echo -n > .descriptions

parse() {
PARSING=$1
while read tok1 tok2 ; do
	if [ "$tok1" = script ] ; then
		script=$tok2
                if [ "$ARG1" != "check" ]; then
		    echo "$script ------------------"
                fi
	fi

	if [ "$tok1" = "url" ] ; then
	    get_new "$script" "$tok2"
	fi

        if [ "$tok1" = "normal" ]; then
		upstream_name="$tok2"
		if [ -z "$upstream_name" ]; then
			upstream_name=$script
		fi
		get_new "$script" "http://scripts.irssi.org/scripts/$upstream_name"
                if [ -z "$(get_description_from_dot_descriptions $script)" ]; then
                    set_description "$script" "$(get_description $upstream_name)"
                fi
	fi

        if [ "$tok1" = "description" ]; then
                set_description "$script" "$tok2"
        fi
done < $1
}

echo -n > update-scripts.log
for i in $(cat INDEX | awk '/^script /{print $2}'); do touch scripts/$i; done
parse INDEX | tee -a update-scripts.log
parse INDEX.scripts.irssi.org | tee -a update-scripts.log
rm INDEX.scripts.irssi.org

cat .scriptlist | sort | sort -u | mysponge .scriptlist
ls scripts/ | grep -Ev "\.(asc|new)$" > .packagedlist
cat .packagedlist | sort | sort -u | mysponge .packagedlist

cp debian/description-list .orig-description-list
echo -n > debian/description-list
COL1_LENGTH=30
for i in $(cat .packagedlist | grep -v XMMSInfo.pm); do
    NAME=$i
    DESC=$(get_description_from_dot_descriptions $i)
    if [ -z "$DESC" ]; then
        echo "No description for: $NAME"
        DESC="No Description"
    fi
    WHITESPACE=""
    for i in `seq $(( $COL1_LENGTH - $(echo -n "$NAME" | wc -c) ))`; do
        WHITESPACE="$WHITESPACE "
    done
    echo "${NAME}${WHITESPACE}${DESC}" >> debian/description-list
done
rm .descriptions

./debian/rewrap.pl | mysponge debian/description-list
if ! diff .orig-description-list debian/description-list >/dev/null; then
    echo "Some descriptions have been changed"
fi
rm .orig-description-list

diff .scriptlist .packagedlist | grep "^>" | awk '{print $2}' | sort > .missinglist
rm .scriptlist .packagedlist
sed -e '/^Known-Missing:/ !d' -e 's/^Known-Missing: //' -e 's/,//g' -e 's/ /\n/g' debian/copyright | sort > .knownlist
if [ -n "$(diff .knownlist .missinglist)" ]; then
    echo "These are the differences between the known missing upstreams and the discovered missing upstreams:" | tee -a update-scripts.log
    diff .knownlist .missinglist | egrep "^[><]" | tee -a update-scripts.log
fi
rm .missinglist .knownlist

if [ "$ARG1" != "check" ]; then
    STR="$(perl -e 'open F, ".to_dch"; my @a = <F>; close F; chomp $_ foreach(@a); my $s = join(", ", @a); print "Updated: " . $s . "\n" if(length($s) > 0);')"
    if [ -n "$STR" ]; then
        dch "$STR"
        echo "$STR"
    fi
    rm .to_dch
fi
rm .scripts.irssi.org