#!/bin/sh
# GENERATED by packaging/gen-variant-scripts.sh — DO NOT EDIT THIS FILE.
#   regenerate: sh packaging/gen-variant-scripts.sh          check: … --check
#
# Jihad Browser — Enyo 1.0 variant (net.riverstonerelay.jihad-browser) — post-install.
# Runs as ROOT under Preware / WebOS Quick Install (palm-install does not run control scripts).
#
# The run-in-place-from-cryptofs install model below — leaving the engine in the app's own
# deviceroot instead of copying it to /media/internal, and doing every rootfs write in a single
# remount-rw window — is adapted from the Atlas browser's
# atlas-browser-app/packaging/ipk-postinst.sh (Apache-2.0, Herman van Hazendonk / Herrie82).
#
# ── INSTALL FOOTPRINT (cavekit-device-build.md R8; enumerated in packaging/README.md) ─────────
# Everything this script creates outside the app's own directory, and nothing else:
#   /usr/lib/BrowserPlugins/BrowserAdapterJihad.so
#         the NPAPI shim. Unavoidable rootfs write: webOS WebKit builds its plugin/MIME database
#         by scanning /usr/lib/BrowserPlugins at BOOT, and that is the only path it loads a
#         plugin from (Atlas hit the same wall and found no way around it). Bounded + reversed
#         instead of pretended away.
#   /usr/lib/jihad/  and  /usr/lib/jihad/enyo/
#         root-owned 0755 directories holding the adapter impl. Mode-pinned EXPLICITLY (F-8):
#         `mkdir -p` applies the INHERITED umask, and the installer has been observed running
#         with `umask 0`, which would leave both 0777 — enough for any local uid to unlink the
#         impl or hardlink-swap it, and the shim validates the impl FILE, never the directory it
#         was loaded out of.
#   /usr/lib/jihad/enyo/BrowserAdapterImpl.so
#         the adapter implementation. It lives on the ROOTFS, not in the app bundle, because the
#         shim dlopens it into privileged LunaSysMgr and fails closed unless the file is
#         root-owned and not group/world-writable (review F-161/F-180) — and cryptofs reports
#         EVERY file as 777, so an app-bundle impl could never pass that check.
#   /etc/event.d/jihad
#         this variant's own upstart job, root-owned 0644. The stock `browserserver` job is
#         never touched. 0644 and not 0755 deliberately: upstart READS a job file, it never
#         execs it, so the execute bit buys nothing and costs a root-run-file's worth of risk.
#   /var/palm/jihad/  and  /var/palm/jihad/enyo/
#         root-owned 0755 runtime state: the daemon log and the debug channels, and NOTHING
#         else. Kilobytes of operational state for a root daemon, correctly on ext3. The engine
#         profile and cache deliberately do NOT live here — /var has 49.6 MB free and is shared
#         with system state (see $APP/profile and $APP/cache below). Root-owned and NOT
#         world-writable: it is read by root-privileged code, and /media/internal
#         (world-writable vfat) is exactly the location the shim's trust check exists to
#         distrust.
#
# EVERY ONE OF THOSE IS `chown 0:0`'d (F-7). They are copied out of the app bundle with `cp -a`,
# and `-a` PRESERVES the source's ownership — from /media/cryptofs, an untrusted 0777 filesystem
# whose reported uid is not ours to trust. The impl was already chown'd because the shim refuses
# to dlopen anything else; the shim itself needs it just as much (LunaSysMgr dlopens the shim as
# root and performs NO trust check of its own) and so does the upstart job (init execs it as
# root).
#
# Created at RUNTIME by the daemon, inside the app's own directory, and listed here because
# this variant's prerm removes it (ipkg only tracks files IT installed, so an untracked tree
# would survive removal as residue and break R8's exact-reversal criterion):
#   $APP/profile/   the engine's DURABLE profile (Gecko's ProfD): cookies.sqlite, prefs.js,
#                   permissions, cert overrides.
#   $APP/cache/     the engine's DISPOSABLE local profile (Gecko's ProfLD): cache2 +
#                   startupCache, capped at 50 MB by browser.cache.disk.capacity.
#         Both on cryptofs, not in /var/palm/jihad/enyo/: measured 2026-08-01, /var has 49.6 MB
#         free and is shared with system state, while cryptofs has 10.2 GB. This is also where
#         BOTH prior implementations of this browser on this device put them — isis
#         (CookieJarPath/CachePath under /media/cryptofs/.browser) and Atlas (netdata/netcache/
#         cookies.db in its app deviceroot), the latter because /media/internal is VFAT and
#         gives SQLite no real file locking.
#
# NOT written, deliberately:
#   * NOTHING under /media/internal. That vfat volume is the user's USB mass-storage partition
#     and must stay free of app internals (user decision 2026-07-31; Atlas's model). The daemon,
#     libxul, the bundled glibc-2.23 and the GRE resources RUN IN PLACE from $APP/deviceroot/hl
#     on cryptofs — measured live 2026-07-31: /media/cryptofs is fuse.cryptofs (rw,nosuid,nodev)
#     and is NOT noexec, and a binary copied into an app dir was proven to execute there.
#   * No stock file is modified, replaced, moved, or backed-up-and-swapped. In particular
#     /usr/lib/BrowserPlugins/BrowserAdapter.so, …/BrowserAdapterMojo.so and
#     /etc/event.d/browserserver keep their stock bytes.
#   * No file owned by another Jihad variant. Every path above carries this variant's token, so
#     installing this package cannot overwrite, downgrade, or invalidate anything the Enyo /
#     Mochi / Mojo siblings own (R7).
#
# Reversed EXACTLY by this variant's prerm.
set -e                              # review #6: a failed deploy must NOT report success

