summary refs log tree commit diff
path: root/noarch/package_api_defaults
blob: b535ee33fcf24e1d8330e929e17de0fa2ac46291 (plain) (blame)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#
# This file contains 'package' API defaults.
#
# NOTE: Tthis file must "sourced" (not executed).
#
# WARNING: This file depends on functions from "run_time_utils" file.
#

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#
# Old API
#
# mandatory
#
# Use something like:
#	echo "package's human readable name"
#
human_readable_name() {
	_abort_execution "'human_readable_name()' is mandatory and must be redefined in each 'package'"
}

#
# Old API
#
# mandatory
#
# Use something like:
#	echo "package_name"
#
package_name() {
	_abort_execution "'package_name()' is mandatory and must be redefined in each 'package'"
}

#
# Old API
#
# optional
#
# Acts as flag to differentiate "common" ("binaries") and "vendor-specific"
# ("script") packages. Shall be empty for "common" packages (will be installed
# into "${INSTALL_BASE_DIR}/smfp-common/" directory). Shall be non-empty for
# "vendor-specific" packages (will be installed into
# "${INSTALL_BASE_DIR}/${VENDOR}/" directory).
#
# Use something like:
#	echo "-package_suffix"
#
package_suffix(){
	#echo ""
	return
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#
# Existing packages don't fit into new API. For compatibility reasons there are
# two "init" functions "package_on_load()" and "package_init()".
#
# "package_on_load()" - new API. References to environment variables are not
# permitted. All communication to "external world" must be performed via API
# functions only.
#
# "package_init()" - old API. Various environment variables like "INSTALL_DIR",
# "VENDOR_LC", "DIST_DIR" are already made available.
#

#
# New API
#
# It is expected that 'package manager' shall invoke this function prior to any
# other API function. Thus any package shall redefine this function to perform
# it's initialization here.
#
# optional
#
# Default implementation provides new API based on old API.
#
# Note: "INSTALL_BASE_DIR" and "VENDOR_LC" are initialized in
# "environment_init()" at the very beginning.
#
package_on_load() {
	log_message ""

	# define "PACKAGE_NAME" and "PACKAGE_SUFFIX"
	PACKAGE_NAME=$(package_name)
	log_variable PACKAGE_NAME
	PACKAGE_SUFFIX=$(package_suffix)
	log_variable PACKAGE_SUFFIX

	# define "INSTALL_DIR" for "install_dir()"
	INSTALL_DIR=$(_install_dir "${PACKAGE_NAME}" "${PACKAGE_SUFFIX}")
	log_variable INSTALL_DIR

	# define "VERSION" for "version()"
	# _version_file( PACKAGE_NAME, PACKAGE_SUFFIX ) // ${INSTALL_BASE_DIR}, ${VENDOR_LC}
	VERSION_FILE=$(_version_file "${PACKAGE_NAME}" "${PACKAGE_SUFFIX}")
	log_variable VERSION_FILE
	VERSION=$(_load_version_from_file "${VERSION_FILE}")
	log_variable VERSION

	# define "DIST_VERSION" for "dist_version()"
	# _dist_version_file( PACKAGE_NAME, PACKAGE_SUFFIX ) // ${DIST_DIR}
	DIST_VERSION_FILE=$(_dist_version_file "${PACKAGE_NAME}" "${PACKAGE_SUFFIX}")
	log_variable DIST_VERSION_FILE
	DIST_VERSION=$(_load_version_from_file "${DIST_VERSION_FILE}")
	log_variable DIST_VERSION

	return
}

#
# Old API
#
package_init() {
	log_message ""
	return
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#
# optional
#
# Default implementation provides new API based on old API (see
# "package_on_load()" default implementation). New packages must provide
# alternative implementation.
#
# Depends on "package_on_load()"
#
install_dir() {
	if [ -z "${INSTALL_DIR}" ] ; then _abort_execution "'INSTALL_DIR' is undefined" ; fi
	echo "${INSTALL_DIR}"
}

#
# optional
#
# Depends on "package_on_load()"
#
version() {
	if [ -z "${VERSION}" ] ; then _abort_execution "'VERSION' is undefined" ; fi
	echo "${VERSION}"
}

#
# optional
#
# Depends on "package_on_load()"
#
dist_version() {
	if [ -z "${DIST_VERSION}" ] ; then _abort_execution "'DIST_VERSION' is undefined" ; fi
	echo "${DIST_VERSION}"
}

#
# optional
#
# @return:
#	"true" - if new version is greater than the old one or FORCE_INSTALL=1
#	"false" - if new version is less than or equal to the old one
#
isInstallNecessary() {
	log_message ""

	log_variable FORCE_INSTALL
	if [ -n "${FORCE_INSTALL}" ] ; then
		echo "true"
		return
	fi

	local VERSION=$(version)
	log_variable VERSION
	if [ -z "${VERSION}" ] ; then _abort_execution "'version()' erroneously returns empty version" ; fi

	local DIST_VERSION=$(dist_version)
	log_variable DIST_VERSION
	if [ -z "${DIST_VERSION}" ] ; then _abort_execution "'dist_version()' erroneously returns empty version"; fi

	# Put '1' digit at the beginning to avoid implicit
	# octal interpretation of numbers starting with 0
	local VERSION_DIGITS=1$(echo "${VERSION}" | tr -d -c "0-9")
	log_variable VERSION_DIGITS
	local DIST_VERSION_DIGITS=1$(echo "${DIST_VERSION}" | tr -d -c "0-9")
	log_variable DIST_VERSION_DIGITS

	# If current version < dist version, do install
	if [ $VERSION_DIGITS -lt $DIST_VERSION_DIGITS ] ; then
		echo "true"
	else
		echo "false"
	fi
}

report_no_install_reason() {
	log_message ""
	return
}

#
# ? optional
#
dependencies() {
	log_message ""
	return
}

#
# ? optional
#
get_missing_requirements() {
	log_message ""
	return
}

#
# ? optional
#
report_missing_requirements() {
	if [ "$UNINSTALLMODE" ] ; then
		return
	fi

	local MISSING_COMPONENT="$1"
	if [ -n "${MISSING_COMPONENT}" ] ; then
		show_nls_message "**** component '\${MISSING_COMPONENT}' is missing"
		exit 1
	fi
}

#
# optional
#
do_install() {
	log_message "installing '$(package_name)' package"
	return
}

#
# optional
#
do_uninstall() {
	log_message "uninstalling '$(package_name)' package"
	return
}

# report end of install
after_install() {
	log_message ""
	return
}

# report end of uninstall
after_uninstall() {
	log_message ""
	return
}


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

log_message "EOF"