#!/usr/bin/env bash

post_install() {
	local directory=/usr/share/bigbashview/bcc/apps/bigbashview-calamares
	local mode temporary

	# This is an optional compatibility marker owned by BigBashView. Do not make
	# that application a hard dependency or create directories in its namespace.
	[[ -d $directory && ! -L $directory && $(stat -c %u -- "$directory") == 0 ]] || return 0
	mode=$(stat -c %a -- "$directory") || return 0
	(((8#$mode & 8#22) == 0)) || return 0

	temporary=$(mktemp --tmpdir="$directory" .install_date.XXXXXX) || return 0
	if ! printf '%s\n' "$(($(date +%s) / 86400))" >"$temporary"; then
		rm -f -- "$temporary"
		return 0
	fi
	if ! chmod 0644 "$temporary" || ! mv -fT -- "$temporary" "$directory/install_date"; then
		rm -f -- "$temporary"
	fi
	return 0
}
