#!/bin/sh
#called from sfsget, passed param TREE1. ex: devx_0.9.8_amd64.sfs
#181107 nothing passed in if no package.
#190913 if $DB_nameonly=easy then label of desktop icon will be pyro or buster.
#200824 BOOT_LOCK in PUPSTATE set if lockdown (running in RAM), containers will be disabled.

export TEXTDOMAIN=sfsget
export OUTPUT_CHARSET=UTF-8
#eval_gettext ref: http://www.murga-linux.com/puppy/viewtopic.php?t=96326

if [ "$1" == "" ];then
 echo -n "" > /tmp/sfsget/pkgtext
 exit
fi

. /etc/rc.d/PUPSTATE #200824

FULLPKGNAME="${1}"
PKGNAME="${FULLPKGNAME/.sfs/}"
currentpath="$(cat /tmp/sfsget/current-path)"

. /mnt/wkg/sfs/${currentpath}/${PKGNAME}.specs

#190913
xDISTRO_COMPAT_VERSION="$(basename $currentpath)" #pyro or buster
xLABEL="$DB_apps"
[ "$DB_nameonly" == "easy" ] && xLABEL="${xDISTRO_COMPAT_VERSION}"

[ "$DB_description_long" == "" ] && DB_description_long="there is supposed to be a long description in '${PKGNAME}.specs', field DB_description_long, but it is missing."

echo "$DB_description_long" > /tmp/sfsget/pkgtext
#cleanup...
sed -i -e 's%&%&amp;%g' -e 's%>%&gt;%g' -e 's%<%&lt;%g' /tmp/sfsget/pkgtext

#note special syntax below! ref: http://www.murga-linux.com/puppy/viewtopic.php?t=96326
[ "$BOOT_LOCK" ] && DB_install='sanscontainer' #200824 locked-down in ram. ref: PUPSTATE
case "$DB_install" in
 desk) #190913...
  M_install="$(eval echo `gettext 'A container named ${DB_nameonly} will be created, and an icon created on the desktop, labeled ${xLABEL}, which will launch as a separate desktop.'`)"
 ;;
 terminal)
  M_install="$(eval echo `gettext 'A container named ${DB_nameonly} will be created, and an icon created on the desktop, labeled ${DB_apps}, which will launch a terminal window.'`)"
 ;;
 sanscontainer) #200824
  M_install="$(gettext 'You are running in a lockdown mode, containers are not supported. The SFS will be offered to mount on the main filesystem.')"
 ;;
 *) #individual
  M_install="$(eval echo `gettext 'A container named ${DB_nameonly} will be created, and icons created on the desktop, labeled: ${DB_apps}'`)"
 ;;
esac
echo "
<b>$(gettext 'Install mode')</b>
${M_install}" >> /tmp/sfsget/pkgtext

#note special syntax below! ref: http://www.murga-linux.com/puppy/viewtopic.php?t=96326
if [ "$DB_dependencies" == "" ];then
 M_deps="$(eval echo `gettext 'There are no dependencies for ${DB_fullfilename}, so there will be no SFS files loaded below it.'`)"
else
 M_deps="$(eval echo `gettext '${DB_fullfilename} has these dependencies: ${DB_dependencies}. They will be loaded in the layered filesystem in the container.'`)"
fi
M_deps="$(echo -n "$M_deps" | sed -e 's%&%&amp;%g')" #cleanup
if [ "$DB_install" != "sanscontainer" ];then #200824
 echo "
<b>$(gettext 'Dependencies')</b>
${M_deps}" >> /tmp/sfsget/pkgtext
fi

###end###
