G2A Many GEOs
SHARE
TWEET

install_missing.sh (4)

s243a Mar 26th, 2020 (edited) 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. INSTALL_MODE='Step by step installation (classic mode)'
  3. EXPORT_FNs=false #Setting this to true might provide a way of overriding the functions in the ppm gui.
  4. USE_installmodes_sh=false
  5. SKIP_installmodes_sh=false
  6.  
  7. rm /tmp/petget_proc/pkgs_to_install_s243a
  8. rm /tmp/petget_proc/pkgs_to_install
  9. #touch /root/.packages/skip_space_check
  10. echo changed > /tmp/petget_proc/mode_changed
  11. touch /tmp/petget_proc/force_install
  12. touch /root/.packages/skip_space_check
  13. touch /tmp/petget_proc/manual_pkg_download
  14.  
  15. rm /tmp/petget_proc/pkgs_to_install
  16.  
  17.  
  18. if [ ! -f /tmp/petget_proc/install_pets_quietly -a ! -f /tmp/petget_proc/download_only_pet_quietly \
  19.     -a ! -f /tmp/petget_proc/download_pets_quietly ]; then
  20.     echo ok
  21. elif [ "$PREVPKG" != "" ]; then
  22.     echo changed >> /tmp/petget_proc/mode_changed
  23. fi
  24. rm -f /tmp/petget_proc/*_pet{,s}_quietly
  25. echo "" > /tmp/petget_proc/forced_install
  26. touch /tmp/petget_proc/install_classic
  27. echo 'wizard' > /var/local/petget/ppm_mode
  28.  
  29.  
  30.  
  31.  
  32. #install_package () is taken from: https://github.com/puppylinux-woof-CE/woof-CE/blob/60d94862a3343bf0a062a0fcd0dd73475d6985ba/woof-code/rootfs-skeleton/usr/local/petget/installmodes.sh#L406
  33. install_package () {
  34.  #set -x
  35.  [ "$(cat /tmp/petget_proc/pkgs_to_install)" = "" ] && exit 0
  36.  cat /tmp/petget_proc/pkgs_to_install | tr ' ' '\n' > /tmp/petget_proc/pkgs_left_to_install
  37.  rm -f /tmp/petget_proc/overall_package_status_log
  38.  echo 0 > /tmp/petget_proc/petget/install_status_percent
  39.  echo "$(gettext "Calculating total required space...")" > /tmp/petget_proc/petget/install_status
  40.  [ ! -f /root/.packages/skip_space_check ] && check_total_size
  41.  #status_bar_func & #-----------
  42.  while IFS="|" read TREE1 REPO zz #TREE1|REPO
  43.  do
  44.    [ -z "$TREE1" ] && continue
  45.    echo "$REPO" > /tmp/petget_proc/petget/current-repo-triad
  46.    if [ -f /tmp/petget_proc/install_quietly ];then
  47.     if [  "$(grep $TREE1 /root/.packages/user-installed-packages 2>/dev/null)" = "" \
  48.      -a -f /tmp/petget_proc/install_pets_quietly ]; then
  49.      if [ "$(cat /var/local/petget/nt_category 2>/dev/null)" = "true" ]; then
  50.       /usr/local/petget/installpreview.sh
  51.      else
  52.       rxvt -title "$VTTITLE... $(gettext 'Do NOT close')" \
  53.       -fn -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-* -bg black \
  54.       -fg grey -geometry 80x5+50+50 -e /usr/local/petget/installpreview.sh
  55.      fi
  56.     else
  57.      if [ "$(cat /var/local/petget/nt_category 2>/dev/null)" = "true" ]; then
  58.       /usr/local/petget/installpreview.sh
  59.      else
  60.       rxvt -title "$VTTITLE... $(gettext 'Do NOT close')" \
  61.       -fn -misc-fixed-medium-r-semicondensed--13-120-75-75-c-60-*-* -bg black \
  62.       -fg grey -geometry 80x5+50+50 -e /usr/local/petget/installpreview.sh
  63.      fi
  64.     fi
  65.    else
  66.    
  67.     /usr/local/petget/installpreview.sh
  68.     if [ $? -eq 100 ] ; then
  69.        exit
  70.     fi
  71.    fi
  72.    /usr/local/petget/finduserinstalledpkgs.sh #s243a: is this necessary?
  73.    
  74.    sed -i "/$TREE1/d" /tmp/petget_proc/pkgs_left_to_install
  75.  done < /tmp/petget_proc/pkgs_to_install
  76.  sync
  77.  report_results
  78.  clean_up
  79. }
  80. [ "$EXPORT_FNs" = true ] && export -f install_package
  81.  
  82. do_install() {
  83.     # Exit if called spuriously
  84.     [ "$TREE1" = "" ] && exit 0
  85.     export ENTRY=$TREE1
  86.     pkg_info
  87.     #pkg_info="$(cat /tmp/petget_proc/pkgs_to_install | cut -d '|' -f1,4)"
  88.     #pkgs_to_install set in the pkg_info function
  89.     echo "pkgs_to_install=$(cat /tmp/petget_proc/pkgs_to_install)"
  90.     mv /tmp/petget_proc/pkgs_to_install /tmp/petget_proc/pkgs_to_install_1_5_10_11
  91.     cat /tmp/petget_proc/pkgs_to_install_1_5_10_11 | cut -d '|' -f1,4 > /tmp/petget_proc/pkgs_to_install
  92.     echo "pkgs_to_install=$(cat /tmp/petget_proc/pkgs_to_install)"
  93.     #-- Make sure that we have atleast one mode flag
  94.     if [ ! -f /tmp/petget_proc/install_pets_quietly \
  95.       -a ! -f /tmp/petget_proc/download_only_pet_quietly \
  96.       -a ! -f /tmp/petget_proc/download_pets_quietly \
  97.       -a ! -f /tmp/petget_proc/install_classic ] ; then
  98.         touch /tmp/petget_proc/install_classic #/tmp/petget_proc/install_pets_quietly
  99.     fi
  100.     #if [ "$(grep $TREE1 /root/.packages/user-installed-packages)" != "" ] ; then
  101.     #   . /usr/lib/gtkdialog/box_yesno "$(gettext 'Package is already installed')" "$(gettext 'This package is already installed! ')" "$(gettext 'If you want to re-install it, first remove it and then install it again. To download only or use the step-by-step classic mode, select No and then change the Auto Install to another option.')" "$(gettext 'To Abort the process now select Yes.')"
  102.     #   if [ "$EXIT" = "yes" ]; then
  103.     #       exit 0
  104.     #   else
  105.     #       echo $TREE1 > /tmp/petget_proc/forced_install
  106.     #   fi
  107.     #fi
  108.     #--
  109.     if [ "$(cat /tmp/petget_proc/forced_install 2>/dev/null)" != "" ]; then
  110.         touch /tmp/petget_proc/force_install
  111.     else
  112.         rm -f /tmp/petget_proc/force_install
  113.     fi
  114.     #cut -d"|" -f1,4 /tmp/petget_proc/pkgs_to_install > /tmp/petget_proc/pkgs_to_install_tmp
  115.     #mv -f /tmp/petget_proc/pkgs_to_install_tmp /tmp/petget_proc/pkgs_to_install
  116.     #if ! [ -f /tmp/petget_proc/force_install -a -f /tmp/petget_proc/install_pets_quietly ]; then
  117.         #/usr/local/petget/installed_size_preview.sh "$NEWPACKAGE" ADD
  118.         if [ "$USE_installmodes_sh" != false ]; then
  119.           /usr/local/petget/installmodes.sh "$INSTALL_MODE"
  120.         elif [ "$SKIP_installmodes_sh" != false ]; then
  121.           install_package #This was taken from installmodes.sh
  122.         else
  123.          
  124.          
  125.           cat /tmp/petget_proc/pkgs_to_install | tr ' ' '\n' > /tmp/petget_proc/pkgs_left_to_install
  126.           mv /tmp/petget_proc/pkgs_to_install /tmp/petget_proc/pkgs_to_install_1_5
  127.           cat /tmp/petget_proc/pkgs_to_install_1_5 | cut -d '|' -f1 > /tmp/petget_proc/pkgs_to_install
  128.           echo "pkgs_to_install=$(cat /tmp/petget_proc/pkgs_to_install)"
  129.          
  130.           export TREE1=${TREE1%%|*}  
  131.           #rm /tmp/petget_proc/install_quietly
  132.           set +x
  133.           echo "/usr/local/petget/installpreview.sh"  
  134.           /usr/local/petget/installpreview.sh
  135.         fi
  136. }
  137.  
  138. echo_pkg_info_fields_helper(){
  139.   [ $# -gt 0 ] && TREE1=$1
  140.   [ $# -gt 1 ] && TREE1="$TREE1|$2"
  141.   local repo_triad
  142.   local result
  143.   if [ -f /tmp/petget_proc/petget/filterpkgs.results.post ]; then
  144.     result="$(grep ^$TREE1 /tmp/petget_proc/petget/filterpkgs.results.post)"
  145.   fi
  146.   if [ -z $result ]; then
  147.     pkg=$(echo $TREE1 | cut -f1 -d '|' )
  148.     #repo_triad=$(echo $TREE1 | cut -f2 -d)
  149.     n_fields=$(echo "$TREE1" | awk -F "|" '{print NF}' | head -n 1)
  150.     if [ $n_fields -gt 1 ]; then
  151.       repo_triad=$(echo "$TREE1" | awk -F "|" '{print $NF}' | head -n 1)
  152.     elif [ -f /tmp/petget_proc/petget ]; then
  153.       repo_triad=$(cat /tmp/petget_proc/petget | head -n 1)
  154.     fi
  155.     result="$(grep -m1 ^$pkg /var/packages/Packages-$repo_triad | cut -f1,5,10,11)"
  156.   fi
  157.   echo "$result"
  158. }
  159. echo_pkg_info_fields(){
  160.     echo_pkg_info_fields_helper
  161.     #TODO maybe look at all repos specified by the ppm or fallback repos.
  162. }
  163. #Taken from: https://github.com/puppylinux-woof-CE/woof-CE/blob/60d94862a3343bf0a062a0fcd0dd73475d6985ba/woof-code/rootfs-skeleton/usr/local/petget/pkg_chooser.sh#L120
  164. # but modified to not depend on filterpkgs.results.post
  165. pkg_info() {
  166.     # Exit if called spuriously
  167.     [ "$TREE1" = "" ] && exit 0
  168.     #NEWPACKAGE="$(grep ^$TREE1 /tmp/petget_proc/petget/filterpkgs.results.post)"
  169.     pkg=$(echo $TREE1 | cut -f1 -d '|' )
  170.     export ENTRY1=$pkg #used in findnames.sh
  171.     /usr/local/petget/findnames.sh  #We can remove this if we generage filterpkgs.results.post another way. See: postfilterpkgs.sh and installpreview.sh
  172.    # rm -f /tmp/petget_proc/overall_*
  173.     #/usr/local/petget/installed_size_preview.sh "$TREE1" ADD
  174.     #installpreview.sh
  175.     repo_triad=$(echo $TREE1 | cut -f2 -d '|' )
  176.     echo "$repo_triad" > /tmp/petget_proc/petget/current-repo-triad
  177.     IFS="|" read PKG_NAME PKG_CAT PKG_DESC PKG_REPO < <(echo_pkg_info_fields  )
  178.     (
  179.         echo "Name    : $PKG_NAME"
  180.         echo "Category: $PKG_CAT"
  181.         echo "Desc    : $PKG_DESC"
  182.         echo "Repo    : $repo_triad" #$PKG_REPO
  183.     ) > /tmp/petget_proc/petget/pgk_info
  184.     echo "$PKG_NAME|$PKG_CAT|$PKG_DESC|$repo_triad" >> /tmp/petget_proc/pkgs_to_install
  185. }
  186.  
  187. #Taken from: https://github.com/puppylinux-woof-CE/woof-CE/blob/60d94862a3343bf0a062a0fcd0dd73475d6985ba/woof-code/rootfs-skeleton/usr/local/petget/installmodes.sh#L12
  188. clean_up () {
  189.  if [ "$(ls /tmp/petget_proc/*_pet{,s}_quietly /tmp/petget_proc/install_classic 2>/dev/null |wc -l)" -eq 1 ]; then
  190.   for MODE in $(ls /tmp/petget_proc/*_pet{,s}_quietly /tmp/petget_proc/install_classic)
  191.   do
  192.    mv $MODE $MODE.bak
  193.   done
  194.  fi
  195.  mv /tmp/petget_proc/install_quietly /tmp/petget_proc/install_quietly.bak
  196.  echo -n > /tmp/petget_proc/pkgs_to_install
  197.  rm -f /tmp/petget_proc/{install,remove}{,_pets}_quietly 2>/dev/null
  198.  rm -f /tmp/petget_proc/install_classic 2>/dev/null
  199.  rm -f /tmp/petget_proc/download_pets_quietly 2>/dev/null
  200.  rm -f /tmp/petget_proc/download_only_pet_quietly 2>/dev/null
  201.  rm -f /tmp/petget_proc/pkgs_left_to_install 2>/dev/null
  202.  rm -f /tmp/petget_proc/pkgs_to_install_done 2>/dev/null
  203.  rm -f /tmp/petget_proc/overall_pkg_size* 2>/dev/null
  204.  rm -f /tmp/petget_proc/overall_dependencies 2>/dev/null
  205.  rm -f /tmp/petget_proc/mode_changed 2>/dev/null
  206.  rm -f /tmp/petget_proc/force*_install 2>/dev/null
  207.  rm -f /tmp/petget_proc/pkgs_to_install_done 2>/dev/null
  208.  rm -f /tmp/petget_proc/pgks_really_installed 2>/dev/null
  209.  rm -f /tmp/petget_proc/pgks_failed_to_install 2>/dev/null
  210.  rm -f /tmp/petget_proc/overall_petget_missingpkgs_patterns.txt 2>/dev/null
  211.  rm -f /tmp/petget_proc/overall_missing_libs.txt 2>/dev/null
  212.  rm -f /tmp/petget_proc/overall_install_report 2>/dev/null
  213.  rm -f /tmp/petget_proc/pkgs_to_install_bar 2>/dev/null
  214.  rm -f /tmp/petget_proc/manual_pkg_download 2>/dev/null
  215.  rm -f /tmp/petget_proc/ppm_reporting 2>/dev/null
  216.  rm -f /tmp/petget_proc/pkgs_DL_BAD_LIST 2>/dev/null
  217.  rm -rf /tmp/petget_proc/PPM_LOGs/ 2>/dev/null
  218.  mv $MODE.bak $MODE
  219.  mv /tmp/petget_proc/install_quietly.bak /tmp/petget_proc/install_quietly
  220. }
  221. [ "$EXPORT_FNs" = true ] && export -f clean_up
  222. report_results () {
  223.  # Info source files
  224.  touch /tmp/petget_proc/ppm_reporting # progress bar flag
  225.  /usr/local/petget/finduserinstalledpkgs.sh #make sure...
  226.  sync
  227.  rm -f /tmp/petget_proc/pgks_really_installed 2>/dev/null
  228.  rm -f /tmp/petget_proc/pgks_failed_to_install 2>/dev/null
  229.  for LINE in $(cat /tmp/petget_proc/pkgs_to_install_done  | cut -f 1 -d '|' | sort | uniq)
  230.  do
  231.   [ "$(echo $LINE)" = "" ] && continue
  232.   if [ -f /tmp/petget_proc/download_pets_quietly -o -f /tmp/petget_proc/download_only_pet_quietly \
  233.    -o -f /tmp/petget_proc/manual_pkg_download ];then
  234.    if [ -f /root/.packages/download_path ];then
  235.     . /root/.packages/download_path
  236.     DOWN_PATH="$DL_PATH"
  237.    else
  238.     DOWN_PATH=$HOME
  239.    fi
  240.    PREVINST=''
  241.    REALLY=$(ls "$DOWN_PATH" | grep $LINE)
  242.    [ "$REALLY" -a "$(grep $LINE /tmp/petget_proc/pkgs_DL_BAD_LIST 2>/dev/null | sort | uniq )" != "" ] && \
  243.     REALLY='' && PREVINST="$(gettext 'was previously downloaded')"
  244.   else
  245.    PREVINST=''
  246.    REALLY=$(grep $LINE /tmp/petget_proc/petget/installedpkgs.results)
  247.    [ "$(grep $LINE /tmp/petget_proc/pgks_failed_to_install_forced 2>/dev/null | sort | uniq )" != "" -o \
  248.     "$(grep $LINE /tmp/petget_proc/pkgs_DL_BAD_LIST 2>/dev/null | sort | uniq )" != "" ] \
  249.     && REALLY='' && PREVINST="$(gettext 'was already installed')"
  250.   fi
  251.   if [ "$REALLY" != "" ]; then
  252.    echo $LINE >> /tmp/petget_proc/pgks_really_installed
  253.   else
  254.    echo $LINE $PREVINST >> /tmp/petget_proc/pgks_failed_to_install
  255.   fi
  256.  done
  257.  rm -f /tmp/petget_proc/pgks_failed_to_install_forced
  258.  
  259.  [ -f /tmp/petget_proc/pgks_really_installed ] && INSTALLED_PGKS="$(</tmp/petget_proc/pgks_really_installed)" \
  260.   || INSTALLED_PGKS=''
  261.  [ -f /tmp/petget_proc/pgks_failed_to_install ] && FAILED_TO_INSTALL="$(</tmp/petget_proc/pgks_failed_to_install)" \
  262.   || FAILED_TO_INSTALL=''
  263.  #MISSING_PKGS=$(cat /tmp/petget_proc/overall_petget_missingpkgs_patterns.txt |sort|uniq )
  264.  MISSING_LIBS=$(cat /tmp/petget_proc/overall_missing_libs.txt 2>/dev/null | tr ' ' '\n' | sort | uniq )
  265.  NOT_IN_PATH_LIBS=$(cat /tmp/petget_proc/overall_missing_libs_hidden.txt 2>/dev/null | tr ' ' '\n' | sort | uniq )
  266.  cat << EOF > /tmp/petget_proc/overall_install_report
  267. Packages succesfully Installed or Downloaded
  268. $INSTALLED_PGKS
  269.  
  270. Packages that failed to be Installed or Downloaded, or were aborted be the user
  271. $FAILED_TO_INSTALL
  272.  
  273. Missing Shared Libraries
  274. $MISSING_LIBS
  275.  
  276. Existing Libraries that may be in a location other than /lib and /usr/lib
  277. $NOT_IN_PATH_LIBS
  278. EOF
  279.  
  280.  # Info window/dialogue (display and option to save "missing" info)
  281.  if [ "$MISSING_LIBS" ];then
  282.   MISSINGMSG1="<i><b>$(gettext 'These libraries are missing:')
  283. ${MISSING_LIBS}</b></i>"
  284.   LM='  <hbox space-expand="true" space-fill="true">
  285.    <hbox scrollable="true" hscrollbar-policy="2" vscrollbar-policy="2" space-expand="true" space-fill="true">
  286.      <hbox space-expand="false" space-fill="false">
  287.        <eventbox name="bg_report" space-expand="true" space-fill="true">
  288.          <vbox margin="5" hscrollbar-policy="2" vscrollbar-policy="2" space-expand="true" space-fill="true">
  289.            '"`/usr/lib/gtkdialog/xml_pixmap building_block.svg 32`"'
  290.            <text angle="90" wrap="false" yalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"<big><b><span color='"'#bbb'"'>'$(gettext 'Libs')'</span></b></big> "</label></text>
  291.          </vbox>
  292.        </eventbox>
  293.      </hbox>
  294.      <vbox scrollable="true" shadow-type="0" hscrollbar-policy="1" vscrollbar-policy="1" space-expand="true" space-fill="true">
  295.        <text ypad="5" xpad="5" yalign="0" xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"'${MISSINGMSG1}'"</label></text>
  296.      </vbox>
  297.    </hbox>
  298.  </hbox>'
  299.  fi
  300.  if [ "$NOT_IN_PATH_LIBS" ];then #100830
  301.   MISSINGMSG1="<i><b>${MISSINGMSG1}</b></i>
  302.  
  303. $(gettext 'These needed libraries exist but are not in the library search path (it is assumed that a startup script in the package makes these libraries loadable by the application):')
  304. <i><b>${NOT_IN_PATH_LIBS}</b></i>"
  305.  fi
  306.  
  307.  if [ -s /tmp/petget_proc/petget-installed-pkgs-log ];then
  308.   BUTTON_TRIM="<button><input file stock=\"gtk-execute\"></input><label>$(gettext 'Trim the fat')</label><action type=\"exit\">BUTTON_TRIM_FAT</action></button>"
  309.  fi
  310.  
  311.  export REPORT_DIALOG='
  312. <window title="'$(gettext 'Package Manager')'" icon-name="gtk-about" default_height="550">
  313. <vbox>
  314.  '"`/usr/lib/gtkdialog/xml_info fixed package_add.svg 60 " " "$(gettext "Package install/download report")"`"'
  315.  <hbox space-expand="true" space-fill="true">
  316.    <hbox scrollable="true" hscrollbar-policy="2" vscrollbar-policy="2" space-expand="true" space-fill="true">
  317.      <hbox space-expand="false" space-fill="false">
  318.        <eventbox name="bg_report" space-expand="true" space-fill="true">
  319.          <vbox margin="5" hscrollbar-policy="2" vscrollbar-policy="2" space-expand="true" space-fill="true">
  320.            '"`/usr/lib/gtkdialog/xml_pixmap dialog-complete.svg 32`"'
  321.            <text angle="90" wrap="false" yalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"<big><b><span color='"'#15BC15'"'>'$(gettext 'Success')'</span></b></big> "</label></text>
  322.          </vbox>
  323.        </eventbox>
  324.      </hbox>
  325.      <vbox scrollable="true" shadow-type="0" hscrollbar-policy="2" vscrollbar-policy="1" space-expand="true" space-fill="true">
  326.        <text ypad="5" xpad="5" yalign="0" xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"<i><b>'${INSTALLED_PGKS}' </b></i>"</label></text>
  327.      </vbox>
  328.    </hbox>
  329.  </hbox>
  330.  
  331.  <hbox space-expand="true" space-fill="true">
  332.    <hbox scrollable="true" hscrollbar-policy="2" vscrollbar-policy="2" space-expand="true" space-fill="true">
  333.      <hbox space-expand="false" space-fill="false">
  334.        <eventbox name="bg_report" space-expand="true" space-fill="true">
  335.          <vbox margin="5" hscrollbar-policy="2" vscrollbar-policy="2" space-expand="true" space-fill="true">
  336.            '"`/usr/lib/gtkdialog/xml_pixmap dialog-error.svg 32`"'
  337.            <text angle="90" wrap="false" yalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"<big><b><span color='"'#DB1B1B'"'>'$(gettext 'Failed')'</span></b></big> "</label></text>
  338.          </vbox>
  339.        </eventbox>
  340.      </hbox>
  341.      <vbox scrollable="true" shadow-type="0" hscrollbar-policy="2" vscrollbar-policy="1" space-expand="true" space-fill="true">
  342.        <text ypad="5" xpad="5" yalign="0" xalign="0" use-markup="true" space-expand="true" space-fill="true"><label>"<i><b>'${FAILED_TO_INSTALL}' </b></i>"</label></text>
  343.      </vbox>
  344.    </hbox>
  345.  </hbox>
  346.  
  347.  '${LM}'
  348.  
  349.  <hbox space-expand="false" space-fill="false">
  350.     <button ok></button>
  351.     <button>
  352.      <label>'$(gettext 'View details')'</label>
  353.      <input file stock="gtk-dialog-info"></input>
  354.      <action>defaulttextviewer /tmp/petget_proc/overall_install_report &</action>
  355.     </button>
  356.     '${BUTTON_TRIM}'
  357.     '"`/usr/lib/gtkdialog/xml_scalegrip`"'
  358.  </hbox>
  359. </vbox>
  360. </window>'
  361.  RETPARAMS="`gtkdialog --center -p REPORT_DIALOG`"
  362.  eval "$RETPARAMS"
  363.  echo 100 > /tmp/petget_proc/petget/install_status_percent
  364.  
  365.   #trim the fat...
  366.  if [ "$EXIT" = "BUTTON_TRIM_FAT" ];then
  367.   INSTALLEDPKGNAMES="`cat /tmp/petget_proc/petget-installed-pkgs-log | cut -f 2 -d ' ' | tr '\n' ' '`"
  368.   #101013 improvement suggested by L18L...
  369.   CURRLOCALES="`locale -a | grep _ | cut -d '_' -f 1`"
  370.   LISTLOCALES="`echo -e -n "en\n${CURRLOCALES}" | sort -u | tr -s '\n' | tr '\n' ',' | sed -e 's%,$%%'`"
  371.   export PPM_TRIM_DIALOG="<window title=\"$(gettext 'Puppy Package Manager')\" icon-name=\"gtk-about\" resizable=\"false\">
  372.  <vbox>
  373.   <pixmap><input file>/usr/share/pixmaps/puppy/dialog-question.svg</input></pixmap>
  374.   <text><label>$(gettext "You have chosen to 'trim the fat' of these installed packages:")</label></text>
  375.   <text use-markup=\"true\"><label>\"<b>${INSTALLEDPKGNAMES}</b>\"</label></text>
  376.   <frame Locale>
  377.   <text><label>$(gettext 'Type the 2-letter country designations for the locales that you want to retain, separated by commas. Leave blank to retain all locale files (see /usr/share/locale for examples):')</label></text>
  378.   <entry><default>${LISTLOCALES}</default><variable>ENTRY_LOCALE</variable></entry>
  379.   </frame>
  380.   <frame $(gettext 'Documentation')>
  381.   <checkbox><default>true</default><label>$(gettext 'Tick this to delete documentation files')</label><variable>CHECK_DOCDEL</variable></checkbox>
  382.   </frame>
  383.   <frame $(gettext 'Development')>
  384.   <checkbox><default>true</default><label>$(gettext 'Tick this to delete development files')</label><variable>CHECK_DEVDEL</variable></checkbox>
  385.   <text><label>$(gettext '(only needed if these packages are required as dependencies when compiling another package from source code)')</label></text>
  386.   </frame>
  387.   <text><label>$(gettext "Click 'OK', or if you decide to chicken-out click 'Cancel':")</label></text>
  388.   <hbox>
  389.    <button ok></button>
  390.    <button cancel></button>
  391.   </hbox>
  392.  </vbox>
  393.  </window>"
  394.   RETPARAMS="`gtkdialog -p PPM_TRIM_DIALOG`"
  395.   eval "$RETPARAMS"
  396.   [ "$EXIT" != "OK" ] && exit $EXITVAL
  397.   if [ ! -f /tmp/petget_proc/install_quietly ]; then
  398.    /usr/lib/gtkdialog/box_splash -text "$(gettext 'Please wait, trimming fat from packages...')" &
  399.    X4PID=$!
  400.   fi
  401.   elPATTERN="`echo -n "$ENTRY_LOCALE" | tr ',' '\n' | sed -e 's%^%/%' -e 's%$%/%' | tr '\n' '|'`"
  402.   for PKGNAME in $INSTALLEDPKGNAMES
  403.   do
  404.    (
  405.    cat /root/.packages/${PKGNAME}.files |
  406.    while read ONEFILE
  407.    do
  408.     [ ! -f "$ONEFILE" ] && echo "$ONEFILE" && continue
  409.     [ -h "$ONEFILE" ] && echo "$ONEFILE" && continue
  410.     #find out if this is an international language file...
  411.     if [ "$ENTRY_LOCALE" != "" ];then
  412.      if [ "`echo -n "$ONEFILE" | grep --extended-regexp '/locale/|/nls/|/i18n/' | grep -v -E "$elPATTERN"`" != "" ];then
  413.       rm -f "$ONEFILE"
  414.       continue
  415.      fi
  416.     fi
  417.     #find out if this is a documentation file...
  418.     if [ "$CHECK_DOCDEL" = "true" ];then
  419.      if [ "`echo -n "$ONEFILE" | grep --extended-regexp '/man/|/doc/|/doc-base/|/docs/|/info/|/gtk-doc/|/faq/|/manual/|/examples/|/help/|/htdocs/'`" != "" ];then
  420.       rm -f "$ONEFILE" 2>/dev/null
  421.       continue
  422.      fi
  423.     fi
  424.     #find out if this is development file...
  425.     if [ "$CHECK_DEVDEL" = "true" ];then
  426.      if [ "`echo -n "$ONEFILE" | grep --extended-regexp '/include/|/pkgconfig/|/aclocal|/cvs/|/svn/'`" != "" ];then
  427.       rm -f "$ONEFILE" 2>/dev/null
  428.       continue
  429.      fi
  430.      #all .a and .la files... and any stray .m4 files...
  431.      if [ "`echo -n "$ONEBASE" | grep --extended-regexp '\.a$|\.la$|\.m4$'`" != "" ];then
  432.       rm -f "$ONEFILE"
  433.       continue
  434.      fi
  435.     fi
  436.     echo "$ONEFILE"
  437.    done
  438.    ) > /tmp/petget_proc/petget_pkgfiles_temp
  439.    mv -f /tmp/petget_proc/petget_pkgfiles_temp /root/.packages/${PKGNAME}.files
  440.   done
  441.   [ "$X4PID" ] && kill $X4PID
  442.  fi
  443. }
  444. [ "$EXPORT_FNs" = true ] && export -f report_results
  445. function split_on_so(){
  446.   local str=$1
  447.   local len=${#str}
  448.   local len_m=$((len-1))
  449.   local index
  450.   local s1
  451.   local s2
  452.   local p1
  453.   local p2
  454.   #Some notes here in case there is a compelling reasone to use PCRE (Perl compatible regular expressions)
  455.   #if type perl; then
  456.   #   read -d '\n' s1 s2 < <(perl -pe 's/(^(?:(?![.]so[.]?).)+)(?:([.]so[.]?)(.*))?$/\1\n\3/')
  457.   #else
  458.     #ind=$(expr index $str .so)
  459.     len=${#str}    
  460.     s1=${str%%.so*}
  461.     p1=${#s1}
  462.     #[ $ind -eq 0 ] && ind=$len
  463.     #p1=$((ind-1))
  464.     #s1=${str:0:$p1}
  465.     if [ $p1 -lt $len ]; then
  466.       p2=$((p1+3))
  467.       if [ "${str:$p2:1}" = '.' ]; then
  468.         p2=$((p2+1))
  469.       fi
  470.     else
  471.       p2=len
  472.     fi
  473.     s2=${str:$p2}
  474.   #fi
  475.   echo "$s1"
  476.   echo "$s2"
  477. }
  478. function link_lib(){
  479.   local lib_spec="$1"
  480.   local needed_lib="$(echo "$lib_spec" | cut -f1 -d '|' | sed -e 's/^[+]//')"
  481.   local ONEFILE="$(echo "$lib_spec|" | cut -f2 -d '|')" #this is the executable which needs the lib
  482.   local pkg_specs="$2" #e.g. /var/packages/re2-1:20200303.files:14:/usr/lib/libre2.so.6.0.0
  483.                        #Lib name follows last colon. Package list path is beforefirst colon.
  484.   local needed_lib_base="$(echo "$needed_lib" | sed -e 's/[.]so.*$/.so/')"
  485.   local needed_ver="$(echo "$lib_specs" | sed -e 's/^.*[.]so//' -e 's/^[.]//')"
  486.   [ -z "needed_ver" ] && needed_ver='0'
  487.   pkg_specs="$(grep -rn /var/packages -e "$needed_lib_base" | grep .files)"
  488.   echo $pkg_specs | \
  489.     while read a_pkg_spec; do
  490.      
  491.       lib_to_link="$(echo "$a_pkg_spec" | sed -e 's/.*[.]files:\([0-9]*[:]\)\?//')"
  492.      
  493.       lib_fm_pkg="$(echo "$lib_to_link_base" | sed -e 's%.*/\([^/]*\)[.]files.*%\1%g')"
  494.       needed_lib_path="/usr/lib/$needed_lib"
  495.       [ ! -z "$needed_ver" ] && needed_lib_path="${needed_lib_path}.${needed_ver}"
  496.      
  497.       if [ ! -e "$needed_lib_path" ]; then
  498.         ldconfig #We probably don't need ldconfig if we link to somewhere in LD LIBRARY_PATH
  499.         #so maybe don't do a ldconfig here because it is slow.
  500.         if [ ! -z "$ONEFILE" ]; then
  501.           ln -s "$lib_to_link" "$needed_lib_path"
  502.           if [ ! -z "$(ldd "$ONEFILE" | grep "$needed_lib" | grep "not found")" ]; then
  503.             rm "$needed_lib_path"
  504.           else
  505.             break
  506.           fi
  507.         else
  508.             provided_lib0="$(cat /var/packages/Provides-* | grep ^"$lib_fm_pkg" | cut -f5 -d '|' sed 's/.\('$needed_lib'[^,|$]*\)/\1/g')"
  509.               provided_ver_range="$(echo "$provided_lib0" | sed -e 's/^.*[.]so[=]//')"
  510.               if [ ! -z "$ver_range" ]; then
  511.                 local provided_min_ver="$(echo "$ver_range" | cut -f1 -d '-')"
  512.                 local provided_max_ver="$(echo "$ver_range" | cut -f2 -d '-')"
  513.                 p_min_ver_ary=(${provided_min_ver//./})
  514.                 p_max_ver_ary=(${provided_max_ver//./})
  515.                 needed_ver_ary=(${needed_ver//./})
  516.                 i=0
  517.                 while [ $i -lt ${#needed_ver_ary[@]} ]; do
  518.                   if [ $i -lt ${#p_min_ver_ary[@]} ]; then
  519.                     [ ${p_min_ver_ary[$i]} -gt ${needed_ver[$i]} ] && break
  520.                     [ ${p_max_ver_ary[$i]} -lt ${needed_ver[$i]} ] && break
  521.                     [ ${needed_ver[$i]} -gt ${p_min_ver_ary[$i]} ] && \
  522.                       ln -s "$lib_to_link" "$needed_lib_path" && break 2
  523.                   else
  524.                     ln -s "$lib_to_link" "$needed_lib_path" && break 2
  525.                   fi
  526.                   i=$((i+1))
  527.                 done
  528.               else  
  529.                 ln -s "$lib_to_link" "$needed_lib_path" && break
  530.               fi          
  531.                
  532.           break
  533.         fi
  534.       fi
  535.     done
  536.   #if [ -z "$pkg_spec" ]; then
  537.   #  pkg_specs="$(cat /var/packages/user-installed-packages /var/packages/woof-installed-packages | \
  538.   #               grep "$need_lib")"
  539.                  
  540.    
  541. }
  542. while read a_lib; do
  543.   while read packages_db; do
  544.         REPO_TRIAD=$(basename $packages_db)
  545.         REPO_TRIAD=${REPO_TRIAD#Packages-} #todo MAYBE MAKE THIS MORE ROBUST  
  546.     for mode in 1 2 3; do  
  547.    
  548.       case "$mode" in
  549.       1)
  550.         provides_db="$(echo "$packages_db" | sed 's/^Packages-/^Provides-/')"
  551.         a_lib_base="$(echo "$a_lib" | sed -r 's/^(.*)([.]so)(.*)$/\1\2/')"
  552.         matches="$(cut -f1,5 -d '|' "$provides_db" | grep -F $a_lib_base )"
  553.         if [ ! -z "$matches" ]; then
  554.           a_pkg="$(echo "$matches" | cut -f1 -d '|')"
  555.           if [ -f /var/packages/$a_pkg.files ]; then
  556.             link_lib $a_lib "$(grep -rn "/var/packages/$a_pkg.files" -e "$a_lib")"
  557.             unset matches
  558.             break 2
  559.           else
  560.             break
  561.           fi
  562.         fi
  563.        
  564.         ;;
  565.         2)
  566.           link_lib $a_lib
  567.           ;;
  568.       3)
  569.         pre_guess=$a_lib
  570.         while [ 1 -eq 1 ]; do
  571.           #guess="$(echo "$pre_guess" | sed 's/[.]so[.]/-/')"
  572.           #guess="$(echo "$pre_guess" | sed 's/[.]so//')"
  573.           #read -d '\n' s1 s2 < <(echo "$pre_guess" | sed 's%([[.]so)*([.]so[.]\?\|)\?%\1\n\3%')
  574.           read -d '\n' s1 s2 < <(split_on_so "$pre_guess")
  575.           s1="$(echo $s1 | sed 's%\(.*[^0-9]\)\([.]\|[-]\|[_]\)\([0-9]*\)$%\1\\([.]\\|[-]\\|[_]\\)\\?\3%')"
  576.           if [ ${#s2} -gt 0 ]; then
  577.             s2="$(echo $s2 | sed 's%\([.]\|[-]\|[_]\)%\\([.]\\|[-]\\|[_]\\)%')"
  578.            
  579.             lp=${#s2}; lp=$((lp-1))
  580.             if [[ ${s1:$lp} =~ [0-9] ]]; then
  581.               ptrn="$s1"'\([.]\|[-]\|[_]\)'"$s2"
  582.             else
  583.               ptrn="$s1"'\([.]\|[-]\|[_]\)\?'"$s2"
  584.             fi
  585.           else
  586.             ptrn="$s1"
  587.           fi
  588.  
  589.           aliases="$(echo "$PKG_NAME_ALIASES" | sed 's/\([^.]\|^\)\(*\)/\1.*/' | tr " " "\n" | tr "," " " | grep '\(^\|,\| \)'"${ptrn}"'\(^\|,\| \)' | tr "\n" " ")"
  590.           aliases="$ptrn $aliases"
  591.           #for mode in 1 2 3 4; do
  592.             for a_alias in $aliases; do
  593.  
  594.                 matches="$(cut -f1,2 -d '|' $packages_db | grep "|${a_alias}$")"
  595.                 matches="$(echo "$matches" | grep -v "$(cut -f1,2 -d '|' /var/packages/user-installed-packages)" | \ grep -v "$(cut -f1,2 -d '|' /var/packages/woof-installed-packages)" | cut f1 -d '|' )"
  596.                [ ! -z $matches ] && break 4
  597.  
  598.                matches="$(cut -f1 -d '|' $packages_db | grep "^${a_alias}")"
  599.                matches="$(echo "$matches" | grep -v "$(cut -f1 -d '|' /var/packages/user-installed-packages)" | \
  600.                  grep -v "$(cut -f1 -d '|' /var/packages/woof-installed-packages)" )"
  601.                [ ! -z $matches ] && break 4                
  602.              
  603.              ptrn2="${a_alias#lib}"
  604.              if [ "$a_alias" != "$ptrn2" ]; then
  605.                matches="$(cut -f1 -d '|' $packages_db | grep "^${ptrn2}")"
  606.                matches="$(echo "$matches" | grep -v "$(cut -f1 -d '|' /var/packages/user-installed-packages)" | \
  607.                  grep -v "$(cut -f1 -d '|' /var/packages/woof-installed-packages)" )"
  608.                [ ! -z $matches ] && break 4
  609.              fi
  610.            done
  611.          #done
  612.          
  613.          last_pre_guess="$pre_guess"
  614.          pre_guess="$(echo "$pre_guess" | sed -r 's/(.*)(.so)(.*)[.][^.]*/\1\2\3/')"
  615.          if [ "$pre_guess" = "$last_pre_guess" ]; then
  616.            pre_guess="$(echo "$pre_guess" | sed 's/[0-9]*$//')"
  617.            [ "$pre_guess" = "$last_pre_guess" ] && break          
  618.          fi
  619.  
  620.        done    
  621.        ;;
  622.      esac
  623.  
  624.    done
  625.  done < <(find /var/packages -name 'Packages-*')
  626.  if [ ! -z "$matches" ]; then
  627.     #pkgs_to_install_s243a is two fields like at: https://github.com/puppylinux-woof-CE/woof-CE/blob/60d94862a3343bf0a062a0fcd0dd73475d6985ba/woof-code/rootfs-skeleton/usr/local/petget/pkg_chooser.sh#L159
  628.     echo "$matches" | cut -d '|' -f1 | \
  629.       sed -n -E '/^[[:space:]]*$/! {s%(.*)%\1|'$REPO_TRIAD'%;p}'  >> /tmp/petget_proc/pkgs_to_install_s243a
  630.     break
  631.  fi  
  632. done < <(cat /tmp/petget_proc/missinglibs.txt | tr [[:space:]] "\n" )
  633.  
  634. while IFS= read line|| [ -n "$line" ];
  635. do    
  636.  export TREE1=$line
  637.  
  638.  #echo $TREE1 > /tmp/petget_proc/forced_install
  639.  do_install #Expects four fields
  640. done < /tmp/petget_proc/pkgs_to_install_s243a
  641.  
  642.  
  643. #export -f do_instal #pkg_info do_install change_mode
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top