forked from openSUSE/obs-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vc
executable file
·158 lines (144 loc) · 3.55 KB
/
vc
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
#!/bin/bash
# use this script to edit *.changes files
#
# based on changelog edit script from xqf
#
# Copyright (C) 2002 Ludwig Nussel
# Copyright (C) 2009 SUSE Linux Products GmbH, Nuernberg, Germany.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 or 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
shopt -s nullglob
if [ -z "$mailaddr" ]; then
domain=`dnsdomainname`
[ -z "$domain" ] && domain=localhost
mailaddr="$USER@$domain"
fi
EDITOR=${EDITOR:-vim}
date=`LC_ALL=POSIX TZ=UTC date`
if ! which mktemp > /dev/null 2>&1; then
echo "mktemp is required for this script to work"
exit 1
fi
while [ -n "$1" ]; do
case "$1" in
-m)
if [ $just_edit ]; then
echo "You cannot use -m and -e together!"
exit 1
fi
message="$2"
shift 2
;;
-e)
if [ -n "${message}" ]; then
echo "You cannot use -m and -e together!"
exit 1
fi
just_edit=true
shift 1
;;
--help)
echo "Usage: $0 [-m MESSAGE|-e] [filename[.changes]|path [file_with_comment]]"
echo
echo "Will use '$mailaddr' for changelog entries"
echo
echo "Options:"
echo " -m MESSAGE add MESSAGE to changes (not open an editor)"
echo " -e just open changes (cannot be used with -m)"
exit 0
;;
*) break ;;
esac
done
changelog="$1"
content="$2"
pkgpath=
if [ -n "$changelog" -a -d "$changelog" ]; then
pkgpath="$changelog/"
changelog=''
fi
if [ -n "$changelog" ]; then
if [ "${changelog%.changes}" = "$changelog" ]; then
changelog="$changelog.changes"
fi
else
changelog=($pkgpath*.changes)
if [ "${#changelog[@]}" -eq 1 ]; then
changelog="$changelog"
elif [ -n "$changelog" ]; then
echo "Choose one of ${changelog[@]}"
exit 1
fi
fi
if [ -z "$changelog" ]; then
changelog=($pkgpath*.spec)
if [ "${#changelog[@]}" -eq 1 ]; then
changelog=${changelog%.spec}.changes
elif [ -n "$changelog" ]; then
echo "Choose one of ${changelog[@]}"
exit 1
fi
fi
if [ -z "$changelog" ]; then
echo "no .changes and no .spec file found"
exit 1
fi
if [ ! -e "$changelog" ]; then
created_new_changelog=true
touch $changelog
fi
tmpfile=`mktemp -q $changelog.vctmp.XXXXXX`
if [ $? -ne 0 ]; then
echo "$0: Can't create temp file, exiting..."
exit 1
fi
trap "rm -f \"$tmpfile\"" EXIT
set +e
{
if [ ! $just_edit ]; then
echo "-------------------------------------------------------------------"
echo "$date - $mailaddr"
echo
fi
if [ -n "$message" ]; then
echo -e "- $message"
echo
elif [ -n "$content" ]; then
cat "$content"
echo
elif [ ! $just_edit ]; then
echo "- "
echo
fi
cat $changelog
} >> "$tmpfile"
if [ -z "$message" ]; then
set -- `md5sum "$tmpfile"`
chksum="$1"
$EDITOR +4 "$tmpfile"
set -- `md5sum "$tmpfile"`
if [ -z "$content" -a "$chksum" == "$1" ]; then
echo "no changes made"
if [ "$created_new_changelog" = true ]; then
rm -f "$changelog"
fi
exit 0
fi
fi
mode=`stat -c "%a" "$changelog"`
user=`stat -c "%u:%g" "$changelog"`
mv "$tmpfile" "$changelog"
chmod $mode "$changelog"
chown $user "$changelog"