V=enyo
APP=/media/cryptofs/apps/usr/palm/applications/net.riverstonerelay.jihad-browser
DR=$APP/deviceroot
HL=$DR/hl
SHIM=/usr/lib/BrowserPlugins/BrowserAdapterJihad.so
IMPLDIR=/usr/lib/jihad/enyo
IMPL=$IMPLDIR/BrowserAdapterImpl.so
RECTSCHEMA=$IMPLDIR/InteractiveWidgetRect.schema
JOB=/etc/event.d/jihad
STATE=/var/palm/jihad/enyo
log() { echo "jihad-postinst($V): $*"; }

# ── 0. preflight ─────────────────────────────────────────────────────────────────────────────
# Nothing on the system is touched until the whole payload is present, so a truncated download
# or a mis-assembled .ipk fails BEFORE it can half-install (review #6).
[ -f "$HL/jihad-browserserver" ] && [ -f "$HL/ld-2.23.so" ] \
  && [ -f "$DR/BrowserPlugins/BrowserAdapterJihad.so" ] && [ -f "$DR/event.d/jihad" ] \
  && [ -f "$APP/BrowserAdapterImpl.so" ] || {
	echo "jihad-postinst($V): bundle payload missing under $APP — aborting" >&2; exit 1; }

# ── 1. engine + daemon: RUN IN PLACE, copy nothing ───────────────────────────────────────────
# The whole runtime already sits in the app's own deviceroot on cryptofs and stays there. All
# this step does is make the two things the upstart job execs executable. Non-fatal: cryptofs
# reports every file 777 regardless, and step 3 verifies the result for real.
log "preparing the Goanna daemon (in place, on cryptofs — nothing is copied)..."
chmod 755 "$HL/jihad-browserserver" "$HL/ld-2.23.so" 2>/dev/null || true

# ── 2. the rootfs writes: ONE rw window ──────────────────────────────────────────────────────
# `/` is treated as read-only; the window is opened here and closed by the trap on EVERY exit
# path INCLUDING failure (R8), so a crash mid-install can never leave the rootfs writable.
# /var/palm is created in the same window because it may sit on the read-only rootfs.
log "installing shim + impl + upstart job + state dir (rootfs rw)..."
# RESTORE WHAT WE FOUND, don't assume we own the mount state. When the installer (Preware's
# ipkgservice) drives this, `/` is ALREADY read-write for the duration of its own work — so
# unconditionally forcing it back to read-only here either fights the installer mid-install or
# fails outright. Measured 2026-08-05 on a supported install: our own honest warning,
# "could not restore / to read-only", and `/` left mounted rw afterwards, which is exactly the
# R8 violation this window exists to prevent. If it was already rw on entry, leave it to
# whoever made it so; only a window WE opened is a window we must close.
ROOTFS_WAS_RW=no
# The mount that counts is the LAST one on / that is not the initramfs "rootfs" (always rw, listed
# first): `mount | grep "on / .*rw"` matched that one, so a read-only root was taken for read-write
# and nothing was remounted (device 2026-10-12: "chmod: /usr/lib/jihad: Read-only file system").
if awk '$2 == "/" && $1 != "rootfs" { o = $4 } END { exit !(o ~ /^rw(,|$)/) }' /proc/mounts; then
	ROOTFS_WAS_RW=yes
