@@ -38,145 +38,147 @@ func_usage()
38
38
echo " -h(help) print help."
39
39
echo " "
40
40
}
41
- PRGNAME=` basename $0 `
42
- MYSCRIPTDIR=` dirname $0 `
43
- SRCTOP=` cd ${MYSCRIPTDIR} /..; pwd`
41
+
42
+ PRGNAME=$( basename " $0 " )
43
+ MYSCRIPTDIR=$( dirname " $0 " )
44
+ SRCTOP=$( cd " ${MYSCRIPTDIR} /.." || exit 1; pwd)
44
45
RELEASE_VERSION_FILE=" ${SRCTOP} /RELEASE_VERSION"
45
46
46
47
#
47
48
# Check options
48
49
#
49
50
PRGMODE=" "
50
51
while [ $# -ne 0 ]; do
51
- if [ " X $1 " = " X " ]; then
52
+ if [ -z " $1 " ]; then
52
53
break ;
53
54
54
- elif [ " X $1 " = " X -h" -o " X $1 " = " X -help" ]; then
55
- func_usage $ PRGNAME
55
+ elif [ " $1 " = " -h" ] || [ " $1 " = " -help" ]; then
56
+ func_usage " ${ PRGNAME} "
56
57
exit 0
57
58
58
- elif [ " X $1 " = " X -pkg_version" ]; then
59
+ elif [ " $1 " = " -pkg_version" ]; then
59
60
PRGMODE=" PKG"
60
61
61
- elif [ " X $1 " = " X -lib_version_info" ]; then
62
+ elif [ " $1 " = " -lib_version_info" ]; then
62
63
PRGMODE=" LIB"
63
64
64
- elif [ " X $1 " = " X -lib_version_for_link" ]; then
65
+ elif [ " $1 " = " -lib_version_for_link" ]; then
65
66
PRGMODE=" LINK"
66
67
67
- elif [ " X $1 " = " X -major_number" ]; then
68
+ elif [ " $1 " = " -major_number" ]; then
68
69
PRGMODE=" MAJOR"
69
70
70
- elif [ " X $1 " = " X -debhelper_dep" ]; then
71
+ elif [ " $1 " = " -debhelper_dep" ]; then
71
72
PRGMODE=" DEBHELPER"
72
73
73
- elif [ " X $1 " = " X -rpmpkg_group" ]; then
74
+ elif [ " $1 " = " -rpmpkg_group" ]; then
74
75
PRGMODE=" RPMGROUP"
75
76
76
77
else
77
78
echo " ERROR: unknown option $1 " 1>&2
78
- echo -n " 0 "
79
+ printf ' 0 '
79
80
exit 1
80
81
fi
81
82
shift
82
83
done
83
- if [ " X ${PRGMODE} " = " X " ]; then
84
+ if [ -z " ${PRGMODE} " ]; then
84
85
echo " ERROR: option is not specified." 1>&2
85
- echo -n " 0 "
86
+ printf ' 0 '
86
87
exit 1
87
88
fi
88
89
89
90
#
90
91
# Make result
91
92
#
92
- if [ ${PRGMODE} = " PKG" ]; then
93
- RESULT=` cat ${RELEASE_VERSION_FILE} `
93
+ if [ " ${PRGMODE} " = " PKG" ]; then
94
+ RESULT=$( cat " ${RELEASE_VERSION_FILE} " )
94
95
95
- elif [ ${PRGMODE} = " LIB" -o ${PRGMODE} = " LINK" ]; then
96
- MAJOR_VERSION=` cat ${RELEASE_VERSION_FILE} | sed ' s/["|\.]/ /g' | awk ' {print $1}' `
97
- MID_VERSION=` cat ${RELEASE_VERSION_FILE} | sed ' s/["|\.]/ /g' | awk ' {print $2}' `
98
- LAST_VERSION=` cat ${RELEASE_VERSION_FILE} | sed ' s/["|\.]/ /g' | awk ' {print $3}' `
96
+ elif [ " ${PRGMODE} " = " LIB" ] || [ " ${PRGMODE} " = " LINK" ]; then
97
+ MAJOR_VERSION=$( sed -e ' s/["|\.]/ /g' " ${RELEASE_VERSION_FILE} " | awk ' {print $1}' )
98
+ MID_VERSION=$( sed -e ' s/["|\.]/ /g' " ${RELEASE_VERSION_FILE} " | awk ' {print $2}' )
99
+ LAST_VERSION=$( sed -e ' s/["|\.]/ /g' " ${RELEASE_VERSION_FILE} " | awk ' {print $3}' )
99
100
100
101
# check version number
102
+ # shellcheck disable=SC2003
101
103
expr " ${MAJOR_VERSION} " + 1 > /dev/null 2>&1
102
104
if [ $? -ge 2 ]; then
103
105
echo " ERROR: wrong version number in RELEASE_VERSION file" 1>&2
104
- echo -n " 0 "
106
+ printf ' 0 '
105
107
exit 1
106
108
fi
109
+ # shellcheck disable=SC2003
107
110
expr " ${MID_VERSION} " + 1 > /dev/null 2>&1
108
111
if [ $? -ge 2 ]; then
109
112
echo " ERROR: wrong version number in RELEASE_VERSION file" 1>&2
110
- echo -n " 0 "
113
+ printf ' 0 '
111
114
exit 1
112
115
fi
116
+ # shellcheck disable=SC2003
113
117
expr " ${LAST_VERSION} " + 1 > /dev/null 2>&1
114
118
if [ $? -ge 2 ]; then
115
119
echo " ERROR: wrong version number in RELEASE_VERSION file" 1>&2
116
- echo -n " 0 "
120
+ printf ' 0 '
117
121
exit 1
118
122
fi
119
123
120
124
# make library revision number
121
- if [ ${MID_VERSION} -gt 0 ]; then
122
- REV_VERSION=` expr ${MID_VERSION} \* 100`
123
- REV_VERSION=` expr ${LAST_VERSION} + ${REV_VERSION} `
125
+ if [ " ${MID_VERSION} " -gt 0 ]; then
126
+ REV_VERSION=$(( MID_VERSION * 100 ))
127
+ REV_VERSION=$(( MID_VERSION * 100 ))
128
+ REV_VERSION=$(( LAST_VERSION + REV_VERSION))
124
129
else
125
- REV_VERSION=${LAST_VERSION}
130
+ REV_VERSION=" ${LAST_VERSION} "
126
131
fi
127
132
128
- if [ ${PRGMODE} = " LIB" ]; then
133
+ if [ " ${PRGMODE} " = " LIB" ]; then
129
134
RESULT=" ${MAJOR_VERSION} :${REV_VERSION} :0"
130
135
else
131
136
RESULT=" ${MAJOR_VERSION} .0.${REV_VERSION} "
132
137
fi
133
138
134
- elif [ ${PRGMODE} = " MAJOR" ]; then
135
- RESULT=` cat ${RELEASE_VERSION_FILE} | sed ' s/["|\.]/ /g' | awk ' {print $1}' `
139
+ elif [ " ${PRGMODE} " = " MAJOR" ]; then
140
+ RESULT=$( sed ' s/["|\.]/ /g' " ${RELEASE_VERSION_FILE} " | awk ' {print $1}' )
136
141
137
- elif [ ${PRGMODE} = " DEBHELPER" ]; then
142
+ elif [ " ${PRGMODE} " = " DEBHELPER" ]; then
138
143
# [NOTE]
139
144
# This option returns debhelper dependency string in control file for debian package.
140
145
# That string is depended debhelper package version and os etc.
141
146
# (if not ubuntu/debian os, returns default string)
142
147
#
143
- apt-cache --version > /dev/null 2>&1
144
- if [ $? -eq 0 ]; then
145
- IS_OS_UBUNTU=0
146
- if [ -f /etc/lsb-release ]; then
147
- grep [Uu]buntu /etc/lsb-release > /dev/null 2>&1
148
- if [ $? -eq 0 ]; then
149
- IS_OS_UBUNTU=1
150
- fi
151
- fi
148
+ OS_ID_STRING=$( grep ' ^ID[[:space:]]*=[[:space:]]*' /etc/os-release | sed -e ' s|^ID[[:space:]]*=[[:space:]]*||g' -e ' s|^[[:space:]]*||g' -e ' s|[[:space:]]*$||g' )
152
149
153
- DEBHELPER_MAJOR_VER=` apt-cache show debhelper 2> /dev/null | grep Version 2> /dev/null | awk ' {print $2}' 2> /dev/null | sed ' s/\..*/ /g' 2> /dev/null`
154
- expr " ${DEBHELPER_MAJOR_VER} " + 1 > /dev/null 2>&1
155
- if [ $? -ne 0 ]; then
156
- DEBHELPER_MAJOR_VER=0
157
- else
158
- DEBHELPER_MAJOR_VER=` expr " ${DEBHELPER_MAJOR_VER} " + 0`
159
- fi
160
- if [ ${DEBHELPER_MAJOR_VER} -lt 10 ]; then
161
- RESULT=" debhelper (>= 9), autotools-dev"
162
- else
163
- if [ ${IS_OS_UBUNTU} -eq 1 ]; then
164
- RESULT=" debhelper (>= 10)"
150
+ DEBHELPER_MAJOR_VER=$( apt-cache show debhelper 2> /dev/null | grep Version 2> /dev/null | awk ' {print $2}' 2> /dev/null | sed ' s/\..*/ /g' 2> /dev/null)
151
+ # shellcheck disable=SC2003
152
+ expr " ${DEBHELPER_MAJOR_VER} " + 1 > /dev/null 2>&1
153
+ if [ $? -ne 0 ]; then
154
+ DEBHELPER_MAJOR_VER=0
155
+ fi
156
+
157
+ if [ -n " ${OS_ID_STRING} " ]; then
158
+ if [ " ${OS_ID_STRING} " = " debian" ]; then
159
+ RESULT=" debhelper (>= 9.20160709) | dh-systemd, autotools-dev"
160
+
161
+ elif [ " ${OS_ID_STRING} " = " ubuntu" ]; then
162
+ if [ ${DEBHELPER_MAJOR_VER} -lt 10 ]; then
163
+ RESULT=" debhelper (>= 9.20160709) | dh-systemd, autotools-dev"
165
164
else
166
- RESULT=" debhelper (>= 10), autotools-dev "
165
+ RESULT=" debhelper (>= 9.20160709) | dh-systemd "
167
166
fi
167
+ else
168
+ # Not debian/ubuntu, set default
169
+ RESULT=" debhelper (>= 9.20160709) | dh-systemd, autotools-dev"
168
170
fi
169
171
else
170
- # Not debian/ubuntu , set default
171
- RESULT=" debhelper (>= 10) , autotools-dev"
172
+ # Unknown OS , set default
173
+ RESULT=" debhelper (>= 9.20160709) | dh-systemd , autotools-dev"
172
174
fi
173
175
174
- elif [ ${PRGMODE} = " RPMGROUP" ]; then
176
+ elif [ " ${PRGMODE} " = " RPMGROUP" ]; then
175
177
# [NOTE]
176
178
# Fedora rpm does not need "Group" key in spec file.
177
179
# If not fedora, returns "NEEDRPMGROUP", and you must replace this string in configure.ac
178
180
#
179
- if [ -f /etc/fedora -release ] ; then
181
+ if grep -q ' ^ID[[:space:]]*=[[:space:]]*["]*fedora["]*[[:space:]]*$ ' /etc/os -release; then
180
182
RESULT=" "
181
183
else
182
184
RESULT=" NEEDRPMGROUP"
186
188
#
187
189
# Output result
188
190
#
189
- echo -n $ RESULT
191
+ printf ' %s ' " ${ RESULT} "
190
192
191
193
exit 0
192
194
193
195
#
194
- # VIM modelines
195
- #
196
- # vim:set ts=4 fenc=utf-8:
196
+ # Local variables:
197
+ # tab-width: 4
198
+ # c-basic-offset: 4
199
+ # End:
200
+ # vim600: noexpandtab sw=4 ts=4 fdm=marker
201
+ # vim<600: noexpandtab sw=4 ts=4
197
202
#
0 commit comments