Newer
Older
#!/bin/bash
# Turris OS version handling script
# (C) 2018 CZ.NIC, z.s.p.o.
#
# 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 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, see <http://www.gnu.org/licenses/>.
news_file="$(dirname "$(dirname "$(readlink -f "$0")")")/NEWS"
get_version() {
sed -n '/^-\+$/{x;p;q}; x' "$news_file"
}
news_text() {
awk '/^-+$/{if(flg) nextfile; else flg=1;next} flg==1{prev=$0;flg=2;next} flg==2{print prev;prev=$0}' "$news_file" | \
sed '/^$/d;s/^[[:blank:]]*\*[[:blank:]]*/ • /'
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
}
gen_package() {
version="$(get_version)"
mkdir -p "$output"
cd "$output"
# Generate package
cat > Makefile << EOF
#
## Copyright (C) $(date +%Y) CZ.NIC z.s.p.o. (http://www.nic.cz/)
#
## This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
# #
#
include \$(TOPDIR)/rules.mk
PKG_NAME:=turris-version
PKG_VERSION:=$version
PKG_MAINTAINER:=CZ.NIC <packaging@nic.cz>
include \$(INCLUDE_DIR)/package.mk
define Package/turris-version
TITLE:=turris-version
endef
define Build/Prepare
endef
define Build/Compile
endef
define Package/turris-version/postinst
#!/bin/sh
# Danger: spaces are not ordinary spaces, but special unicode ones
[ -n "\$\$IPKG_INSTROOT" ] || {
create_notification -s news "$(news_text | sed 's/"/\\"/')"
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
}
endef
define Package/turris-version/install
\$(INSTALL_DIR) \$(1)/etc
echo \$(PKG_VERSION) > \$(1)/etc/turris-version
endef
\$(eval \$(call BuildPackage,turris-version))
EOF
}
output=.
operation=
while [ $# -gt 0 ]; do
case "$1" in
-h|--help)
echo "Turris version from NEWS file."
echo "Usage: $0 [OPTION].. OPERATION"
echo
echo "Operations:"
echo " version"
echo " Prints version parsed from NEWS file. This is default operation."
echo " package"
echo " Generate turris-version package from NEWS file."
echo
echo "Options:"
echo " --output PATH"
echo " Path used as output for package command."
echo " --help, -h"
echo " Print this help text."
exit 0
;;
--output)
shift
output="$1"
;;
version|package)
operation="$1"
;;
*)
echo "Unknown argument: $1" >&2
exit 1
;;
esac
shift
done
[ -n "$operation" ] || operation=version
[ -f "$news_file" ] || {
echo "Error: NEWS file not located!" >&2
exit 1
}
case "$operation" in
version)
get_version
;;
package)
gen_package
;;
esac