fi
if [ "$ROOTFS_WAS_RW" = no ]; then
	trap 'mount -o remount,ro / 2>/dev/null || true' EXIT
	mount -o remount,rw /
else
	log "/ was already read-write (installer-driven) — leaving the mount state to the caller"
fi
mkdir -p /usr/lib/BrowserPlugins "$IMPLDIR" "$STATE"
# F-8: `mkdir -p` uses the INHERITED umask. The state dir was already mode-pinned; the impl
# directories were not, so under `umask 0` they landed 0777 and any local uid could unlink or
# hardlink-swap the impl the shim is about to dlopen into LunaSysMgr. Pin all four, root-owned
# 0755, NOT world-writable — see the footprint note above.
chown 0:0 /usr/lib/jihad "$IMPLDIR" /var/palm/jihad "$STATE" 2>/dev/null || true
chmod 0755 /usr/lib/jihad "$IMPLDIR" /var/palm/jihad "$STATE"
# ── REPLACE THE ADAPTER BY RENAME, NEVER IN PLACE (2026-10-01) ───────────────────────────────
# On an UPGRADE, LunaSysMgr may still have the previous shim and impl MAPPED: an NPAPI library
# stays loaded after its last card closes. `cp` onto the same path rewrites the bytes of the
# inode that mapping is backed by, so LunaSysMgr's loaded copy turns into a mix of old and new
# pages — and the next plugin load walks its symbol tables. Measured on webOS CE 3.1.0: an
# install-over through the supported installer, then one card launch, and LunaSysMgr died with
# SIGSEGV in ld.so's do_lookup_x under WebCore::PluginPackage::load, taking every card of every
# app with it. Writing the new file beside the old one and renaming it over leaves the old inode
# intact for whoever has it mapped; the new file is what the next LunaSysMgr start loads, which
# is the reboot this script asks for anyway. Ownership and mode are set on the temp name so the
# file is never visible at its real path with the wrong ones.
# An adapter that is byte-identical to the installed one is left alone (2026-10-13): the rename
# leaves the old inode mapped in LunaSysMgr as a deleted file on /, and a deleted file still open
# on / makes `mount -o remount,ro /` fail with EBUSY until LunaSysMgr restarts — measured on the
# device, a reinstall of Mochi left / read-write after all ten tries below. Most installs carry
# the same adapter, so most now replace nothing on / that anything has mapped.
SHIMTMP=/usr/lib/BrowserPlugins/.BrowserAdapterJihad.so.new
IMPLTMP=$IMPLDIR/.BrowserAdapterImpl.so.new
if cmp -s "$DR/BrowserPlugins/BrowserAdapterJihad.so" "$SHIM"; then
	chown 0:0 "$SHIM" 2>/dev/null || true
	chmod 0755 "$SHIM"
else
	cp -a "$DR/BrowserPlugins/BrowserAdapterJihad.so" "$SHIMTMP"
	# F-7: `cp -a` preserves the SOURCE's ownership, and the source is the app bundle on cryptofs —
	# an untrusted 0777 filesystem. LunaSysMgr dlopens this shim as root with no trust check of its
	# own, so it must be root-owned exactly like the impl it loads.
	chown 0:0 "$SHIMTMP" 2>/dev/null || true
	chmod 0755 "$SHIMTMP"
	mv -f "$SHIMTMP" "$SHIM"
fi
if cmp -s "$APP/BrowserAdapterImpl.so" "$IMPL"; then
	chown 0:0 "$IMPL" 2>/dev/null || true
	chmod 0644 "$IMPL"
else
	cp -a "$APP/BrowserAdapterImpl.so" "$IMPLTMP"
	# The shim REJECTS an impl that is not root-owned or is group/world-writable, and `cp -a`
	# preserves the source's cryptofs-reported 777 — so set both explicitly, or the adapter will
	# refuse to load its own implementation.
	chown 0:0 "$IMPLTMP" 2>/dev/null || true
	chmod 0644 "$IMPLTMP"
	mv -f "$IMPLTMP" "$IMPL"
