Advertisement
s243a

install_pkgs_fm_dir.sh

Mar 31st, 2019
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.70 KB | None | 0 0
  1. #/bin/bash
  2. curdir=`realpath $(pwd)/../..`
  3. source $curdir/defaults
  4. prefix=${prefix:-"/64"}
  5. branch=${branch:-next64}
  6. xinteractive=${xinteractive:-0}
  7.  
  8. post_inst_fixes_coreutils(){
  9.   arg_1=$1
  10.   pfk_local=${arg_1:-$prefix}
  11.   if [ -f $curdir/slitaz-rootfs$prefix/var/lib/tazpkg/installed/coreutils ]; then
  12.     #TODO perhaps we don't want to do this if df-Full already exists.
  13.     echo '#!/bin/sh
  14.     exec df $@' > $curdir/slitaz-rootfs$prefix/usr/bin/df-FULL
  15.     chmod +x $curdir/slitaz-rootfs$prefix/usr/bin/df-FULL
  16.   fi
  17. }
  18. post_inst_fixes_gzip(){
  19.      if [ -f $curdir/slitaz-rootfs$prefix/var/lib/tazpkg/installed/grep ]; then    
  20.        rm -f  $curdir/slitaz-rootfs$prefix/bin/gzip
  21.      fi
  22. }
  23. post_inst_fixes_lzma(){
  24.     if [ -f $curdir/slitaz-rootfs$prefix/var/lib/tazpkg/installed/lzma ]; then
  25.       rm -f  $curdir/slitaz-rootfs$prefix/bin/lzma
  26.       rm -f  $curdir/slitaz-rootfs$prefix/bin/unlzma
  27.       rm -f  $curdir/slitaz-rootfs$prefix/bin/lzcat      
  28.     fi
  29. }
  30. post_inst_fixes_xz(){
  31.     if [ -f $curdir/slitaz-rootfs$prefix/var/lib/tazpkg/installed/xz ]; then
  32.       rpost_inst_fixes_lzma
  33.     fi
  34. }
  35. post_inst_fixes(){
  36.   arg_1=$1
  37.   #arg_2=$2
  38.   pkg_local=${arg_1:-$pkg}
  39.   pfk_local=${prefix:-$2}
  40.  
  41.   if [ -z "${pkg_local##coreutils}" ]; then
  42.     post_inst_fixes_coreutils $pfk_local
  43.   fi
  44.  
  45.   if [ -z "${pkg_local##gzip}" ]; then
  46.     post_inst_fixes_gzip $pfk_local
  47.   fi
  48.   if [ -z "${pkg_local##lzma}" ]; then #Added by s243a
  49.     post_inst_fixes_lzma $pfk_local
  50.   fi
  51.   if [ -z "${pkg_local##xz}" ]; then #Added by s243a
  52.      post_inst_fixes_xz $pfk_local
  53.   fi  
  54. }
  55.  
  56. trap close_fd_12 EXIT SIGKILL SIGTERM
  57. close_fd_12() { exec 12>&- ; }
  58. is_array(){ #Pass the name of the variable to this function (not the variable it's self)
  59.   #https://stackoverflow.com/questions/14525296/bash-check-if-variable-is-array
  60.   #http://fvue.nl/wiki/Bash:_Detect_if_variable_is_an_array
  61.   #https://www.computerhope.com/unix/bash/declare.htm
  62.   if [ $(declare -p $1 | grep -q '^declare \-a') ]; then
  63.   #Variable is an array
  64.    is_array_rtn=1 #This is opposite standard unix exit codes: https://shapeshed.com/unix-exit-codes/
  65.   else
  66.   #variable is not an array
  67.    is_array_rtn=0 #This is opposite standard unix exit codes: #http://www.tldp.org/LDP/abs/html/exitcodes.html
  68.   fi
  69. }
  70. install_pkg(){
  71.  
  72.   pkg="$1"
  73.   opt_in=$2
  74.   options=${opt_in:-'--local'} #In some cases might want to use options like --forced --newconf --nodeps of --local
  75.   echo "installing $1"
  76.   echo "options=$options"
  77.   bname="$(basename $pkg)"
  78.  
  79.   #Direct errors to null because it should already exist in destination folder.    
  80.   cp $pkg $curdir/slitaz-rootfs$prefix/pkgs/$bname 2> /dev/null #We'll copy everything into $curdir/slitaz-rootfs/pkgs before installig anything.
  81.  
  82.   echo "#!/bin/sh
  83. cd $prefix/pkgs
  84. tazpkg $options install $bname --root=$prefix
  85. " > $curdir/slitaz-rootfs$prefix/pkgs/start.sh #$curdir/slitaz-rootfs/start.sh
  86.  
  87.   chmod +x $curdir/slitaz-rootfs$prefix/pkgs/start.sh
  88.   chroot $curdir/slitaz-rootfs/ $prefix/pkgs/start.sh #Consider chrooting into the prefix folder once enough packages are installed
  89.   #read -p "Press enter to continue" #added by s243a
  90.   rm -f $curdir/slitaz-rootfs$prefix/pkgs/$bname
  91.   rm -f $curdir/slitaz-rootfs$prefix/pkgs/start.sh     
  92.   post_inst_fixes $pkg
  93. }
  94. install_pkgs_fm_dir(){ #Specify full path to directory as first input argument
  95.    mkdir -p "/tmp/make-tazpup/functions/fd"
  96.    exec 12<> "/tmp/mv_or_copy_files/fd_12"
  97.    while IFS=$'\0' read  -r -d $'\0' -u12 aPkg ; do
  98.    if [ -L "$aPkg" ]; then
  99.        aPkg=`readlink "$aPkg"`
  100.    fi
  101.    if [ -f "$aPkg" ]; then
  102.      install_pkg "$aPkg"
  103.    fi
  104.    done 12< <( find "$1" -wholename '*'"$branch/"'*.tazpkg' -print0 ) #https://blog.famzah.net/2016/10/20/bash-process-null-terminated-results-piped-from-external-commands/
  105.    exec 12>&-
  106. }
  107. for Ap_Type in "console_editors" "terminal_emulators" "text_editors" "graphics" "games"; do
  108.   Applicatoins_TO_INSTALL="$Ap_Type"_TO_INSTALL
  109.   is_array "$Applicatoins_TO_INSTALL"
  110.   if [ ! is_array_rtn ]; then
  111.     if [ "${#Applicatoins_TO_INSTALL}" -gt 0 ]; then
  112.        Applicatoins_TO_INSTALL=( "${app_options_str//,/$IFS}" )
  113.     fi
  114.   fi
  115.   #if [ is_array_rtn -eq 1 ]; then
  116.     #if [ ${#myvar} -gt 0 ]; then
  117.     #  Applicatoins_TO_INSTALL=( "$TextEditors_TO_INSTALL" )
  118.     #else
  119.     #  set_Applications_TO_INSTALL
  120.     #  Applicatoins_TO_INSTALL="$set_Applications_TO_INSTALL_rtn"
  121.     #fi
  122.     for applicaiton in "${Applicatoins_TO_INSTALL[@]}"; do
  123.      
  124.       app_path=$curdir/pkgs/applications/$Ap_Type/$application
  125.       #if [ -d "$app_path/$branch" ]; then
  126.         install_pkgs_fm_dir "$app_path" #see $curdir/build-scripts/make-tazpup_functions.sh
  127.       #fi
  128.       #install_pkg "$app_path"
  129.     done
  130.   #fi
  131. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement