#!/bin/sh
#(c) Copyright Barry Kauler 2009, puppylinux.com
#2009 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html).
#called from /usr/local/petget/pkg_chooser.sh
#configure package manager
#110118 alternate user interfaces.
#120203 BK: internationalized.
#120210 01micko: Ziggy ui crashes if *all* repos unticked here (no one would do that, but it is still a bug).
#120515 in some cases, Packages-puppy-${DISTRO_FILE_PREFIX}-* may not exist (ex, Racy only has Packages-puppy-wary5-official).
#120529 checkbox to display app thumbnail icons.
#120811 category field now supports sub-category |category;subcategory|, use as icon in ppm main window. -- always enabled.
#121102 Packages-puppy-${DISTRO_FILE_PREFIX}- (or Packages-puppy-${DISTRO_COMPAT_VERSION}-) is now Packages-puppy-${DISTRO_DB_SUBNAME}-. refer /etc/DISTRO_SPECS.
#121129 Update: d/l Packages-puppy-squeeze-official, which wasn't there before, upset this script.
export TEXTDOMAIN=petget___configure.sh
export OUTPUT_CHARSET=UTF-8
. gettext.sh
#export LANG=C
. /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
. /etc/rc.d/PUPSTATE
. /root/.packages/DISTRO_PKGS_SPECS
. /root/.packages/DISTRO_PET_REPOS
. /root/.packages/PKGS_MANAGEMENT #has PKG_REPOS_ENABLED
#find what repos are currently in use... 120510...
CHECKBOXES_REPOS=""
#for ONEREPO in `ls -1 /root/.packages/Packages-*`
#120510 bugfix with ui_Ziggy. add CHECKBOX_MAIN_REPO var to gui
MAIN_REPO="`ls -1 /root/.packages/Packages-* | grep "puppy\-${DISTRO_DB_SUBNAME}\-" | head -n 1 | sed 's%^/root/.packages/%%'`" #121102 121129
#120515 hmmm, in some cases, Packages-puppy-${DISTRO_FILE_PREFIX}-* may not exist (ex, Racy only has Packages-puppy-wary5-official)...
#121102 ...now using DISTRO_DB_SUBNAME, should always exist.
[ "$MAIN_REPO" = "" ] && MAIN_REPO="`echo "$PACKAGELISTS_PET_ORDER" | tr ' ' '\n' | head -n 1`" #PACKAGELISTS_PET_ORDER is in /root/.packages/DISTRO_PET_REPOS.
[ "$MAIN_REPO" = "" ] && MAIN_REPO="Packages-puppy-noarch-official" #paranoid precaution.
bMAIN_PATTERN=' '"$MAIN_REPO"' '
MAIN_DBNAME="`echo -n "$MAIN_REPO" | sed -e 's%Packages\-%%'`"
CHECKBOX_MAIN_REPO="trueCHECK_${MAIN_DBNAME}disabled" #hard coded "true"
DBFILESLIST="$(ls -1 /root/.packages/Packages-*)" #121129
PKG_REPOS_ENABLED=" ${PKG_REPOS_ENABLED} " #121129 precaution.
for ONEREPO in `echo "$DBFILESLIST" | grep -v "${MAIN_REPO}" | tr '\n' ' '` #120515 fix. 121129
do
BASEREPO="`basename $ONEREPO`"
bPATTERN=' '"${BASEREPO}"' '
DEFAULT='true'
[ "`echo -n "$PKG_REPOS_ENABLED" | grep "$bPATTERN"`" = "" ] && DEFAULT='false'
DBNAME="`echo -n "$BASEREPO" | sed -e 's%Packages\-%%'`"
CHECKBOXES_REPOS="${CHECKBOXES_REPOS}${DEFAULT}CHECK_${DBNAME}"
done
if [ "$(cat /tmp/pup_event_sizefreem | head -n 1 )" -gt 4000 ]; then
[ -f /var/local/petget/sc_category ] && \
CATEGORY_SC=$(cat /var/local/petget/sc_category) || CATEGORY_SC="false"
SIZEBOX="
CATEGORY_SC
${CATEGORY_SC}
"
else
SIZEBOX=''
fi
if [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ]; then
[ -f /var/local/petget/sc_category ] && \
CATEGORY_IM=$(cat /var/local/petget/install_mode) || CATEGORY_IM="false"
IMODE="
CATEGORY_IM
${CATEGORY_IM}
"
else
IMODE=''
fi
# pet download folder
SAVEPATH=""
if [ -f /root/.packages/download_path ]; then
. /root/.packages/download_path
if [ -d "$DL_PATH" ];then
DL_PATH="$DL_PATH"
else
DL_PATH=/root
rm -f /root/.packages/download_path
fi
else
DL_PATH=/root
fi
DBmethod="$(cat /var/local/petget/db_verbose)"
if [ "$DBmethod" = "" ]; then
echo true > /var/local/petget/db_verbose
DBmethod=true
fi
if [ "$DBmethod" = "false" ]; then
RXVT="rxvt -title \"$(gettext 'Updating Databases')\" -geometry 110x12+0+200 -bg gray -e "
else
RXVT="rxvt -bg yellow -title \"$(gettext 'Databases Update')\" -e "
fi
export SETUPCALLEDFROM='ppm'
S='
'${CHECKBOXES_REPOS}'
'${CHECKBOX_MAIN_REPO}'
'"`/usr/lib/gtkdialog/xml_pixmap nb.svg`"'
'"`/usr/lib/gtkdialog/xml_pixmap info.svg`"'
'"`/usr/lib/gtkdialog/xml_pixmap info.svg`"'
CATEGORY_SI'
[ "$(true'
S=$S'
CATEGORY_BB'
[ "$(true'
S=$S'
'
[ "$(true'
S=$S'if true echo Classic > /var/local/petget/ui_choice
if false echo Ziggy > /var/local/petget/ui_choice
'
[ "$(true'
S=$S'if true echo tall > /var/local/petget/uo_choice
if false echo wide > /var/local/petget/uo_choice
'${SIZEBOX}'
CATEGORY_NT'
[ "$(true'
S=$S'
'${IMODE}'
CATEGORY_RD'
[ "$(true'
S=$S'
CATEGORY_ND'
[ "$(true'
S=$S'
CATEGORY_SD'
[ "$(true'
S=$S'
'$DBmethod'
DBmethod
if true echo true > /var/local/petget/db_verbose
if false echo false > /var/local/petget/db_verbose
/usr/local/petget/configure.sh &
exit:QUIT
'${DL_PATH}'SAVEPATH
'"`/usr/lib/gtkdialog/xml_scalegrip`"'
'
export PPM_CONFIG="$S"
#echo "$PPM_CONFIG" > /root/gtk
RETPARAMS="`gtkdialog -p PPM_CONFIG`"
#ex:
# CHECK_puppy-2-official="false"
# CHECK_puppy-3-official="true"
# CHECK_puppy-4-official="true"
# CHECK_puppy-woof-official="false"
# CHECK_ubuntu-intrepid-main="true"
# CHECK_ubuntu-intrepid-multiverse="true"
# CHECK_ubuntu-intrepid-universe="true"
# EXIT="OK"
[ "`echo -n "$RETPARAMS" | grep 'EXIT' | grep 'OK'`" = "" ] && exit
echo -n "$RETPARAMS" | grep 'CATEGORY_BB' | cut -d= -f2 | tr -d '"' > /var/local/petget/bb_category
echo -n "$RETPARAMS" | grep 'CATEGORY_SC' | cut -d= -f2 | tr -d '"' > /var/local/petget/sc_category
echo -n "$RETPARAMS" | grep 'CATEGORY_NT' | cut -d= -f2 | tr -d '"' > /var/local/petget/nt_category
echo -n "$RETPARAMS" | grep 'CATEGORY_RD' | cut -d= -f2 | tr -d '"' > /var/local/petget/rd_category
echo -n "$RETPARAMS" | grep 'CATEGORY_ND' | cut -d= -f2 | tr -d '"' > /var/local/petget/nd_category
echo -n "$RETPARAMS" | grep 'CATEGORY_SD' | cut -d= -f2 | tr -d '"' > /var/local/petget/sd_category
echo -n "$RETPARAMS" | grep 'CATEGORY_SI' | cut -d= -f2 | tr -d '"' > /var/local/petget/si_category
# handle install mode
if [ $PUPMODE -eq 3 -o $PUPMODE -eq 7 -o $PUPMODE -eq 13 ]; then
echo -n "$RETPARAMS" | grep 'CATEGORY_IM' | cut -d= -f2 | tr -d '"' > /var/local/petget/install_mode
fi
# handle savepath
SAVEPATH="`echo -n "$RETPARAMS" | grep 'SAVEPATH' | cut -f 2 -d '"'`"
if [ "$SAVEPATH" = "" ];then
rm -f /root/.packages/download_path
else
if [ ! -d "$SAVEPATH" ]; then
mkdir -p "$SAVEPATH"
[ $? -eq 0 ] && echo DL_PATH=\'$SAVEPATH\' > /root/.packages/download_path
elif [ -w "$SAVEPATH" ]; then
echo DL_PATH=\'$SAVEPATH\' > /root/.packages/download_path
else
rm -f /root/.packages/download_path
fi
fi
enabledrepos=" "
#repocnt=1
for ONEREPO in `echo "$DBFILESLIST" | tr '\n' ' '` #121129
do
REPOBASE="`basename $ONEREPO`"
repoPATTERN="`echo -n "$REPOBASE" | sed -e 's%Packages\\-%%' | sed -e 's%\\-%\\\\-%g'`"
if [ "`echo "$RETPARAMS" | grep "$repoPATTERN" | grep 'false'`" = "" ];then
enabledrepos="${enabledrepos}${REPOBASE} "
# repocnt=`expr $repocnt + 1`
# [ $repocnt -gt 5 ] && break #only allow 5 active repos in PPM.
fi
done
grep -v '^PKG_REPOS_ENABLED' /root/.packages/PKGS_MANAGEMENT > /tmp/pkgs_management_tmp2
mv -f /tmp/pkgs_management_tmp2 /root/.packages/PKGS_MANAGEMENT
echo "PKG_REPOS_ENABLED='${enabledrepos}'" >> /root/.packages/PKGS_MANAGEMENT
for I in `grep -E "PPM_GUI|pkg_chooser|/usr/local/bin/ppm" <<< "$(ps -eo pid,command)" | awk '{print $1}' `; do kill -9 $I; done
sleep 0.5
/usr/local/petget/pkg_chooser.sh &
###END###