fi
# The interactive-widget-rect JSON schema, NEXT TO the impl because the impl finds it with
# dladdr on itself (jihadAppFile in BrowserAdapter.cpp). The adapter validates every
# msgAddFlashRects payload against this file and DROPS the whole message if it cannot be
# read, so a missing schema turns plugin input arbitration off with no error anywhere.
# Stock webOS 3.0.5 ships only HitTest.schema in /etc/palm/browser — this one is simply not
# on the device — and /etc is the read-only system rootfs, outside this variant's footprint
# (R8). Hence a private copy here, which the prerm removes with everything else.
if [ -f "$APP/conf/InteractiveWidgetRect.schema" ]; then
  cp -a "$APP/conf/InteractiveWidgetRect.schema" "$RECTSCHEMA"
  chown 0:0 "$RECTSCHEMA" 2>/dev/null || true
  chmod 0644 "$RECTSCHEMA"
fi
# ── this variant's OWN Luna service name (cavekit-ipc-contract.md R4) ────────────────────────
# The app clears cache/cookies over the Luna bus. Upstream calls `palm://com.palm.browserServer/`,
# which is the STOCK daemon — on a device with Jihad installed that call succeeds and clears the
# WRONG browser (measured 2026-08-04). Each variant therefore owns its own service name, the same
# coexistence move already made for the NPAPI MIME, the YAP name, the upstart job and the state
# dir. Registering a name needs the hub's permission, which is what these four files grant.
#
# `exeName` is the path the hub resolves for our process, and that is the BUNDLED LOADER, not the
# daemon binary: the job execs `./ld-2.23.so … ./jihad-browserserver`, so /proc/<pid>/exe is
# ld-2.23.so. Naming jihad-browserserver here would look right and fail.
# A Luna service name CANNOT contain a hyphen — LS2 rejects it at the caller
# (`_UriParse: Not a valid service name`) and LSRegister fails with -1027. Our YAP names all
# have hyphens, so the Luna name is the camel-cased form, matching the platform's own idiom
# (com.palm.browserServer, com.palm.applicationManager). Kept as an explicit table rather than
# a sed transform: three variants, and busybox sed has no \U.
case "enyo" in
	enyo)  LSNAME=net.riverstonerelay.jihadBrowser ;;
	mochi) LSNAME=net.riverstonerelay.jihadBrowserMochi ;;
	mojo)  LSNAME=net.riverstonerelay.jihadBrowserMojo ;;
	*)     LSNAME=net.riverstonerelay.jihadBrowser ;;
esac
LSEXE=$DR/hl/ld-2.23.so
mkdir -p /usr/share/ls2/roles/prv /usr/share/ls2/roles/pub \
         /usr/share/dbus-1/system-services /usr/share/dbus-1/services
# COMPACT, single-line JSON — deliberately, for two reasons. This generator rejects a bare `}`
# at column 0 (it would close an OE function body early), and the obvious workaround, indenting
# the JSON, puts a leading SPACE before the opening brace of a file that ls-hubd parses with its
# own C parser. ls-hubd is load-bearing for boot: if it rejects a role file it can take the whole
# UI down with it. One line has no column-0 brace and no leading whitespace, so neither parser
# has anything to object to.
printf '%s' "{\"role\":{\"exeName\":\"$LSEXE\",\"type\":\"regular\",\"allowedNames\":[\"$LSNAME\",\"com.palm.flashgraphics\",\"\"]},\"permissions\":[{\"service\":\"$LSNAME\",\"inbound\":[\"*\"],\"outbound\":[\"*\"]},{\"service\":\"com.palm.flashgraphics\",\"inbound\":[\"*\"],\"outbound\":[\"*\"]}]}" \
  > /usr/share/ls2/roles/prv/$LSNAME.json
cp -a /usr/share/ls2/roles/prv/$LSNAME.json /usr/share/ls2/roles/pub/$LSNAME.json
# Type=static: upstart already runs the daemon, so the bus must never try to spawn it.
cat > /usr/share/dbus-1/system-services/$LSNAME.service <<LSSVC
[D-BUS Service]
Name=$LSNAME
Exec=$LSEXE
Type=static
LSSVC
cp -a /usr/share/dbus-1/system-services/$LSNAME.service /usr/share/dbus-1/services/$LSNAME.service
chown 0:0 /usr/share/ls2/roles/prv/$LSNAME.json /usr/share/ls2/roles/pub/$LSNAME.json \
          /usr/share/dbus-1/system-services/$LSNAME.service \
          /usr/share/dbus-1/services/$LSNAME.service 2>/dev/null || true
chmod 0644 /usr/share/ls2/roles/prv/$LSNAME.json /usr/share/ls2/roles/pub/$LSNAME.json \
           /usr/share/dbus-1/system-services/$LSNAME.service \
           /usr/share/dbus-1/services/$LSNAME.service
# ls-hubd reads roles at startup OR on a rescan — not the moment these files land. So tell it
# now, before the daemon is started further down: `ls-control scan-services` is nothing but
# `kill -HUP $(pidof ls-hubd)`, and the hub re-reads its whole config including roles (verified
# 2026-08-07 and again on webOS CE 3.1.0 2026-09-27; the bus stays healthy across it).
#
# Until 2026-10-01 this script only DESCRIBED that and left the role to "the reboot this postinst
# already asks for". The daemon it starts a few lines later therefore asked a hub that had never
# seen its role for the name, got -1027, and — registration being attempted exactly once — ran
# with no Luna service until the next restart: Clear Cache / Clear Cookies from the card, and
# every toast, silently dead on a first install (seen on CE 3.1.0, 2026-09-27; an UPGRADE never
# showed it because the hub already knew the role). The daemon also retries the registration
# now (JihadLunaService.cpp), so a failed rescan here is a delay, not a dead service.
if [ -x /usr/bin/ls-control ] && /usr/bin/ls-control scan-services >/dev/null 2>&1; then
	log "ls-hubd rescanned: role for $LSNAME is live"
else
	log "WARNING: could not rescan ls-hubd — $LSNAME registers when the daemon's retry succeeds or after a reboot"
fi
#
# ── WHY com.palm.flashgraphics IS IN allowedNames ────────────────────────────────────────────
# The device's Flash plugin calls LSRegisterPalmService("com.palm.flashgraphics") and attaches
# that service to the GMainLoop the host hands it via npPalmEventLoopValue; its whole startup
# (getPreferences, display status, db find) runs over that connection. Stock webOS grants the
# name in com.palm.browserServer.json because Flash ran IN-PROCESS in /usr/bin/BrowserServer.
# We run it out-of-process in plugin-container, but plugin-container and the daemon both exec
# through the SAME bundled ld-2.23.so, so the hub resolves both to this one role — granting it
# here covers the plugin child. Without it the hub answers -1027 "Invalid permissions", Flash
# never gets a service handle, nothing is ever attached to the loop, and the player never
# starts its frame clock. Measured 2026-08-07: adding the name turned
# registerServerStatus{com.palm.flashgraphics} from connected:false to connected:true and made
# the child's glib pump run sources for the first time.
#
# The name is not exclusive to us: stock com.palm.browserServer.json also allows it, and only
# one process can hold a bus name at a time. Whoever instantiates Flash first wins; the other
# gets -1027. Acceptable — the stock browser and this one are not expected to play Flash
# simultaneously — but it is why this is first-come-first-served rather than a hard conflict.

