summaryrefslogtreecommitdiffstats
path: root/bin/padd.sh
blob: c561fc687876dc10a040771da2bc7a0194ae791d (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
#!/bin/sh

set -e

case "$(basename ${0})" in
	p*)
		MODE="progress-linux"
		;;

	b*)
		MODE="bfh"
		;;
esac

HOSTNAME="$(hostname -f)"

RED="\033[1;33;31m"
GREEN="\033[1;33;32m"
YELLOW="\033[1;33;33m"
BLUE="\033[1;33;34m"
WHITE="\033[1;33;37m"
NORMAL="\033[0m"
PURPLE="\033[1;33;35m"

case "${MODE}" in
	progress-linux)
		CHANNELS="progress-linux bfh-linux-systems"
		;;

	bfh)
		CHANNELS="bfh-linux-systems"
		;;
esac

Irk ()
{
	MESSAGE="${1}"

	echo ${MESSAGE}

	for CHANNEL in ${CHANNELS}
	do
		irk irc://irc.oftc.net:7000/${CHANNEL} ${MESSAGE}
	done
}

ARCHITECTURES="arm64 armel armhf amd64 i386"

case "$(basename ${PWD})" in
	*_arm64)
		_ARCH="arm64"
		;;

	*_armel)
		_ARCH="armel"
		;;

	*_armhf)
		_ARCH="armhf"
		;;

	*_amd64)
		_ARCH="amd64"
		;;

	*_i386)
		_ARCH="i386"
		;;

	*_all)
		_ARCH="all"
		;;

	*_source)
		_ARCH="source"
		;;
esac

#_DIST="$(cd ../../../ && echo $(basename ${PWD}))"

case "${_ARCH}" in
	source)
		#_DIST="$(grep -m1 '^Distribution: ' *.dsc | awk '{ print $2 }')"
		_DIST="$(pwd | awk -F/ '{ print $5 }')"
		_PACKAGE="$(basename *.dsc .dsc | awk -F_ '{ print $1 }')"
		;;

	*)
		_DIST="$(grep -m1 '^Distribution: ' *.changes | awk '{ print $2 }')"
		_PACKAGE="$(basename *.changes .changes | awk -F_ '{ print $1 }')"
		;;
esac

# HACK
_POOL="/srv/${HOSTNAME}/packages"

if ls *.dsc > /dev/null 2>&1
then
	echo "### Removing ${_PACKAGE} sources..."

	# Remove source and binary upload
	reprepro -b ${_POOL} removesrc ${_DIST} ${_PACKAGE} || true

	# Include source upload
	echo "### Including ${_PACKAGE} upload..."
	reprepro -b ${_POOL} ${_REPREPRO_OPTIONS} includedsc ${_DIST} *.dsc
else
	#echo "### Removing ${_PACKAGE} binary..."
	## Remove binary upload
	#reprepro -b ${_POOL} --architecture ${_ARCH} remove ${_DIST} ${_PACKAGE} || true

	echo "### Including ${_PACKAGE} upload..."
	reprepro -b ${_POOL} ${_REPREPRO_OPTIONS} include ${_DIST} *.changes
fi

if [ "${1}" != "quiet" ]
then
	case "${_ARCH}" in
		source)
			FILE="dsc"
			;;
		*)
			FILE="changes"
			;;
	esac

	_SOURCE="$(grep -m1 '^Source: ' *.${FILE} | awk '{ print $2 }')"
	_VERSION="$(grep -m1 '^Version: ' *.${FILE} | awk '{ print $2 }')"
	#_URGENCY="$(grep -m1 '^Urgency: ' *.${FILE} | awk '{ print $2 }')"
	_URGENCY="$(grep -m1 '^Urgency: ' *.${FILE} | awk '{ print $2 }')"
	#_DISTRIBUTION="$(grep -m1 '^Distribution: ' *.${FILE} | awk '{ print $2 }')"
	_DISTRIBUTION="${_DIST}"
	#_ARCHITECTURE="$(grep -m1 '^Architecture: ' *.${FILE} | awk '{ $1=""; print $0 }' | sed -e 's|^ ||')"
	_ARCHITECTURE="${_ARCH}"

	_UPLOADER="$(grep -m1 '^Changed-By: ' *.${FILE} | awk -F: '{ print $2 }' | sed -e 's|^ ||' -e 's|<.*||')"

	case "${_ARCH}" in
		source)
			;;

		*)
			if grep -qs '^Closes: ' *.changes
			then
				_BUGS="(Closes: ${PURPLE}$(grep -m1 '^Closes: ' *changes | sed -e 's|^Closes: |#|' -e "s| |\\\033\\[0m, \\\033\\[1;33;35m#|g")${NORMAL})"
			fi
			;;
	esac

	case "${_ARCH}" in
		source)
			Irk "${GREEN}${_SOURCE}${NORMAL} ${_VERSION} [${_ARCHITECTURE}] uploaded  to ${BLUE}${_DISTRIBUTION}${NORMAL}"
			;;

		*)
			Irk "${GREEN}${_SOURCE}${NORMAL} ${_VERSION} [${_ARCHITECTURE}] uploaded to ${BLUE}${_DISTRIBUTION}${NORMAL} with urgency ${RED}${_URGENCY}${NORMAL} by ${YELLOW}${_UPLOADER}${NORMAL}${_BUGS}"
			;;
	esac
	#twidge update "uploaded ${_SOURCE} ${_VERSION} to ${_DISTRIBUTION} #progress_linux"
fi