summaryrefslogtreecommitdiff
path: root/type
diff options
context:
space:
mode:
authorDennis Camera <dennis.camera@ssrq-sds-fds.ch>2021-03-21 18:23:13 +0100
committerDennis Camera <dennis.camera@ssrq-sds-fds.ch>2021-03-21 18:23:13 +0100
commita7385a53faa2411eb9d3c850eabd32f3eadff167 (patch)
tree425eebd96dc5fb10e7cca10fa47c9cceb0eac5a5 /type
parent6e342aae9e6988e790e955c665be4245b895bb4e (diff)
download__dtnrch_egov-a7385a53faa2411eb9d3c850eabd32f3eadff167.tar.gz
__dtnrch_egov-a7385a53faa2411eb9d3c850eabd32f3eadff167.zip
[type/__dtnrch_install4j] Add support for Mac OS X
Diffstat (limited to 'type')
-rw-r--r--type/__dtnrch_install4j/files/find_uninstaller.awk58
-rwxr-xr-xtype/__dtnrch_install4j/gencode-remote99
2 files changed, 147 insertions, 10 deletions
diff --git a/type/__dtnrch_install4j/files/find_uninstaller.awk b/type/__dtnrch_install4j/files/find_uninstaller.awk
new file mode 100644
index 0000000..374c81a
--- /dev/null
+++ b/type/__dtnrch_install4j/files/find_uninstaller.awk
@@ -0,0 +1,58 @@
+#!/usr/bin/awk -f
+# Usage: awk -f find_uninstaller.awk ${install_dir}/.install4j/i4jparams.conf
+
+function post(uninst, inst_dir) {
+ inst_dir = FILENAME
+ sub(FILESMATCH, "", inst_dir)
+
+ if (!system("cd '" inst_dir "' && test -e '" uninst "'")) {
+ if (uninst !~ /^\//)
+ printf "%s/%s\n", inst_dir, uninst
+ else
+ print uninst
+ }
+}
+
+BEGIN {
+ FILESMATCH = "(^|/).install4j/i4jparams\.conf$"
+
+ "uname -s" | getline kernel_name
+ close("uname -s")
+}
+
+/\r$/ { sub(/\r$/, "") }
+
+FNR == 1 {
+ if (!/^<\?xml version="1\.0".*\?>$/)
+ exit (e=1)
+
+ if (FILENAME !~ FILESMATCH)
+ exit (e=2)
+}
+
+/^<config.*>$/ {
+ in_config = 1
+ next
+}
+
+/^<\/config>$/ {
+ in_config = 0
+ post(UNINST)
+ next
+}
+
+in_config && /^[ ]*<general.*\/>$/ {
+ if (match($0, /uninstallerDirectory="[^"]*"/)) {
+ prefix_len = length("uninstallerDirectory=\"")
+ uninst_dir = substr($0, RSTART + prefix_len, RLENGTH - prefix_len - 1)
+ }
+ if (match($0, /uninstallerFilename="[^"]*"/)) {
+ prefix_len = length("uninstallerFilename=\"")
+ uninst_name = substr($0, RSTART + prefix_len, RLENGTH - prefix_len - 1)
+ }
+
+ UNINST = sprintf("%s/%s", (uninst_dir ? uninst_dir : "."), uninst_name)
+ uninst_dir = uninst_name = ""
+ if (kernel_name == "Darwin" && UNINST !~ /\/$/)
+ UNINST = UNINST ".app/Contents/MacOS/JavaApplicationStub"
+}
diff --git a/type/__dtnrch_install4j/gencode-remote b/type/__dtnrch_install4j/gencode-remote
index 46bc6bd..363c6f2 100755
--- a/type/__dtnrch_install4j/gencode-remote
+++ b/type/__dtnrch_install4j/gencode-remote
@@ -18,12 +18,15 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
-quote() { printf "'%s'" "$(echo "$*" | sed -e "s/'/'\\\\''/g")"; }
+quote() { printf "'%s'" "$(printf '%s\n' "$*" | sed -e "s/'/'\\\\''/g")"; }
+drop_awk_comments() { quote "$(sed '/^[[:blank:]]*#.*$/d;/^$/d' "$@")"; }
target_setenv() {
printf '%s=%s\nexport %s\n' "$1" "$(quote "$2")" "$1"
}
+os=$(cat "${__global:?}/explorer/os")
+
state_is=$(cat "${__object:?}/explorer/state")
state_should=$(cat "${__object:?}/parameter/state")
@@ -43,6 +46,8 @@ i4j_opts='-q'
case ${state_should}
in
(present)
+ printf 'set -e\n'
+
if test -s "${__object:?}/parameter/java-home"
then
java_home=$(cat "${__object:?}/parameter/java-home")
@@ -52,7 +57,7 @@ in
i4j_opts="${i4j_opts} -manual $(quote "${java_home}")"
fi
- i4j_script=$(cat "${__object:?}/parameter/installer")
+ i4j_installer=$(cat "${__object:?}/parameter/installer")
i4j_vm_opts='-Dinstall4j.suppressUnattendedReboot=true'
i4j_opts="${i4j_opts} -dir '${destination}'"
@@ -70,21 +75,82 @@ in
i4j_opts="${i4j_opts} -overwrite"
fi
- printf "/bin/sh '%s' %s %s\\n" "${i4j_script}" "${i4j_opts}" "${i4j_vm_opts}"
- printf "cksum '%s' | cut -d ' ' -f 1,2 >'%s'\\n" "${i4j_script}" "${destination}/.install4j/inst_cksum"
+ # Prepare installer
+ if expr "${i4j_installer}" : '.*\.sh$' >/dev/null
+ then
+ cat <<-EOF
+ pre() {
+ installer_exe=$(quote "${i4j_installer}")
+ }
+ run() {
+ /bin/sh "\${installer_exe}" ${i4j_opts} ${i4j_vm_opts}
+ }
+ post() { :; }
+
+ EOF
+ elif test "${os}" = 'macosx' && expr "${i4j_installer}" : '.*\.dmg$' >/dev/null
+ then
+ cat <<-EOF
+ pre() {
+ # Mount DMG first
+ dmg_path=$(quote "${i4j_installer}")
+ mountpoint_tmp=\$(mktemp)
+ hdiutil attach "\${dmg_path}" >"\${mountpoint_tmp}" || hdirc=$?
+ cat "\${mountpoint_tmp}"
+ dmg_mountpoint=\$(sed -n -e '\$s#^/dev/[^ ]*[[:space:]]*\(/Volumes/.*\)\$#\1#p' "\${mountpoint_tmp}")
+ rm "\${mountpoint_tmp}"
+ if test -n "\${hdirc-}"; then exit \$((hdirc)); fi
+
+ # Find installer
+ test -d "\${dmg_mountpoint}" || {
+ printf 'Failed to mount DMG %s\n' "\${dmg_path}" >&2
+ exit 1
+ }
+
+ installer_bundle=\$(
+ find "\${dmg_mountpoint}" -type d -name '*.app' -exec grep -q -F com.install4j.runtime {}/Contents/Info.plist \; -print |
+ awk '1;NR>1{e="Found more than one potential installer"} END{if(e){print e|"cat >&2";exit 1}}'
+ )
+ }
+ run() {
+ test -d "\${installer_bundle}" || {
+ printf 'Cannot find installer: %s\n' "\${installer_bundle}" >&2
+ exit 1
+ }
+ "\${installer_bundle}"/Contents/MacOS/JavaApplicationStub ${i4j_opts} ${i4j_vm_opts}
+ }
+ post() {
+ if test -d "\${dmg_mountpoint}"
+ then
+ hdiutil detach "\${dmg_mountpoint}"
+ fi
+ }
+
+ EOF
+ else
+ printf 'Unsupported install4j installer format: %s\n' "${i4j_installer}" >&2
+ exit 1
+ fi
+
+ # Run installer
+ printf 'trap post EXIT\n'
+ echo pre
+ echo run
+ printf "cksum '%s' | cut -d ' ' -f 1,2 >%s\\n" \
+ "${i4j_installer}" "$(quote "${destination}/.install4j/inst_cksum")"
echo 'installed' >>"${__messages_out:?}"
;;
(absent)
remote_logs_dir='${__object:?}/logs'
cat <<-EOF
- if test -f '${destination}/.install4j/inst_jre.cfg'
+ if test -f $(quote "${destination}/.install4j/inst_jre.cfg")
then
- read INSTALL4J_JAVA_HOME_OVERRIDE <'${destination}/.install4j/inst_jre.cfg'
+ read INSTALL4J_JAVA_HOME_OVERRIDE <$(quote "${destination}/.install4j/inst_jre.cfg")
test -d "\${INSTALL4J_JAVA_HOME_OVERRIDE}" || {
- if test -f '${destination}/.install4j/pref_jre.cfg'
+ if test -f $(quote "${destination}/.install4j/pref_jre.cfg")
then
- read INSTALL4J_JAVA_HOME_OVERRIDE <'${destination}/.install4j/pref_jre.cfg'
+ read INSTALL4J_JAVA_HOME_OVERRIDE <$(quote "${destination}/.install4j/pref_jre.cfg")
fi
}
if test -d "\${INSTALL4J_JAVA_HOME_OVERRIDE}"
@@ -95,12 +161,25 @@ in
fi
fi
+ if test -x $(quote "${destination}/.install4j/uninstall")
+ then
+ uninstaller=$(quote "${destination}/.install4j/uninstall")
+ elif test -f $(quote "${destination}/.install4j/i4jparams.conf")
+ then
+ uninstaller=\$(
+ awk $(drop_awk_comments "${__type:?}/files/find_uninstaller.awk") $(quote "${destination}/.install4j/i4jparams.conf"))
+ test -x "\${uninstaller}" || {
+ echo 'Cannot find uninstaller.' >&2
+ exit 1
+ }
+ fi
+
mkdir "${remote_logs_dir}" || exit 1
- rm -f '${destination}/.install4j/inst_cksum'
+ rm -f $(quote "${destination}/.install4j/inst_cksum")
i4j_exit=0
- /bin/sh '${destination}/uninstall' ${i4j_opts} >"${remote_logs_dir}/i4j_stdout" 2>"${remote_logs_dir}/i4j_stderr" || i4j_exit=$?
+ "\${uninstaller}" ${i4j_opts} >"${remote_logs_dir}/i4j_stdout" 2>"${remote_logs_dir}/i4j_stderr" || i4j_exit=$?
cat <"${remote_logs_dir}/i4j_stdout"
cat >&2 <"${remote_logs_dir}/i4j_stderr"