# ── REGISTER THIS VARIANT'S db8 KINDS (2026-08-05) ───────────────────────────────────────────
# The installer does NOT do this for us. Measured on the supported path: after installing Mochi
# and Mojo through org.webosinternals.ipkgservice, every one of their kinds came back
# "kind not registered", and the card logged the same error each time it tried to read history
# or bookmarks — i.e. installed, running, and its history silently broken. (Enyo's kinds were
# registered only because a dev helper, build/webos-oe/register-db-kinds.sh, had been run by
# hand months earlier. That helper stays useful for a palm-install dev loop; it must not be the
# only thing that ever registers them.)
#
# putKind/putPermissions are upserts, so this is idempotent and safe on reinstall. The `-a <app
# id>` is load-bearing: db8 requires a kind's declared owner to equal the identity registering
# it, which is also why each variant owns its OWN namespace rather than sharing Enyo's (R7).
if [ -d "$APP/db/kinds" ]; then
	for kf in "$APP/db/kinds"/*; do
		[ -f "$kf" ] || continue
		kn=$(basename "$kf")
		pf="$APP/db/permissions/$kn"
		if luna-send -n 1 -a "net.riverstonerelay.jihad-browser" luna://com.palm.db/putKind "$(cat "$kf")" >/dev/null 2>&1; then
			log "db8 kind registered: $kn"
		else
			log "WARNING: could not register db8 kind $kn — history/bookmarks will not work"
		fi
		if [ -f "$pf" ]; then
			luna-send -n 1 -a "net.riverstonerelay.jihad-browser" luna://com.palm.db/putPermissions \
				"{\"permissions\":$(cat "$pf")}" >/dev/null 2>&1 \
				|| log "WARNING: could not set db8 permissions for $kn"
		fi
	done
fi

cp -a "$DR/event.d/jihad" "$JOB"
# F-7 again: init execs this job as root, so it is not the app bundle's file to own. 0644, not
# 0755 — upstart READS a job file, it never execs it, so the execute bit is pure surface.
chown 0:0 "$JOB" 2>/dev/null || true
chmod 0644 "$JOB"
sync
# F-9: never swallow a failed restore-to-read-only. R8 requires `/` back to ro on every exit
# path, so if it did not happen, say so — out loud, on stderr, where ipkg records it. The EXIT
# trap stays armed as a second attempt when this one fails.
if [ "$ROOTFS_WAS_RW" = yes ]; then
	log "leaving / read-write as found"
else
	# Retried for about ten seconds: the usual cause is a write still settling on / ("Device or
	# resource busy" right after ls-hubd's rescan and db8's kind registrations, device 2026-10-12,
	# when two tries a second apart both failed and / was left rw for every later install).
	ro_try=0
	until mount -o remount,ro / 2>/dev/null; do
		ro_try=$((ro_try + 1))
		if [ "$ro_try" -ge 10 ]; then
			echo "jihad-postinst($V): WARNING: could not restore / to read-only" >&2
			break
		fi
		sync; sleep 1
	done
	[ "$ro_try" -lt 10 ] && trap - EXIT
fi

# ── 3. verify the deploy actually landed ─────────────────────────────────────────────────────
# BusyBox `cp` can fail with EBADF across these mounts, so believe the filesystem, not $?.
[ -f "$SHIM" ] && [ -f "$IMPL" ] && [ -f "$JOB" ] && [ -d "$STATE" ] \
  && [ -x "$HL/jihad-browserserver" ] && [ -x "$HL/ld-2.23.so" ] || {
	echo "jihad-postinst($V): deploy verification failed" >&2; exit 1; }

# ── 4. runtime kicks — optional, never fatal (a reboot picks all of this up anyway) ───────────
# `stop` first: on an UPGRADE the previous daemon is still bound to /tmp/yapserver.jihad-browser and
# still holds the replaced files open, so a bare `start` would fail and leave the old build
# running. Only this variant's job name is used — never a glob, never another variant's job.
set +e
log "restarting the Enyo 1.0 daemon..."
stop jihad 2>/dev/null
# `stop` returns before upstart has finished tearing the job down, and a `start` issued into that
# window is dropped ("Job not changed") — leaving the job STOPPED with no error anywhere. Measured
# 2026-08-01: after a three-variant matrix install, jihad-mochi and jihad-mojo were both
# stop/waiting while enyo happened to win the race; started by hand each came up fine
# ("engine up; serving YAP 'jihad-browser-mochi'"). So: wait for the teardown, then start, then
# CONFIRM — and retry, because a deferred/duplicated install can leave upstart in an odd state.
# NB the status format: this device's upstart prints "(NNN/NNN) <job> (start) running,
# process N" / "(stop) waiting" — NOT the modern "start/running". Match BOTH forms, or the
# teardown wait always times out and the confirm below reports a false WARNING for a daemon
# that is in fact running (observed on the 2026-08-02 mochi deploy).
i=0
while [ $i -lt 10 ]; do
	case "$(status jihad 2>/dev/null)" in *"stop/waiting"*|*"(stop) waiting"*) break ;; esac
	i=$((i + 1)); sleep 1
done
i=0
while [ $i -lt 3 ]; do
	start jihad 2>/dev/null
	sleep 2
	case "$(status jihad 2>/dev/null)" in
		*"start/running"*|*"(start) running"*) break ;;
	esac
	i=$((i + 1))
done
case "$(status jihad 2>/dev/null)" in
	*"start/running"*|*"(start) running"*) log "daemon job jihad is running" ;;
	*) log "WARNING: jihad did not start; it will come up on the next boot" ;;
esac
# F-12: there is deliberately NO `killall LunaSysMgr` here. It tears down every card of every
# app — including the OTHER Jihad variants' cards, which is precisely the cross-variant
# interference R7 exists to forbid, arriving from the packaging side. And it never bought the
# thing it was there for: a NEW plugin enters WebKit's MIME database only on a full BOOT,
# because WebKit scans /usr/lib/BrowserPlugins exactly once, at startup. The old comment
# conceded that. Nothing short of a reboot works, so ASK for the reboot instead of taking the
# user's running cards away in exchange for nothing.
log "install complete."
log "REBOOT the device before launching Enyo 1.0 for the first time: webOS WebKit builds its"
log "NPAPI MIME database at boot, so BrowserAdapterJihad.so stays unregistered until the next one."
exit 0
