#!/bin/sh
#(c) Copyright Barry Kauler 2009, puppylinux.com
#2009 Lesser GPL licence v2 (http://www.fsf.org/licensing/licenses/lgpl.html).
#called from pkg_chooser.sh
#package to be previewed prior to installation is TREE1 -- inherited from parent.
#/tmp/petget/current-repo-triad has the repository that installing from.
#100821 bug in Lucid 5.1, /tmp/pup_event_sizefreem had two identical lines.
#101221 yaf-splash fix.
#120101 01micko: jwm >=547 has -reload, no screen flicker.
#120116 rev. 514 introduced icon rendering method which broke -reload at 547. fixed at rev. 574.
#120203 BK: internationalized.
#120504 if no pkgs in category, then when click in window in main dlg, comes here with TREE1="".
#120504 select correct repo when have chosen a pkg from multiple-repo list.
#120604 fix for prepended icons field.
#120811 category field now supports sub-category |category;subcategory|, use as icon in ppm main window.
#120827 if pkg already installed, do not examine dependencies (doesn't work).
#120903 ubuntu, have lots pkgs installed, check_deps.sh takes ages, remove for now, need to rewrite in C.
#120904 "examine dependencies" button did not create any /tmp/petget_missing_dbentries-*, workaround.
#120905 better advice if too many deps. 120907 revert.
#120907 max frames increase 5 to 10. Note, precise puppy gave 72 deps for vlc, which would require 10 frames.
#130511 popup warning if a dep in devx but devx not loaded.
[ "$(cat /var/local/petget/nt_category 2>/dev/null)" != "true" ] && \
[ -f /tmp/install_quietly ] && set -x
#; mkdir -p /tmp/PPM_LOGs ; NAME=$(basename "$0"); exec 1>> /tmp/PPM_LOGs/"$NAME".log 2>&1
export TEXTDOMAIN=petget___installpreview.sh
export OUTPUT_CHARSET=UTF-8
[ "$TREE1" = "" ] && exit #120504 nothing to install.
. /etc/DISTRO_SPECS #has DISTRO_BINARY_COMPAT, DISTRO_COMPAT_VERSION
. /root/.packages/DISTRO_PKGS_SPECS
if [ ! -f /tmp/install_quietly ]; then
. /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'Please wait, processing package database files...')" &
X1PID=$!
fi
#ex: TREE1=abiword-1.2.4 (first field in database entry).
DB_FILE=Packages-`cat /tmp/petget/current-repo-triad` #ex: Packages-slackware-12.2-official
tPATTERN='^'"$TREE1"'|'
#120827 'examine dependencies' button does not work if pkg already installed...
EXAMDEPSFLAG='yes'
ttPTN='^'"$TREE1"'|.*ALREADY INSTALLED'
if [ "`grep "$ttPTN" /tmp/petget/filterpkgs.results.post`" != "" ];then #created by postfilterpkgs.sh
EXAMDEPSFLAG='no'
fi
#120504 if findnames.sh searched multiple repos, /tmp/petget/current-repo-triad (set in pkg_chooser.sh) might be wrong...
[ -f /tmp/petget/current-repo-triad.previous ] && rm -f /tmp/petget/current-repo-triad.previous
if [ -f /tmp/petget/filterpkgs.results.post ];then
ALTSEARCHREPO="$(grep "$tPATTERN" /tmp/petget/filterpkgs.results.post | grep '|\[' | cut -f 2 -d '[' | cut -f 1 -d ']')"
[ "$ALTSEARCHREPO" ] && DB_FILE="Packages-${ALTSEARCHREPO}"
#hmmm, other scripts, ex dependencies.sh, will need to have this correct...
if [ "$ALTSEARCHREPO" ];then
mv -f /tmp/petget/current-repo-triad /tmp/petget/current-repo-triad.previous #need to restore old one before exit this script.
echo -n "$ALTSEARCHREPO" > /tmp/petget/current-repo-triad
fi
fi
rm -f /tmp/petget_missing_dbentries-* 2>/dev/null
DB_ENTRY="`grep "$tPATTERN" /root/.packages/$DB_FILE | head -n 1`"
#line format: pkgname|nameonly|version|pkgrelease|category|size|path|fullfilename|dependencies|description|
#optionally on the end: compileddistro|compiledrelease|repo| (fields 11,12,13)
DB_pkgname="`echo -n "$DB_ENTRY" | cut -f 1 -d '|'`"
DB_nameonly="`echo -n "$DB_ENTRY" | cut -f 2 -d '|'`"
DB_version="`echo -n "$DB_ENTRY" | cut -f 3 -d '|'`"
DB_pkgrelease="`echo -n "$DB_ENTRY" | cut -f 4 -d '|'`"
DB_category="`echo -n "$DB_ENTRY" | cut -f 5 -d '|'`"
DB_size="`echo -n "$DB_ENTRY" | cut -f 6 -d '|'`"
DB_path="`echo -n "$DB_ENTRY" | cut -f 7 -d '|'`"
DB_fullfilename="`echo -n "$DB_ENTRY" | cut -f 8 -d '|'`"
DB_dependencies="`echo -n "$DB_ENTRY" | cut -f 9 -d '|'`"
DB_description="`echo -n "$DB_ENTRY" | cut -f 10 -d '|'`"
[ "$DB_description" = "" ] && DB_description="$(gettext 'no description available')"
SIZEFREEM=`cat /tmp/pup_event_sizefreem | head -n 1` #100821 bug in Lucid 5.1, file had two identical lines.
SIZEFREEK=`expr $SIZEFREEM \* 1024`
if [ $DB_size ];then
SIZEMK="`echo -n "$DB_size" | rev | cut -c 1`"
SIZEVAL=`echo -n "$DB_size" | rev | cut -c 2-9 | rev`
SIZEINFO=""
SIZEVALz=`expr $SIZEVAL \/ 3`
SIZEVALz=`expr $SIZEVAL + $SIZEVALz`
SIZEVALx2=`expr $SIZEVALz + 10000`
if [ $SIZEVALx2 -ge $SIZEFREEK ];then
MSGWARN1="${SIZEINFO}"
else
MSGWARN1="${SIZEINFO}"
fi
else
MSGWARN1=""
fi
#find missing dependencies...
if [ "$DB_dependencies" = "" ];then
DEPINFO=""
else
#find all missing pkgs...
/usr/local/petget/findmissingpkgs.sh "$DB_dependencies"
#...returns /tmp/petget_installed_patterns_all, /tmp/petget_pkg_deps_patterns, /tmp/petget_missingpkgs_patterns
MISSINGDEPS_PATTERNS="`cat /tmp/petget_missingpkgs_patterns`"
#/tmp/petget_missingpkgs_patterns has a list of missing dependencies, format ex:
#|kdebase|
#|kdelibs|
#|mesa|
#|qt|
DEPBUTTON=""
ONLYMSG=""
if [ "$MISSINGDEPS_PATTERNS" = "" ];then
DEPINFO=""
else
ONLYMSG=" $(gettext 'ONLY')"
xMISSINGDEPS="`echo "$MISSINGDEPS_PATTERNS" | sed -e 's%|%%g' | tr '\n' ' '`"
if [ "$EXAMDEPSFLAG" != "no" ];then #120828
DEPBUTTON=""
DEPINFO="
"
else
DEPINFO="
"
fi
if [ $DB_size ];then
MSGWARN1=""
else
MSGWARN1=""
fi
fi
fi
[ ! -f /tmp/install_quietly ] && kill $X1PID || echo
if [ ! -f /tmp/install_quietly ]; then
export PREVIEW_DIALOG="
${DEPINFO}
${MSGWARN1}
${DEPBUTTON}
"
RETPARAMS="`gtkdialog3 --center --program=PREVIEW_DIALOG`"
else
if [ -f /tmp/download_only_pet_quietly ]; then
RETPARAMS='EXIT="BUTTON_PKGS_DOWNLOADONLY"'
elif [ "$MISSINGDEPS_PATTERNS" != "" ];then
RETPARAMS='EXIT="BUTTON_EXAMINE_DEPS"'
elif [ -f /tmp/download_pets_quietly ]; then
RETPARAMS='EXIT="BUTTON_PKGS_DOWNLOADONLY"'
else
RETPARAMS='EXIT="BUTTON_INSTALL"'
fi
fi
eval "$RETPARAMS"
if [ "$EXIT" != "BUTTON_INSTALL" -a "$EXIT" != "BUTTON_EXAMINE_DEPS" -a "$EXIT" != "BUTTON_PKGS_DOWNLOADONLY" ];then
[ -f /tmp/petget/current-repo-triad.previous ] && mv -f /tmp/petget/current-repo-triad.previous /tmp/petget/current-repo-triad
exit
fi
#DB_ENTRY has the database entry of the main package that we want to install.
#DB_FILE has the name of the database file that has the main entry, ex: Packages-slackware-12.2-slacky
if [ "$EXIT" = "BUTTON_EXAMINE_DEPS" ];then
/usr/local/petget/dependencies.sh
[ $? -ne 0 ] && exec /usr/local/petget/installpreview.sh #reenter.
#returns with /tmp/petget_missing_dbentries-* has the database entries of missing deps.
#the '*' on the end is the repo-file name, ex: Packages-slackware-12.2-slacky
#120904
FNDMISSINGDBENTRYFILE="`ls -1 /tmp/petget_missing_dbentries-* 2>/dev/null`"
if [ "$FNDMISSINGDBENTRYFILE" = "" -a ! -f /tmp/install_quietly ];then
. pupdialog --title "$(gettext 'PPM: examine dependencies')" --background LightYellow --msgbox "$(gettext 'There seem to be no missing dependencies.')
$(gettext 'Note: if the previous window indicated that there are missing dependencies, they were not found. Sometimes, a package database lists a dependency that does not actually exist anymore and is not required.')" 0 0
exec /usr/local/petget/installpreview.sh #reenter.
fi
#130511 popup warning if a dep in devx but devx not loaded...
if ! which gcc; then
NEEDGCC="$(cat /tmp/petget_missing_dbentries-* | grep -E '\|gcc\||\|gcc_dev_DEV\|' | cut -f 1 -d '|')"
if [ "$NEEDGCC" ];then
rm -f /tmp/petget_installed_patterns_system #see pkg_chooser.sh
#create a separate process for the popup, with delay...
DEVXNAME="devx_${DISTRO_FILE_PREFIX}_${DISTRO_VERSION}.sfs"
echo "#!/bin/sh
sleep 3
. pupdialog --background pink --colors --ok-label \"$(gettext 'OK')\" --backtitle \"$(gettext 'WARNING: devx not installed')\" --msgbox \"$(gettext 'Package:') \Zb${TREE1}\ZB
$(gettext "This package has dependencies that are in the 'devx' SFS file, which is Puppy's C/C++/Vala/Genie/BaCon mega-package, a complete compiling environment.")
$(gettext 'The devx file is named:') \Zb${DEVXNAME}\ZB
$(gettext "Please cancel installation, close the Puppy Package Manager, then click the \Zbinstall\ZB icon on the desktop and install the devx SFS file first.")\" 0 0" > /tmp/petget_devx_popup.sh #'geany
chmod 755 /tmp/petget_devx_popup.sh
/tmp/petget_devx_popup.sh &
fi
fi
#compose pkgs into checkboxes...
MAIN_REPO="`echo "$DB_FILE" | cut -f 2-9 -d '-'`"
MAINPKG_NAME="`echo "$DB_ENTRY" | cut -f 1 -d '|'`"
MAINPKG_SIZE="`echo "$DB_ENTRY" | cut -f 6 -d '|'`"
MAINPKG_DESCR="`echo "$DB_ENTRY" | cut -f 10 -d '|'`"
MAIN_CHK="trueCHECK_PKG_${MAIN_REPO}_${MAINPKG_NAME}"
INSTALLEDSIZEK=0
[ "$MAINPKG_SIZE" != "" ] && INSTALLEDSIZEK=`echo "$MAINPKG_SIZE" | rev | cut -c 2-10 | rev`
#making up the dependencies into tabs, need limit of 8 per tab...
#also limit to 6 tabs (gedit is way beyond this!)...
echo -n "" > /tmp/petget_moreframes
echo -n "" > /tmp/petget_tabs
echo "0" > /tmp/petget_frame_cnt
DEP_CNT=0
ONEREPO=""
for ONEDEPSLIST in `ls -1 /tmp/petget_missing_dbentries-*`
do
ONEREPO_PREV="$ONEREPO"
ONEREPO="`echo "$ONEDEPSLIST" | grep -o 'Packages.*' | sed -e 's%Packages\\-%%'`"
FRAME_CNT=`cat /tmp/petget_frame_cnt`
if [ "$ONEREPO_PREV" != "" ];then #next repo, so start a new tab.
DEP_CNT=0
FRAME_CNT=`expr $FRAME_CNT + 1`
echo "$FRAME_CNT" > /tmp/petget_frame_cnt
#w017 bugfix, prevent double frame closure...
[ "`cat /tmp/petget_moreframes | tail -n 1 | grep '$'`" = "" ] && echo "" >> /tmp/petget_moreframes
fi
cat $ONEDEPSLIST |
while read ONELIST
do
DEP_NAME="`echo "$ONELIST" | cut -f 1 -d '|'`"
DEP_SIZE="`echo "$ONELIST" | cut -f 6 -d '|'`"
DEP_DESCR="`echo "$ONELIST" | cut -f 10 -d '|'`"
DEP_CNT=`expr $DEP_CNT + 1`
case $DEP_CNT in
1)
echo -n "" >> /tmp/petget_moreframes
echo -n "Dependencies|" >> /tmp/petget_tabs
echo -n "trueCHECK_PKG_${ONEREPO}_${DEP_NAME}" >> /tmp/petget_moreframes
;;
8)
FRAME_CNT=`cat /tmp/petget_frame_cnt`
FRAME_CNT=`expr $FRAME_CNT + 1`
if [ $FRAME_CNT -gt 10 ];then #120907
echo -n "" >> /tmp/petget_moreframes #120907
else
echo -n "trueCHECK_PKG_${ONEREPO}_${DEP_NAME}" >> /tmp/petget_moreframes
fi
echo "" >> /tmp/petget_moreframes
DEP_CNT=0
echo "$FRAME_CNT" > /tmp/petget_frame_cnt
;;
*)
echo -n "trueCHECK_PKG_${ONEREPO}_${DEP_NAME}" >> /tmp/petget_moreframes
;;
esac
[ $FRAME_CNT -gt 10 ] && break #too wide! 120907
ADDSIZEK=0
[ "$DEP_SIZE" != "" ] && ADDSIZEK=`echo "$DEP_SIZE" | rev | cut -c 2-10 | rev`
INSTALLEDSIZEK=`expr $INSTALLEDSIZEK + $ADDSIZEK`
echo "$INSTALLEDSIZEK" > /tmp/petget_installedsizek
done
INSTALLEDSIZEK=`cat /tmp/petget_installedsizek`
FRAME_CNT=`cat /tmp/petget_frame_cnt`
[ $FRAME_CNT -gt 10 ] && break #too wide! 120907
done
TABS="`cat /tmp/petget_tabs`"
MOREFRAMES="`cat /tmp/petget_moreframes`"
#make sure last frame has closed...
[ "`echo "$MOREFRAMES" | tail -n 1 | grep '$'`" = "" ] && MOREFRAMES="${MOREFRAMES}"
INSTALLEDSIZEM=`expr $INSTALLEDSIZEK \/ 1024`
MSGWARN2="$(gettext "If that looks like enough free space, go ahead and click the 'Install' button...")"
testSIZEK=`expr $INSTALLEDSIZEK \/ 3`
testSIZEK=`expr $INSTALLEDSIZEK + $testSIZEK`
testSIZEK=`expr $testSIZEK + 8000`
[ $testSIZEK -gt $SIZEFREEK ] && MSGWARN2="$(gettext "Not too good! recommend that you make more space before installing -- see 'Resize personal storage file' in the 'Utility' menu.")"
if [ ! -f /tmp/install_quietly ]; then
export DEPS_DIALOG="
${MAIN_CHK}
${MOREFRAMES}
"
RETPARAMS="`gtkdialog3 --center --program=DEPS_DIALOG`"
else
if [ ! -f /tmp/download_pets_quietly ]; then
xEXIT="BUTTON_PKGS_INSTALL"
else
xEXIT="BUTTON_PKGS_DOWNLOADONLY"
fi
DEPS_TOINSTALL=$(sed 's//\n/g' /tmp/petget_moreframes \
|grep ^CHECK_PKG_ | cut -f1 -d '<' | sed 's/$/=\"true\"/')
PKG_TOINSTALL=CHECK_PKG_${MAIN_REPO}_${MAINPKG_NAME}="true"
RETPARAMS="$DEPS_TOINSTALL
$PKG_TOINSTALL
EXIT=$xEXIT"
[ "$DEPS_TOINSTALL" != "" ] && echo "$DEPS_TOINSTALL" | cut -f 1 -d '=' \
| cut -f 4-10 -d '_' >> /tmp/pkgs_to_install_done
rm -f /tmp/petget_moreframes
fi
#example if 'Install' button clicked:
#CHECK_PKG_slackware-12.2-official_libtermcap-1.2.3="true"
#CHECK_PKG_slackware-12.2-official_pygtk-2.12.1="true"
#CHECK_PKG_slackware-12.2-slacky_beagle-0.3.9="true"
#CHECK_PKG_slackware-12.2-slacky_libgdiplus-2.0="true"
#CHECK_PKG_slackware-12.2-slacky_libgdiplus-2.2="true"
#CHECK_PKG_slackware-12.2-slacky_mono-2.2="true"
#CHECK_PKG_slackware-12.2-slacky_monodoc-2.0="true"
#EXIT="BUTTON_PKGS_INSTALL"
if [ "`echo "$RETPARAMS" | grep '^EXIT' | grep -E 'BUTTON_PKGS_INSTALL|BUTTON_PKGS_DOWNLOADONLY'`" != "" ];then
#remove any unticked pkgs from the list...
for ONECHK in `echo "$RETPARAMS" | grep '^CHECK_PKG_' | grep '"false"' | tr '\n' ' '`
do
ONEREPO="`echo -n "$ONECHK" | cut -f 1 -d '=' | cut -f 3 -d '_'`" #ex: slackware-12.2-slacky
ONEPKG="`echo -n "$ONECHK" | cut -f 1 -d '=' | cut -f 4-9 -d '_'`" #ex: libtermcap-1.2.3
opPATTERN='^'"$ONEPKG"'|'
grep -v "$opPATTERN" /tmp/petget_missing_dbentries-Packages-${ONEREPO} > /tmp/petget_tmp
mv -f /tmp/petget_tmp /tmp/petget_missing_dbentries-Packages-${ONEREPO}
done
else
[ -f /tmp/petget/current-repo-triad.previous ] && mv -f /tmp/petget/current-repo-triad.previous /tmp/petget/current-repo-triad #120504
exit
fi
fi
#come here, want to install pkg(s)...
#DB_ENTRY has the database entry of the main package that we want to install.
#DB_FILE has the name of the database file that has the main entry, ex: Packages-slackware-12.2-slacky
#TREE1 is name of main pkg, ex: abiword-1.2.3
#check to see if main pkg entry already in install-lists...
touch /tmp/petget_missing_dbentries-${DB_FILE} #create if doesn't exist.
mPATTERN='^'"$TREE1"'|'
if [ "`grep "$mPATTERN" /tmp/petget_missing_dbentries-${DB_FILE}`" = "" ];then
echo "$DB_ENTRY" >> /tmp/petget_missing_dbentries-${DB_FILE}
fi
#now do the actual install...
PASSEDPRM=""
[ "`echo "$RETPARAMS" | grep '^EXIT' | grep 'BUTTON_PKGS_DOWNLOADONLY'`" != "" ] && PASSEDPRM="DOWNLOADONLY" && touch /tmp/manual_pkg_download
/usr/local/petget/downloadpkgs.sh $PASSEDPRM
if [ $? -ne 0 ];then
[ -f /tmp/petget/current-repo-triad.previous ] && mv -f /tmp/petget/current-repo-triad.previous /tmp/petget/current-repo-triad #120504
exit 1
fi
[ "$PASSEDPRM" = "DOWNLOADONLY" ] && exit
if [ -f /tmp/install_pets_quietly ]; then
LEFT=$(cat /tmp/pkgs_left_to_install | wc -l)
[ "$LEFT" -le 1 ] && UPDATE_MENUS=yes
else
UPDATE_MENUS=yes
fi
if [ "$UPDATE_MENUS" = "yes" ]; then
INSTALLEDCAT="menu" #any string.
[ "`cat /tmp/petget-installed-pkgs-log | grep -o 'CATEGORY' | grep -v 'none'`" = "" ] && INSTALLEDCAT="none"
RESTARTMSG="$(gettext 'Please wait, updating help page and menu...')"
[ "$INSTALLEDCAT" = "none" ] && RESTARTMSG="$(gettext 'Please wait, updating help page...')"
if [ ! -f /tmp/install_quietly ]; then
/usr/lib/gtkdialog/box_splash -text "${RESTARTMSG}" &
X3PID=$!
fi
fi
#w091019 update image cache...
iUPDATE='no'
for iONE in `cat /tmp/petget_missing_dbentries-* | cut -f 1 -d '|' | tr '\n' ' '`
do
if [ -f /root/.packages/${iONE}.files ]; then
[ "`grep 'usr/share/icons/hicolor' /root/.packages/${iONE}.files`" != "" ] \
&& echo yes >> /tmp/iUPDATE
fi
done
if [ "$UPDATE_MENUS" = "yes" ]; then
if [ "$(grep yes /tmp/iUPDATE)" != "" ]; then \
gtk-update-icon-cache -f /usr/share/icons/hicolor/
rm -f /tmp/iUPDATE
fi
fi
#Reconstruct configuration files for JWM, Fvwm95, IceWM...
if [ "$UPDATE_MENUS" = "yes" -a "$INSTALLEDCAT" != "none" ];then
nohup /usr/sbin/fixmenus
[ "`pidof jwm`" != "" ] && { jwm -reload || jwm -restart ; }
fi
[ ! -f /tmp/install_quietly ] && kill $X3PID || echo
#120905 restore...
#120903 ubuntu, have lots pkgs installed, this takes ages. remove for now, need to rewrite in C...
#check any missing shared libraries...
PKGS="`cat /tmp/petget_missing_dbentries-* | cut -f 1 -d '|' | tr '\n' '|'`"
/usr/local/petget/check_deps.sh $PKGS
[ -f /tmp/petget/current-repo-triad.previous ] && mv -f /tmp/petget/current-repo-triad.previous /tmp/petget/current-repo-triad #120504
rm -f nohup.out 2>/dev/null
###END###