summaryrefslogtreecommitdiff
path: root/lib/port.sh
blob: dd7a4844f78dff818b31a8b4f2141f7b9e016d2d (plain)
    1 #!/usr/bin/env bash
    2 #
    3 # Portimg uses Crux port-like system for creating software deployment images.
    4 # Copyright (C) 2016 Aaron Ball <nullspoon@oper.io>
    5 #
    6 # This program is free software: you can redistribute it and/or modify
    7 # it under the terms of the GNU General Public License as published by
    8 # the Free Software Foundation, either version 3 of the License, or
    9 # (at your option) any later version.
   10 #
   11 # This program is distributed in the hope that it will be useful,
   12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14 # GNU General Public License for more details.
   15 #
   16 # You should have received a copy of the GNU General Public License
   17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
   18 #
   19 
   20 function archive_extract {
   21   local src=${1:-}
   22   local dest=${2:-}
   23 
   24   local ext=${src##*.}
   25 
   26   if [[ ${ext} == 'tar'
   27      || ${ext} == 'gz'
   28      || ${ext} == 'tgz'
   29      || ${ext} == 'xz'
   30      || ${ext} == 'bz2' ]]; then
   31     tar -xf ${src} -C ${dest}
   32   elif [[ ${ext} == 'zip' ]]; then
   33     unzip ${src} -d ${dest}
   34   fi
   35 }
   36 
   37 
   38 function download_src {
   39   local uri=${1:-}
   40   local destdir=${2:-}
   41 
   42   local localname=$(basename ${uri})
   43 
   44   curl -L -s -k -o "${destdir}/${localname}" "${uri}"
   45 }
   46 
   47 
   48 #
   49 # Downloads the list of source files to the specified port directory. If the
   50 # file is local, it is skipped (with a friendly info message).
   51 #
   52 # @param _src    Array reference of sources (from the Pkgfile)
   53 #
   54 function port_download_src {
   55   local _ref_src="${1:-}"
   56 
   57   # Download from Pkgfile src spec
   58   for file in ${!_ref_src}; do
   59     if [ -f "${file}" ]; then
   60       # If the source file exists locally, just copy from here
   61       linfo "File ${file} exists locally."
   62       continue
   63     else
   64       # The "file" is probably a uri that couldn't be resolved locally, so we
   65       # get the basename and see if that exists locally.
   66       if [ -f $(basename ${file}) ]; then
   67         linfo "Source '${file}' already downloaded"
   68       else
   69         linfo "Downloading ${file}"
   70         download_src "${file}" "./"
   71       fi
   72     fi
   73   done
   74 }

Generated by cgit