File: //var/lib/dpkg/info/imunify-ui-generic.postinst
#!/bin/bash
# postinst script for imunify-antivirus-generic
set -e
is_imunify360_installed()
{
test -f /var/imunify360/.i360
return $?
}
update_config(){
config_path=$1
if is_imunify360_installed ; then
sed -i -E "s/IMUNIFY_PACKAGE = 'AV'/IMUNIFY_PACKAGE = '360'/" "${config_path}"
/usr/share/av-userside-plugin.sh -update-package
else
sed -i -E "s/IMUNIFY_PACKAGE = '360'/IMUNIFY_PACKAGE = 'AV'/" "${config_path}"
fi
}
case "$1" in
configure)
generic_folder=/var/imunify360/generic
generic_integration_config=/etc/sysconfig/imunify360/integration.conf
generic_ui_path=$(\
cat $generic_integration_config | /opt/imunify360/venv/bin/python3 -c 'import sys, configparser, pathlib; config = configparser.ConfigParser(); config.read_file(sys.stdin); p = pathlib.Path(config.get("paths", "ui_path", fallback="")); print(p if p.is_absolute() else "")' \
)
generic_ui_path_owner=$(\
cat $generic_integration_config | /opt/imunify360/venv/bin/python3 -c 'import sys, configparser; config = configparser.ConfigParser(); config.read_file(sys.stdin); print(config.get("paths", "ui_path_owner", fallback=""))' \
)
if [ -z "${generic_ui_path}" ]; then
echo "ERROR: could not get ui_path from ${generic_integration_config}. UI will not be installed."
exit 0
fi
if [ ! -d ${generic_ui_path} ]; then
echo "ERROR: ${generic_ui_path} is not a directory (it should be created by the imunify deploy script). UI will not be installed."
exit 0
fi
mkdir -p -m 0700 $generic_ui_path.unzipped
unzip -o "${generic_folder}/imunify-plugin.zip" -d "${generic_ui_path}.unzipped"
generic_old_path="$generic_ui_path.old.$(date +%s)"
mkdir -p -m 0700 $generic_old_path
mv -fT $generic_ui_path $generic_old_path
mv -fT $generic_ui_path.unzipped $generic_ui_path
rm -rf $generic_old_path
chmod -R 644 $generic_ui_path
chmod -R +X $generic_ui_path # 755 for folders only.
chmod +x $generic_ui_path/bin/execute.py
if [ ! -z ${generic_ui_path_owner} ]; then
chown -R $generic_ui_path_owner $generic_ui_path
fi
# install UI static
cd $generic_ui_path
chmod +x i360deploy-ui.sh
./i360deploy-ui.sh --module core
cd -
chmod 0644 /var/imunify360/generic/imunify-plugin.zip
chmod 0600 /etc/sysconfig/imunify360/auth.admin
if [ -f /etc/cagefs/cagefs.mp ] && [ -d /var/run/defence360agent ] ; then
if ! grep '^/var/run/defence360agent' /etc/cagefs/cagefs.mp ; then
echo "/var/run/defence360agent" >> /etc/cagefs/cagefs.mp
/usr/sbin/cagefsctl -M
fi
fi
update_config "${generic_ui_path}/assets/js/config.js"
;;
triggered)
generic_integration_config=/etc/sysconfig/imunify360/integration.conf
generic_ui_path=$(\
cat $generic_integration_config | /opt/alt/python311/bin/python3 -c 'import sys, configparser, pathlib; config = configparser.ConfigParser(); config.read_file(sys.stdin); p = pathlib.Path(config.get("paths", "ui_path", fallback="")); print(p if p.is_absolute() else "")' \
)
config_path="${generic_ui_path}/assets/js/config.js"
if [ -f "$config_path" ]; then
update_config "${generic_ui_path}/assets/js/config.js"
else
echo "WARNING: could not find $config_path"
fi
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac
exit 0