From 99e08e37b317d3998a92803f0afa55c70aea25ee Mon Sep 17 00:00:00 2001 From: was4444 Date: Wed, 22 Feb 2017 12:19:52 +0800 Subject: [PATCH] genrpm changes (#1292) * auto select latest version * bash-completion comes with version 2.6.0 * version greater than 2.6.2 need submodules packed * adjust version check order --- rpm/SPECS/shadowsocks-libev.spec.in | 8 ++++++++ rpm/genrpm.sh | 27 +++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/rpm/SPECS/shadowsocks-libev.spec.in b/rpm/SPECS/shadowsocks-libev.spec.in index c920e084..36168177 100644 --- a/rpm/SPECS/shadowsocks-libev.spec.in +++ b/rpm/SPECS/shadowsocks-libev.spec.in @@ -1,3 +1,6 @@ +%bcond_with completion + + Name: shadowsocks-libev Version: VERSION Release: 1%{?dist} @@ -73,8 +76,11 @@ install -m 644 %{_builddir}/%{buildsubdir}/debian/shadowsocks-libev.service %{bu install -m 644 %{_builddir}/%{buildsubdir}/debian/shadowsocks-libev-*.service %{buildroot}%{_unitdir}/ %endif install -m 644 %{_builddir}/%{buildsubdir}/debian/config.json %{buildroot}%{_sysconfdir}/shadowsocks-libev/config.json + +%if %{with completion} mkdir -p %{buildroot}%{_datadir}/bash-completion/completions/ install -m 644 %{_builddir}/%{buildsubdir}/completions/bash/* %{buildroot}%{_datadir}/bash-completion/completions/ +%endif %pre %if 0%{?use_systemd} && 0%{?suse_version} @@ -126,7 +132,9 @@ fi %{_bindir}/* %{_libdir}/*.so.* %config(noreplace) %{_sysconfdir}/shadowsocks-libev/config.json +%if %{with completion} %{_datadir}/bash-completion/completions/* +%endif %doc %{_mandir}/* %if ! 0%{?use_systemd} %{_initddir}/shadowsocks-libev diff --git a/rpm/genrpm.sh b/rpm/genrpm.sh index 3c10c6c2..27d87d11 100755 --- a/rpm/genrpm.sh +++ b/rpm/genrpm.sh @@ -1,20 +1,28 @@ #!/usr/bin/env bash set -e +g_version=$(git tag -l v* | sort --version-sort | tail -1) +g_version=${g_version#"v"} + show_help() { echo -e "`basename $0` [option] [argument]" echo echo -e "Options:" echo -e " -h show this help." - echo -e " -v with argument version (3.0.2 by default)." - echo -e " -f with argument format (tar.xz by default) used by git archive." + echo -e " -v with argument version (${g_version} by default)." + echo -e " -f with argument format (tar.gz by default) used by git archive." echo echo -e "Examples:" echo -e " to build base on version \`2.4.1' with format \`tar.xz', run:" echo -e " `basename $0` -f tar.xz -v 2.4.1" } +version_greater_equal() +{ + [ "$1" = $(printf "$1\n$2\n" | sort --version-sort | tail -1) ] +} + while getopts "hv:f:" opt do case ${opt} in @@ -38,9 +46,15 @@ do esac done -: ${version:=3.0.2} +: ${version:=${g_version}} : ${format:=tar.gz} +supported_max_version="2.6.2" +if ! version_greater_equal ${supported_max_version} ${version}; then + echo "version(${version}) greater than ${supported_max_version} are not currently supported." + exit 1 +fi + name="shadowsocks-libev" spec_name="shadowsocks-libev.spec" @@ -52,4 +66,9 @@ sed -e "s/^\(Version: \).*$/\1${version}/" \ -e "s/^\(Source0: \).*$/\1${name}-${version}.${format}/" \ SPECS/"${spec_name}".in > SPECS/"${spec_name}" -rpmbuild -bb SPECS/"${spec_name}" --define "%_topdir `pwd`" +completion_min_verion="2.6.0" +version_greater_equal ${version} ${completion_min_verion} \ + && with_completion="--with completion" || : + +rpmbuild -bb SPECS/"${spec_name}" --define "%_topdir `pwd`" \ + ${with_completion}