Advertisement
Guest User

Untitled

a guest
Dec 6th, 2015
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 22.77 KB | None | 0 0
  1. #!/bin/sh
  2. #jlst 2014
  3.  
  4. case $0 in
  5.     /usr/sbin/pacman) aconfig='/zz/aconfig' ;;
  6.     /*)  aconfig=${0%/*}'/aconfig' ;; #full path
  7.     ./*) aconfig=${0%/*}'/aconfig' ;; #./
  8.     *) aconfig=./aconfig ;; #...
  9. esac
  10.  
  11. curdir=${PWD}
  12. cd ${aconfig%/*}
  13.  
  14. . $aconfig
  15. [ ! "$SETUPDIR" ] && SETUPDIR='.'
  16. export INSTALLED
  17. export SETUPDIR
  18.  
  19. #echo $INSTALLED; echo $SETUPDIR ; exit
  20.  
  21. function GeneratePecSpecsByName() {
  22.     file="$@"  
  23.     tarfile=${file##*/} #"$(basename "$file")"
  24.     rootname=${tarfile%.tar.*}
  25.     rootname=${rootname%.pet}
  26.    
  27.     pkgname=${rootname%%\-[0-9]*} #first match onwards: -X* where X is a number
  28.     if [ "$pkgname" = "$rootname" ] ; then
  29.         pkgname="${rootname%%\-*}" #the old way, easy way
  30.     fi
  31.     pkgversion="${rootname#${pkgname}\-}"
  32.     pkgversion="${pkgversion//-*}"
  33.  
  34.     specs="${rootname}|${pkgname}|${pkgversion}||BuildingBlock|K||${tarfile}||||||"
  35.     echo $specs
  36. }
  37.  
  38.  
  39.  
  40. function Builtin() {
  41.     pkg="$1"
  42.     case $pkg in
  43.         /*) echo -n ;;
  44.         *)  pkg=${SETUPDIR}/builtin_files/${pkg} ;;
  45.     esac
  46.     if [ -f "$pkg" ] ; then
  47.         echo $pkg #if pkg exists, return pkg name
  48.         return 0
  49.     else
  50.         #now try with woof-installed-packages      
  51.         return 1
  52.     fi 
  53. }
  54.  
  55. #Returns full list, can be used in a pipe or stored in a variable
  56. function BuiltinList() {
  57.     . ${SETUPDIR}/DISTRO_PKGS_SPECS
  58.     pkgs=$(echo "$PKGS_SPECS_TABLE" | \
  59.         sed -e '/^no|/d' -e 's/#.*//')
  60.     SFI=$IFS
  61.     IFS='|'
  62.     while read line; do
  63.         specsinfo=${line//||/|~|}
  64.         specsinfo=${specsinfo//||/|~|}
  65.         x=1
  66.         for field in $specsinfo ; do
  67.             [ "$field" = "~" ] && field=''
  68.             case $x in
  69.                 #1) yesno=${field}          ;;
  70.                 #2) genericpkgname=${field} ;;
  71.                 #3) pkgnames=${field}       ;;
  72.                 #4) splitup=${field}            ;;
  73.                 #5) repo=${field}           ;;
  74.                 2) echo ${field}    ;;
  75.                 3) [ "$field" ] && echo '   '${field//,/
  76.     }
  77.             esac
  78.             let x++
  79.         done
  80.     done <<< "$pkgs"
  81.     IFS=$SFI   
  82. }
  83.  
  84. function InstalledList() {
  85.     filez="$(cat ${SETUPDIR}/woof-installed-packages)"
  86.     SFI=$IFS
  87.     IFS='|'
  88.     (
  89.     while read line; do
  90.         pkginfo=${line//||/|~|}
  91.         pkginfo=${pkginfo//||/|~|}
  92.         x=1
  93.         for field in $pkginfo ; do
  94.             [ "$field" = "~" ] && field=''
  95.             case $x in
  96.                 #1) pkgname=${field}            ;;
  97.                 2) nameonly=${field}        ;;
  98.                 #3) version=${field}            ;;
  99.                 #4) pkgrelease=${field}     ;;
  100.                 #5) category=${field}       ;;
  101.                 #6) size=${field}           ;;
  102.                 #7) path=${field}           ;;
  103.                 #8) fullfilename=${field}   ;;
  104.                 #9) dependencies=${field}   ;;
  105.                 10) description=${field}    ;;
  106.                 #11) compileddistro=${field}    ;;
  107.                 #12) compiledrelease=${field};;
  108.                 #13) repo=${field}          ;;
  109.             esac
  110.             let x++
  111.         done
  112.         #first field must have 40 chars wide
  113.         length=${#nameonly}
  114.         echo -n ${nameonly}
  115.         for ((x=$length ; x<=40 ; x++ )) ; do echo -n ' ' ; done
  116.         echo $description
  117.     done <<< "$filez"
  118.     ) > builtin.installed.txt
  119.     IFS=$SFI
  120.     geany builtin.installed.txt &  
  121. }
  122.  
  123. function BuiltinFiles() {
  124.     pkg="$(Builtin $1)"
  125.     if [ "$pkg" ] ; then
  126.         x=0
  127.         while read line; do
  128.             case $line in
  129.                 /*) lastdir=$line ;;
  130.                 *)  
  131.                     let x++
  132.                     echo "${lastdir}/${line}"
  133.                     ;;
  134.             esac
  135.         done < $pkg
  136.         if [ $x -eq 0 ] ; then
  137.             cat "$pkg" 2>/dev/null
  138.         fi
  139.         return 0
  140.     else
  141.         return 1
  142.     fi
  143. }
  144.  
  145. function CheckFiles() {
  146.     files=$(BuiltinFiles $1)
  147.     while read file; do
  148.         [ ! "$file" ] && continue
  149.         echo -n "$file... "
  150.         if [ -e "$file" ] ; then
  151.             echo "ok"
  152.         else
  153.             echo "error"
  154.         fi
  155.     done <<< "$files"
  156. }
  157.  
  158. function Puppy2Info() {
  159.     local specs="$@"
  160.     pkginfo=${specs//||/|~|}
  161.     pkginfo=${pkginfo//||/|~|}
  162.     SFI=$IFS
  163.     IFS='|'
  164.     x=1
  165.     for field in $pkginfo ; do
  166.         [ "$field" = "~" ] && field=''
  167.         case $x in
  168.             #1) [ "$field" ] && echo pkgname=${field}       ;;
  169.             2) [ "$field" ] && echo nameonly=${field}       ;;
  170.             3) [ "$field" ] && echo version=${field}        ;;
  171.             4) [ "$field" ] && echo pkgrelease=${field}     ;;
  172.             5) [ "$field" ] && echo category=${field}       ;;
  173.             6) [ "$field" ] && echo size=${field}           ;;
  174.             7) [ "$field" ] && echo path=${field}           ;;
  175.             8) [ "$field" ] && echo fullfilename=${field}   ;;
  176.             9) [ "$field" ] && echo dependencies=${field}   ;;
  177.             10) [ "$field" ] && echo description=${field}   ;;
  178.             11) [ "$field" ] && echo compileddistro=${field};;
  179.             12) [ "$field" ] && echo compiledrelease=${field};;
  180.             13) [ "$field" ] && echo repo=${field}          ;;
  181.         esac
  182.         let x++
  183.     done
  184.     IFS=$SFI   
  185. }
  186.  
  187. function BuiltinSpecs() {
  188.     pkg="$(Builtin $1)"
  189.     if [ "$pkg" ] ; then
  190.         name=${pkg##*/}
  191.         grep -m 1 "|${name}|" ${SETUPDIR}/woof-installed-packages
  192.         return 0
  193.     else
  194.         return 1
  195.     fi
  196. }
  197.  
  198. function BuiltinSpecs2() {
  199.     pkg="$(Builtin $1)"
  200.     if [ "$pkg" ] ; then
  201.         name=${pkg##*/}
  202.         grep "|${name}|" ${SETUPDIR}/woof-installed-packages ${SETUPDIR}/DISTRO_PKGS_SPECS
  203.         #grep "|${name}|" ${SETUPDIR}/DISTRO_PKGS_SPECS
  204.         return 0
  205.     else
  206.         return 1
  207.     fi 
  208. }
  209.  
  210. function BuiltinExport() {
  211.     BuiltinSpecs="$(BuiltinSpecs $1)"
  212.     if [ "$BuiltinSpecs" ] ; then
  213.         pkgdir=${BuiltinSpecs%%|*}
  214.         #echo $pkgdir
  215.         mkdir -p $pkgdir
  216.         echo "$BuiltinSpecs" > ${pkgdir}/pet.specs
  217.         BuiltinFiles="$(BuiltinFiles $1)"
  218.         while read file ; do
  219.             if [ -f "$file" ] ; then
  220.                 filedir=${file%/*}
  221.                 targetdir=${pkgdir}${filedir}
  222.                 [ ! -d "$targetdir" ] && mkdir -p "$targetdir"
  223.                 cp -a -v --remove-destination "$file" "$targetdir"
  224.             fi
  225.         done <<< "$BuiltinFiles"
  226.         tar -zcf ${pkgdir}.tar.gz ${pkgdir}
  227.         rm -rf ${pkgdir}
  228.     else
  229.         echo "Error: '$1' pkg does not exist "
  230.         return 1
  231.     fi
  232. }
  233.  
  234. function BuiltinInfo() {
  235.     Puppy2Info "$(BuiltinSpecs $1)"
  236. }
  237.  
  238.  
  239. function PkgInfo() {
  240.     pkg="$1"
  241.     if [ -f ${SETUPDIR}/installedpkgs/${pkg} ] ; then
  242.         read -r specs < ${SETUPDIR}/installedpkgs/${pkg}
  243.         Puppy2Info "$specs"
  244.     else
  245.         specs=$(DistroSearch "|$pkg|")
  246.         if [ "$specs" ] ; then
  247.             echo "** NOT INSTALLED **"
  248.             Puppy2Info "$specs"
  249.         fi
  250.     fi
  251.    
  252. }
  253. function PkgDeps() {
  254.     pkg=$1
  255.     if [ -f ${SETUPDIR}/installedpkgs/${pkg} ] ; then
  256.         read -r specs < ${SETUPDIR}/installedpkgs/${pkg}
  257.     else
  258.         specs=$(DistroSearch "|$pkg|")
  259.         if [ "$specs" ] ; then
  260.             echo "** NOT INSTALLED **"
  261.         else
  262.             return 1
  263.         fi
  264.     fi
  265.     pkginfo=${specs//||/|~|}
  266.     pkginfo=${pkginfo//||/|~|}
  267.     SFI=$IFS ; IFS='|' ; x=1
  268.     for field in $pkginfo ; do
  269.         [ "$field" = "~" ] && field=''
  270.         case $x in 9) [ "$field" ] && dependencies=${field} && break ;; esac
  271.         let x++
  272.     done
  273.     IFS=$SFI
  274.     if [ "$dependencies" ] ; then
  275.         echo "$dependencies" | sed -e "s/\,/\n/g" | sed -e 's/^+//' -e 's/&.*//'
  276.     else
  277.         echo "* No dependencies specified..."
  278.     fi
  279. }
  280. function CheckDeps() {
  281.     (
  282.     PkgDeps $1 | while read dep ; do
  283.         if [ -f "${SETUPDIR}/installedpkgs/${dep}" ] ; then
  284.             echo "$dep ... ok"
  285.         elif [ -f "${SETUPDIR}/builtin_files/${dep}" ] ; then
  286.             echo "$dep ... ok (generic puppy pkg name)"
  287.         else
  288.             echo "$dep ... missing"
  289.         fi
  290.     done
  291.     ) | sort -u
  292. }
  293. function CheckDepsTree() {
  294.     pkg=$1
  295.     echo -n > packages.checked
  296.     echo -n > packages.tocheck
  297.     echo -n > packages.missing
  298.     echo -n > packages.log
  299.     while true ; do
  300.         echo "checking: $pkg"
  301.         echo "$pkg" >> packages.log
  302.         PkgDeps $pkg | while read dep ; do
  303.             echo $dep" >> packages.log
  304.             echo "$dep" >> packages.tocheck
  305.             if [ -f "${SETUPDIR}/installedpkgs/${dep}" ] ; then
  306.                 echo -n
  307.             elif [ -f "${SETUPDIR}/builtin_files/${dep}" ] ; then
  308.                 echo -n
  309.             else
  310.                 echo "$dep" >> packages.missing
  311.             fi
  312.         done
  313.         echo "$pkg" >> packages.checked
  314.         while true ; do
  315.             sed -i -e '/\*/d' packages.tocheck
  316.             pkg="$(sed -n '1p' packages.tocheck)"
  317.             #sed -i '1d' packages.tocheck
  318.             sed -i -e "/^${pkg}$/d" packages.tocheck
  319.             case "$pkg" in *\**) continue ;; esac
  320.             [ ! "$(grep "^${pkg}$" packages.checked)" ] && break
  321.         done
  322.         if [ ! "$pkg" ] ; then
  323.             break
  324.         fi
  325.     done
  326.     sort -u packages.missing | grep -v '\*' > packages.missing2
  327.     mv -f packages.missing2 packages.missing
  328.     sort -u packages.checked | grep -v '\*' > packages.checked2
  329.     mv -f packages.checked2 packages.checked
  330.     rm -f packages.tocheck
  331.     echo
  332.     echo "* These packages are not installed: "
  333.     while read line ; do echo '  '$line ; done < packages.missing
  334. }
  335.  
  336.  
  337.  
  338. function BuiltinRemoveSpecs() { #<pkg>
  339.     # Remove generic names only
  340.     # woof-installed-packages contains all the installed packages
  341.     # but won't be able to know what
  342.     # packages belong to a specific generic name, already removed...
  343.     local name=$1
  344.     sed -i "/|${name}|/d" ${SETUPDIR}/DISTRO_PKGS_SPECS
  345.     sed -i "/|${name}|/d" ${SETUPDIR}/woof-installed-packages
  346.     # This can be useful only to generate a new puppy in woof
  347. }
  348. function BuiltinRemoveFiles() { #<pkg>
  349.     pkg="$(Builtin $1)"
  350.     if [ "$pkg" ] ; then
  351.         while read line; do
  352.             case $line in
  353.                 /*) lastdir=$line ;;
  354.                 *)  rm -fv "${lastdir}/${line}" ;;
  355.             esac
  356.         done < $pkg
  357.         #name=${pkg##*/}
  358.         #BuiltinRemoveSpecs $name
  359.         rm -fv $pkg
  360.         return 0
  361.     else
  362.         echo "Error: '$1' pkg does not exist "
  363.         return 1
  364.     fi
  365. }
  366.  
  367. function FileBytes() {
  368.     echo "$(stat -c%s "$@")"
  369. }
  370. function FileKB() {
  371.     bytes="$(stat -c%s "$@")"
  372.     echo "$((bytes/1024))"'KB'
  373. }
  374.  
  375. ####################
  376. #################### Builtin Install
  377. ####################
  378.  
  379. #   This converts a file list to the format in /root/.packages/builtin_files/
  380. function TarFilelist2Builtin() {
  381.     while read file ; do
  382.         [[ $file == */ ]] && file=${file%/} #no trailing slash
  383.         if [ -f "$file" ] ; then
  384.             echo ' '${file##*/} #basename $file
  385.         else
  386.             echo $file
  387.         fi
  388.     done
  389. }
  390. function Pkg2Builtin() {
  391.     local file="$@"
  392.     [ ! "$file" ] && echo "* ERROR: no file provided..." && return 1
  393.     [ ! -f "$file" ] && echo "* ERROR: $file does not exist" && return 1
  394.     case "$file" in
  395.         *.tar.gz|*.pet) echo -n ;;
  396.         *) echo "* ERROR: Only *.tar.gz and *.pet allowed" && return 1
  397.     esac
  398.    
  399.     tarlist="-ztf"
  400.     tardecomp="-z -x --strip=1 -f"
  401.     filelist="$(tar $tarlist "$file" 2>/dev/null)" #; echo "$filelist"
  402.     tarfile=${file##*/} #"$(basename "$file")"
  403.     rootname=${tarfile%.tar.*}
  404.     rootname=${rootname%.pet}
  405.  
  406.     pkgname=${rootname%%\-[0-9]*} #first match onwards: -X* where X is a number
  407.     if [ "$pkgname" = "$rootname" ] ; then
  408.         pkgname="${rootname%%\-*}" #the old way, easy way
  409.     fi
  410.     pkgversion="${rootname#${pkgname}\-}"
  411.     pkgversion="${pkgversion//-*}"
  412.    
  413.     ## /root/.packages/builtin_files/ - only stores generic names, which can have many packages
  414.     #if [ -f /root/.packages/builtin_files/${pkgname} ] ; then
  415.     #   echo "* Pkg: '$pkgname' is already installed, replacing..."
  416.     #   sed -i -e "/|${pkgname}|/d" /root/.packages/woof-installed-packages
  417.     #fi
  418.    
  419.     ## This is the correct method...
  420.     #if [ "$(grep -m 1 "|${pkgname}|" /root/.packages/woof-installed-packages)" ] ; then
  421.     #   echo "* Pkg: '$pkgname' is already installed, replacing..."
  422.     #   PKGINSTALLED="TRUE"
  423.     #fi
  424.    
  425.     tar --directory="/" $tardecomp "$file"
  426.  
  427.     if [ -f /pet.specs ] ; then
  428.         read -r specs < /pet.specs
  429.         #specs="$(cat /pet.specs | head -1)"
  430.     else
  431.         specs="${rootname}|${pkgname}|${pkgversion}||BuildingBlock|K||${tarfile}||||||"
  432.     fi
  433.  
  434.     if [ "$PKGINSTALLED" ] ; then
  435.         sed -i -e "s/.*|${pkgname}|.*/${specs}/" /root/.packages/woof-installed-packages
  436.     else
  437.         echo "$specs" >> /root/.packages/woof-installed-packages
  438.     fi
  439.    
  440.     [ -f /pinstall.sh ] && sh /pinstall.sh
  441.     rm -f /pet.specs /pinstall.sh /puninstall.sh
  442.    
  443.     echo "$filelist" | \
  444.         sed -e "s%^${rootname}%%" | grep -v -E '^/$|pet.specs|pinstall.sh|puninstall.sh' | \
  445.             TarFilelist2Builtin > /root/.packages/builtin_files/${pkgname}
  446. }
  447.  
  448. #$woofdir - this must be exported by the calling script
  449. #"$@" - txt filelist
  450. function InstallPkgs2Woof() {
  451.     filez="$@"
  452.     [ ! -f "$filez" ] && echo "* ERROR: no file or invalid txt file..." && return 1
  453.    
  454.     if [ ! "$woofdir" ] ; then
  455.         echo '==============================================='
  456.         echo '[FATAL] You must export the variable $woofdir'
  457.         echo '  example: export woofdir="/initrd/mnt/dev_ro2/precise5.7.1retro"'
  458.         echo '==============================================='
  459.         return 1
  460.     fi
  461.    
  462.     cat "$filez" | sort -u | while read file; do
  463.         echo "* Processing: $file"
  464.         tarlist="-ztf"
  465.         tardecomp="-z -x --strip=1 -f"
  466.         filelist="$(tar $tarlist "$file" 2>/dev/null)" #; echo "$filelist"
  467.         tarfile=${file##*/} #"$(basename "$file")"
  468.         rootname=${tarfile%.tar.*}
  469.         rootname=${rootname%.pet}
  470.  
  471.         pkgname=${rootname%%\-[0-9]*} #first match onwards: -X* where X is a number
  472.         if [ "$pkgname" = "$rootname" ] ; then
  473.             pkgname="${rootname%%\-*}" #the old way, easy way
  474.         fi
  475.         pkgversion="${rootname#${pkgname}\-}"
  476.         pkgversion="${pkgversion//-*}"
  477.  
  478.         tar --directory=${woofdir} $tardecomp "$file"
  479.  
  480.         if [ -f "${woofdir}/pinstall.sh" ] ; then
  481.             sed -e '/^#\!\/bin/d' ${woofdir}/pinstall.sh >> ${woofdir}/pinstall.final
  482.         fi
  483.  
  484.         if [ -f ${woofdir}/pet.specs ] ; then
  485.             read -r specs < ${woofdir}/pet.specs
  486.         else
  487.             specs="${rootname}|${pkgname}|${pkgversion}||BuildingBlock|??K||${tarfile}||||||"
  488.         fi
  489.  
  490.         if [ "$PKGINSTALLED" ] ; then
  491.             sed -i -e "s/.*|${pkgname}|.*/${specs}/" ${woofdir}/root/.packages/woof-installed-packages
  492.         else
  493.             echo "$specs" >> ${woofdir}/root/.packages/woof-installed-packages
  494.         fi
  495.  
  496.         rm -f ${woofdir}/pinstall.sh ${woofdir}/puninstall.sh ${woofdir}/pet.specs
  497.        
  498.         echo "$filelist" | sort | \
  499.             sed -e "s%^${rootname}%%" | grep -v -E '^/$|pet.specs|pinstall.sh|puninstall.sh' | \
  500.                 while read zzfile ; do
  501.                     [[ $zzfile == */ ]] && zzfile=${zzfile%/} #no trailing slash
  502.                     if [ -f "${woofdir}/$zzfile" ] ; then
  503.                         echo ' '${zzfile##*/} #basename $zzfile
  504.                     else
  505.                         echo $zzfile
  506.                     fi
  507.                 done > ${woofdir}/root/.packages/builtin_files/${pkgname}
  508.         #-
  509.     done
  510.     chroot $woofdir sh pinstall.final  
  511. }
  512.  
  513.  
  514. #############################################
  515. #########        ZZNET STUFF        #########
  516. #############################################
  517.  
  518. scriptdir=${aconfig%/*}
  519. export netfile="${scriptdir}/woofnet.blacklist"
  520.  
  521. export WOOFFILES="${SETUPDIR}/Packages-puppy-4-official
  522. ${SETUPDIR}/Packages-puppy-5-official
  523. ${SETUPDIR}/Packages-puppy-common-official
  524. ${SETUPDIR}/Packages-puppy-noarch-official
  525. ${SETUPDIR}/Packages-puppy-precise-official
  526. ${SETUPDIR}/Packages-puppy-quirky-official
  527. ${SETUPDIR}/Packages-puppy-wary5-official
  528. ${SETUPDIR}/DISTRO_PKGS_SPECS"
  529.  
  530. #export WOOFFILES="${SETUPDIR}/DISTRO_PKGS_SPECS" #Testing...
  531.  
  532. function RemoveBuiltinFilesBL() {
  533.     #try both generic and global
  534.     REMOVEPKGS=$(grep -E '^GENERIC |^GLOBAL ' $netfile |
  535.     sed -e 's/^GENERIC //' \
  536.         -e 's/^GLOBAL //' \
  537.         -e '/^#/d' \
  538.         -e '/^$/d' \
  539.         -e 's/ .*//' \
  540.         -e "s/\t.*//" | sort -u)
  541.     for PKG in $REMOVEPKGS ; do
  542.         BuiltinRemoveFiles $PKG
  543.     done
  544.     echo
  545. }
  546.  
  547. function WoofRemoveGenericPkgs() {
  548.     echo "Now going to remove GENERIC matches"
  549.     echo "=================================="  
  550.     REMOVEPKGS=$(grep '^GENERIC ' $netfile |
  551.     sed -e 's/^GENERIC //' \
  552.         -e '/^#/d' \
  553.         -e '/^$/d' \
  554.         -e 's/ .*//' \
  555.         -e "s/\t.*//" | sort -u)
  556.     while read file ; do
  557.         tmpfile="${file}.2"
  558.         echo "* Fixing $file"
  559.         (
  560.         while read line ; do
  561.             found=0
  562.             for PKG in $REMOVEPKGS ; do
  563.                 [ ! "$PKG" ] && continue
  564.                 WPKG="*|${PKG}|*"
  565.                 [[ $line == $WPKG ]] && found=1 && break #ignore this line
  566.             done
  567.             [ $found -eq 0 ] && echo $line
  568.         done < "$file"
  569.         ) > $tmpfile
  570.         mv -f $tmpfile $file
  571.     done <<< "$WOOFFILES"
  572.     echo
  573. }
  574.  
  575. function WoofRemoveGlobalMatch() {
  576.     echo "Now going to remove GLOBAL matches"
  577.     echo "=================================="
  578.     REMOVEPKGS=$(grep '^GLOBAL ' $netfile | \
  579.         sed -e 's/^GLOBAL //' \
  580.         -e '/^#/d' \
  581.         -e '/^$/d' \
  582.         -e 's/ .*//' \
  583.         -e "s/\t.*//" | sort -u)
  584.     while read file ; do
  585.         tmpfile="${file}.2"
  586.         echo "* Fixing $file"
  587.         (
  588.         while read line ; do
  589.             found=0
  590.             for PKG in $REMOVEPKGS ; do
  591.                 [ ! "$PKG" ] && continue
  592.                 #WPKG="*|${PKG}|*"
  593.                 WPKG="*${PKG}*"
  594.                 [[ $line == $WPKG ]] && found=1 && break #ignore this line
  595.             done
  596.             [ $found -eq 0 ] && echo $line
  597.         done < "$file"
  598.         ) > $tmpfile
  599.         mv -f $tmpfile $file
  600.     done <<< "$WOOFFILES"
  601.     echo
  602. }
  603.  
  604. ###############################################################
  605.  
  606. # Extract all info from woof-installed-packages
  607. function GenerateInstalledPkgs() {
  608.     echo "* Generating list of installed packages..."
  609.     pkgsdir=${SETUPDIR}/installedpkgs
  610.     mkdir -p ${pkgsdir}
  611.     rm -f ${pkgsdir}/*
  612.     SFI=$IFS ; IFS='|'
  613.     FILESW="${SETUPDIR}/woof-installed-packages|${SETUPDIR}/devx-only-installed-packages"
  614.     for FILEW in ${FILESW} ; do
  615.         while read line ; do
  616.             specs="$line"
  617.             pkginfo=${specs//||/|~|}
  618.             pkginfo=${pkginfo//||/|~|}
  619.             x=1
  620.             for field in $pkginfo ; do
  621.                 [ "$field" = "~" ] && field=''
  622.                 case $x in 2) [ "$field" ] && nameonly=${field} && break ;; esac
  623.                 let x++
  624.             done
  625.             [ "${nameonly}" ] && echo "$specs" > ${pkgsdir}/${nameonly}
  626.         done < ${FILEW}
  627.     done
  628.     IFS=$SFI
  629.     ls ${pkgsdir} > ${pkgsdir}.txt
  630. }
  631.  
  632. function GenPackagesPuppy() {
  633.     cd ${SETUPDIR}
  634.     SFI=$IFS ; IFS='|'
  635.     echo -n > packages.puppy
  636.     ls Packages-puppy-* 2>/dev/null | sed -e '/puppy-2/d' -e '/puppy-3/d' | \
  637.     while read puppyfile ; do
  638.         (
  639.         while read line ; do
  640.             specs="$line"
  641.             pkginfo=${specs//||/|~|}
  642.             pkginfo=${pkginfo//||/|~|}
  643.             x=1
  644.             for field in $pkginfo ; do
  645.                 [ "$field" = "~" ] && field=''
  646.                 case $x in 2) [ "$field" ] && nameonly=${field} && break ;; esac
  647.                 let x++
  648.             done
  649.             [ "${nameonly}" ] && echo ${nameonly} $puppyfile
  650.         done < $puppyfile
  651.         ) >> packages.puppy
  652.     done
  653.     IFS=$SFI
  654. }
  655.  
  656. function BuiltinSearch() {
  657.     [ ! "$1" ] && echo "need <searchterm>" && return 1
  658.     grep "$@" ${pkgsdir}.txt | while read pkg ; do
  659.         echo "${pkg}... installed"
  660.     done
  661.     return $?
  662. }
  663. function SearchFile() {
  664.     [ ! "$1" ] && echo "need <searchterm>" && return 1
  665.     grep "$@" ${SETUPDIR}/builtin_files/*
  666.     return $?
  667. }
  668.  
  669. ## Generate GenericNames from Packages-distro-*
  670. function DistroIndex() {
  671.     echo "* Generting index of distro packages..."
  672.     . /etc/DISTRO_SPECS
  673.     SFI=$IFS ; IFS='|' 
  674.     ls ${SETUPDIR}/Packages-${DISTRO_BINARY_COMPAT}-* | \
  675.      grep -v 'index' | \
  676.      while read file ; do
  677.         echo "Processing: $file"
  678.         (
  679.         while read line ; do
  680.             specs="$line"
  681.             pkginfo=${specs//||/|~|}
  682.             pkginfo=${pkginfo//||/|~|}
  683.             x=1
  684.             for field in $pkginfo ; do
  685.                 [ "$field" = "~" ] && field=''
  686.                 case $x in 2) [ "$field" ] && nameonly=${field} && break ;; esac
  687.                 let x++
  688.             done
  689.             echo ${nameonly}
  690.             #echo "$specs"
  691.         done < $file
  692.         ) > ${file}.index
  693.      done
  694.      IFS=$SFI
  695. }
  696. # Quick search in distro generated index files
  697. function DistroSearchIndex() {
  698.     . /etc/DISTRO_SPECS
  699.     filez=$(ls ${SETUPDIR}/Packages-${DISTRO_BINARY_COMPAT}-* | grep 'index')
  700.     grep "$@" $filez | \
  701.         sed -e "s%${SETUPDIR}/%%" \
  702.             -e 's|.index||' \
  703.             -e 's|Packages-||'
  704. }
  705. function DistroSearch() {
  706.     . /etc/DISTRO_SPECS
  707.     filez=$(ls ${SETUPDIR}/Packages-${DISTRO_BINARY_COMPAT}-* | grep -v 'index')
  708.     grep "$@" $filez | sed -e 's|.*:||' | sort
  709. }
  710.  
  711. ### This is specifically to add all packages info specifiec in pkgs/
  712. function zznetpackages() {
  713.     cd ${aconfig%/*}
  714.     pkgs=$(ls pkgs)
  715.     for ONEPKG in $pkgs ; do
  716.         filelist="$(cat pkgs/$ONEPKG | sed '/^#/d')"
  717.         pkg=${ONEPKG##*/} #"$(basename "$file")"
  718.         rootname=${pkg%.tar.*}
  719.         rootname=${rootname%.pet}
  720.    
  721.         pkgname=${rootname%%\-[0-9]*} #first match onwards: -X* where X is a number
  722.         if [ "$pkgname" = "$rootname" ] ; then
  723.             pkgname="${rootname%%\-*}" #the old way, easy way
  724.         fi
  725.         pkgversion="${rootname#${pkgname}\-}"
  726.         pkgversion="${pkgversion//-*}"
  727.        
  728.         size=0
  729.         while read file ; do
  730.             filesize=$(stat -c%s "$file")
  731.             size=$((size+filesize))
  732.         done <<< "$filelist"
  733.        
  734.         size=$((size/1024))
  735.    
  736.         specs="${rootname}|${pkgname}|${pkgversion}||BuildingBlock|${size}K||${pkg}.pet||_${pkgname}_||||"
  737.    
  738.         sed -i "/|${pkgname}|/d" ${SETUPDIR}/woof-installed-packages
  739.         echo "$specs" >> ${SETUPDIR}/woof-installed-packages
  740.         echo "$filelist" > ${SETUPDIR}/builtin_files/${pkgname}
  741.     done
  742.     sort -u ${SETUPDIR}/woof-installed-packages > ${SETUPDIR}/woof-installed-packages.2
  743.     mv -fv ${SETUPDIR}/woof-installed-packages.2 ${SETUPDIR}/woof-installed-packages
  744. }
  745.  
  746. # This gathers information from DISTRO_PKGS_SPECS
  747. function PackageByGenericName() {
  748.     . ${SETUPDIR}/DISTRO_PKGS_SPECS
  749.     pkgs=$(echo "$PKGS_SPECS_TABLE" | \
  750.         sed -e '/^#.*/d' \
  751.             -e 's/#.*//' \
  752.             -e '/^no/d' | \
  753.           grep "|$1|")
  754.     SFI=$IFS
  755.     IFS='|'
  756.     while read line; do
  757.         specsinfo=${line//||/|~|}
  758.         specsinfo=${specsinfo//||/|~|}
  759.         x=1
  760.         for field in $specsinfo ; do
  761.             [ "$field" = "~" ] && field=''
  762.             case $x in
  763.                 #2) echo ${field}   ;;
  764.                 3)  
  765.                   if [ "$field" ] ; then
  766.                     packages=${field//,/|}
  767.                     for package in $packages ; do
  768.                         echo '  '${package}
  769.                     done
  770.                   fi
  771.                     ;;
  772.             esac
  773.             let x++
  774.         done
  775.     done <<< "$pkgs"
  776.     IFS=$SFI   
  777. }
  778.  
  779. #####################################################
  780. #remaster stuff
  781. case "$1" in
  782.     -zzremove)
  783.         cd ${aconfig%/*}
  784.         RemoveBuiltinFilesBL    #1
  785.         WoofRemoveGlobalMatch   #2
  786.         WoofRemoveGenericPkgs   #3
  787.         exit
  788.         ;;
  789. esac
  790.  
  791. #####################################################
  792.  
  793. export pkgsdir=${SETUPDIR}/installedpkgs
  794. if [ ! -d "${pkgsdir}" ] || [ ! -f "${pkgsdir}.txt" ] ; then
  795.     echo "Initializing $0 ..."
  796.     DistroIndex
  797.     GenerateInstalledPkgs
  798. fi
  799. #####################################################
  800.  
  801.  
  802. case "$1" in
  803.     -export)
  804.         [ ! "$2" ] && echo "* Syntax: $0 -export <pkg>" && exit
  805.         BuiltinExport "$2"     
  806.         ;;
  807.     -pkginfo)   PkgInfo $2 ;;
  808.     -pkgdeps)   PkgDeps $2 ;;
  809.     -checkdeps) CheckDeps $2 ;;
  810.     -checkdepstree) CheckDepsTree $2 ;;
  811.     -info)
  812.         [ ! "$2" ] && echo "* Syntax: $0 -info <pkg>" && exit
  813.         BuiltinInfo "$2"
  814.         ;;
  815.     -fullinfo)
  816.         ( BuiltinInfo $2 ; BuiltinFiles $2 ) | more
  817.         ;; 
  818.     -files)
  819.         [ ! "$2" ] && echo "* Syntax: $0 -files <pkg>" && exit
  820.         BuiltinFiles "$2"
  821.         [ $? -ne 0 ] && echo "* ERROR: '$2' is not a builtin pkg"
  822.         ;;
  823.     -checkfiles)    CheckFiles "$2"     ;;
  824.     -specs)         BuiltinSpecs2 $2    ;;
  825.     -installed)     InstalledList       ;;
  826.     -list)          BuiltinList > builtin.list  ;;
  827.     -listinfo) 
  828.         ;; 
  829.     -remove)
  830.         [ ! "$2" ] && echo "* Syntax: $0 -remove <pkg>" && exit
  831.         BuiltinRemoveFiles $2
  832.         BuiltinRemoveSpecs $2
  833.         ;;     
  834.     -install)       shift;  Pkg2Builtin "$@"        ;;
  835.     -install2woof)  shift;  InstallPkgs2Woof "$@"   ;;
  836.     -search)        shift;  BuiltinSearch "$@"      ;;
  837.     -searchfile)    shift;  SearchFile "$@"     ;;
  838.  
  839.     -gen)       GenerateInstalledPkgs   ;;
  840.     -genpuppy)  GenPackagesPuppy        ;;
  841.        
  842.     -distroindex)   DistroIndex ;;     
  843.     -distrosearch)  shift; DistroSearch "$@" ;;
  844.     -distrosindex)  shift; DistroSearchIndex "$@" ;;
  845.     #-init)         PacmanInit  ;;
  846.     -pkgbygeneric)  PackageByGenericName $2 ;;
  847.        
  848.     ########## zznet stuff
  849.     -removebl)      WoofRemoveGenericPkgs   ;;
  850.     -removegbl)     WoofRemoveGlobalMatch   ;;
  851.     -removefilesbl) RemoveBuiltinFilesBL    ;;
  852.     -net)
  853.         #cd ${aconfig%/*}
  854.         #RemoveBuiltinFilesBL   #1
  855.         #WoofRemoveGlobalMatch  #2
  856.         #WoofRemoveGenericPkgs  #3
  857.         echo "*** Now zznetpackages ***"
  858.         zznetpackages           #4
  859.         echo "*** Finished zznetpackages ***"
  860.         ;;
  861.    
  862.     -zznetpackages)
  863.         zznetpackages
  864.         ;;
  865.    
  866.     -ubuntufiller)
  867.         while read pkg; do
  868.             specs=$(DistroSearch "|$pkg|")
  869.             if [ "$specs" ] ; then
  870.                 echo "$specs" > ${SETUPDIR}/installedpkgs/${pkg}
  871.                 echo "$specs" >> ${SETUPDIR}/woof-installed-packages
  872.             else
  873.                 echo "* $pkg is not in distro database..."
  874.             fi
  875.         done < woofnet.ubuntu.fillers
  876.         ;;
  877.                
  878.     #No args, no action, completely silent
  879.     "") echo -n  ;;
  880.    
  881.     #args provided, but not recognized...
  882.     *)  echo "${0##*/}: '$1' unrecognized command " ;;     
  883. esac   
  884.  
  885. ### END ###
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement