Advertisement
s243a

ppa2pup_gawk

Dec 20th, 2019
798
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 16.92 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # ppa2pup
  4. # convert an Ubuntu PPA repo file, into a Puppy compatible repo file.
  5.  
  6. # @TODO1 - fix last few fields of package entries (should contain the supported ubuntu distro, not current system)
  7. TMPDIR=/tmp/pkg/${whoami}
  8. . /etc/DISTRO_SPECS
  9.  
  10. #if [ "$DISTRO_BINARY_COMPAT" != "ubuntu" ] && [ "$DISTRO_BINARY_COMPAT" != "debian" ];then
  11. #  echo "Sorry, you must be running a .deb compatible Puppy Linux"
  12. #  echo "to use this tool. Your Puppy is based on '$DISTRO_BINARY_COMPAT'"
  13. #  exit 1
  14. #fi
  15.  
  16. #Consider /looking to see if /root/.packages/repo exists. See: https://github.com/s243a/woof-CE/blob/8e44442ca9144b202b73737101231115a87488f1/woof-code/rootfs-packages/PKG/usr/sbin/ppa2pup#L17
  17. [ -z "$REPO_DIR" ] && REPO_DIR="$(realpath /root/.packages)"
  18. [ -z "$REPO_DIR" ]  && REPO_DIR="$(readlink /root/.packages)"
  19. [ -z "$REPO_DIR" ]  && REPO_DIR="/root/.packages)"
  20. [ -z "$PKG_KEEP_EPOCH_IN_DOC_REPO" ] && export PKG_KEEP_EPOCH_IN_DOC_REPO=false
  21. if [ -z "$PKG_KEEP_EPOCH_IN_DOC_REPO" ] || [ "$PKG_KEEP_EPOCH_IN_DOC_REPO" = false ]; then
  22.   AWK_STRIP_EPOCH='\
  23. function stripEpoch(s){
  24.  sub(/^([0-9]*:)?/,"",s)
  25.  return  s
  26. }'
  27.  AWK_STRIP_EPOCH_DEPNDS='stripEpoch(v[2])'
  28.  AWK_STRIP_EPOCH_VERSION='stripEpoch($0)'
  29. else
  30.   AWK_STRIP_EPOCH=''
  31.   AWK_STRIP_EPOCH_DEPNDS='v[2]'
  32.   AWK_STRIP_EPOCH_VERSION='$0'
  33. fi
  34.  
  35.  
  36. if [ ! "$1" ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]
  37. then
  38.  
  39.   echo "This script creates a Puppy-compatible repo file from a PPA or Debian repo."
  40.   echo
  41.   echo "For Launchpad PPA repos:"
  42.   echo
  43.   echo "  Usage: ppa2pup ppa:<user>/<repo> [debian|ubuntu] [bionic|stretch|artful|etc] [main|all|contrib|non-free|etc]"
  44.   echo
  45.   echo "Examples:"
  46.   echo
  47.   echo "  ppa2pup ppa:team-xbmc/ppa"
  48.   echo
  49.   echo "  ppa2pup ppa:team-xbmc/ppa ubuntu bionic"
  50.   echo
  51.   echo "  ppa2pup ppa:team-xbmc/ppa ubuntu artful"
  52.   echo
  53.   echo "  ppa2pup ppa:team-xbmc/ppa debian stretch"
  54.   echo
  55.   echo
  56.   echo "For other third-party Debian repos:"
  57.   echo
  58.   echo "  Usage: ppa2pup http://site.com/[debian|ubuntu]/ [stretch|bionic|etc] [main|contrib|non-free|etc]"
  59.   echo
  60.   echo "Examples:"
  61.   echo
  62.   echo "  ppa2pup http://rpms.litespeedtech.com/debian/"
  63.   echo
  64.   echo "  ppa2pup http://rpms.litespeedtech.com/debian/ stretch main"
  65.   echo
  66.   echo "  ppa2pup http://repo.steampowered.com/steam/ precise steam"
  67.   echo
  68.   echo "  ppa2pup http://http.kali.org/kali/ kali-bleeding-edge main contrib non-free"
  69.   echo
  70.   echo "NOTE: Any ommitted distro names or versions will be guessed."
  71.   echo
  72.   exit 1
  73.  
  74. fi
  75.  
  76.  
  77. # create a dir to work in
  78. mkdir -p /tmp/ppa_pkgs
  79.  
  80. # remove any old files
  81. rm /tmp/ppa_pkgs/* 2>/dev/null
  82.  
  83.  
  84. # we need to find the correct Packages.gz for the distro (debian/ubuntu),
  85. # distro version (stretch/bionic/etc), and architecture (i386/amd64)
  86.  
  87. arch='i386'
  88. case $(uname -m) in
  89.   i*86) arch='i386'  ;;
  90.   *64)  arch='amd64' ;;
  91. esac
  92.  
  93. function get_distro(){
  94.   local a_repo_url=$1
  95.   local a_distro_ver=$2
  96.   local a_stream=$3
  97.   distro_rtn=''
  98.   distro_match_weakness='' #'0' Is for the best match. Higher Numbers indicate a weaker match
  99.  
  100.   distro_rtn=$(cat /root/.pkg/sources-all | awk -v VER="$a_distro_ver" -v  STREAM="$a_stream" -v URL="$a_repo_url" \
  101.   'BEGIN{FS="|"}
  102.     /^.+$/ {
  103.     if ( (index($4,URL) > 0 ) && ( index($3,  "-" VER "-" STREAM) > 0 )  ) {
  104.       split($3, array , "-" )
  105.       print array[2]
  106.       exit 0
  107.     }
  108.    }')
  109.     if [ ! -z "$distro_rtn" ]; then
  110.       distro_match_weakness=0 #Perfect Match
  111.       return 0
  112.     fi
  113.    
  114.   distro_rtn=$(cat /root/.pkg/sources-all | awk -v VER="$a_distro_ver"  \
  115.   'BEGIN{FS="|"}
  116.     /^.+$/ {
  117.     if ( index($3,  "-" VER "-") > 0 )  {
  118.       split($3, array , "-" )
  119.       print array[2]
  120.       exit 0
  121.     }
  122.    }')    
  123.     if [ ! -z "$distro_rtn" ]; then
  124.       distro_match_weakness=1 #Excelent Match
  125.       return 0
  126.     fi    
  127.     if [ -z "$distro_rtn" ]; then #Try searching by a stripped distro version.
  128.   distro_rtn=$(cat /root/.pkg/sources-all | awk -v VER="${a_distro_ver%%-*}"  \
  129.   'BEGIN{FS="|"}
  130.     /^.+$/ {
  131.     if ( index($3,  "-" VER "-") > 0 )  {
  132.       split($3, array , "-" )
  133.       print array[2]
  134.       exit 0
  135.     }
  136.    }')  
  137.     if [ ! -z "$distro_rtn" ]; then
  138.       distro_match_weakness=2 #Good Match
  139.       return 0
  140.     fi    
  141.    
  142.     case "$a_distro_ver") in
  143.     "${$DISTRO_COMPAT_VERSION}"*)
  144.        distro_rtn="${DISTRO_BINARY_COMPAT}"
  145.        distro_match_weakness=3 #Okay Match
  146.        return 0; ;;        
  147.     sid-*|buster*|stretch*|wheezy*|squeeze*|lenny*|etch*|sarge*|woody*|potato*|slink*|hamm*)
  148.        distro_rtn=debian;
  149.        distro_match_weakness=4 #Probably Okay Match
  150.        return 0; ;;            
  151.     jessie*)
  152.       distro_rtn=debian;
  153.       distro_match_weakness=5 #Poor Match        
  154.       return 0; ;;#Might also be devuan so return an error.
  155.     ceres*|beowulf*|ascii*)
  156.       distro_rtn=devuan;
  157.       distro_match_weakness=4 #Probably Okay Match
  158.       return 0; ;;        
  159.     eoan*|disco*|bionic*|xenial*|trusty|cosmic*|artful*|zesty*|wily*|utopic*|saucy*|raring*|quantal*|precise*|oneiric*|lucid*|karmic*|jaunty*|intrepid*|hardy*|gusty*|feisty*|edgy*|dapper*|breezy*|hoary*|warty*)
  160.       distro_rtn=ubuntu; ;;
  161.       distro_match_weakness=4 #Probably Okay Match
  162.       return 0; ;;          
  163.     *)
  164.       distro_rtn="${DISTRO_BINARY_COMPAT}"; ;;
  165.       distro_match_weakness=6 #Very Poor Match (Default Used)
  166.       return 0; ;; #Return an error since the distro returned might be wrong.
  167.     esac
  168. }
  169.  
  170. if [[ "$1" =~ 'ppa:' ]]
  171. then
  172.  
  173.   # we got a 'PPA' URL, lets parse it and get the Packages.gz
  174.   ppaname="${1/*\//}"
  175.   username="${1/\/*/}"
  176.   username="${username//ppa:/}"
  177.   ppaname="${ppaname//ppa:/}"
  178.  
  179.   # get username, but strip special chars
  180.   PPA_NAME="${username//[-_:]/}"
  181.  
  182.   distro=${2:-$DISTRO_BINARY_COMPAT}
  183.   distro_ver=${3:-$DISTRO_COMPAT_VERSION}
  184.   repo_name="$distro_ver-$PPA_NAME"
  185.   repo_filename="Packages-$distro-$distro_ver-${PPA_NAME}"
  186.   repo_stream=${4:-main}
  187.   repo_stream2=''
  188.   repo_stream3=''
  189.   repo_stream4=''
  190.   [ "$5" != '' ] && repo_stream2=${5}
  191.   [ "$6" != '' ] && repo_stream3=${6}
  192.   [ "$7" != '' ] && repo_stream4=${7}
  193.  
  194.  
  195.   URL=http://ppa.launchpad.net/${username}/${ppaname}/${distro}/dists/${distro_ver}/${repo_stream}/binary-${arch}/Packages.gz
  196.   repo_url=http://ppa.launchpad.net/${username}/${ppaname}/${distro}/
  197.  
  198. elif [[ "$1" =~ 'http://' ]] || [[ "$1" =~ 'https://' ]] || [[ "$1" =~ 'ftp://' ]];then
  199.   repo_type=debian
  200.   # we got a Debian repo source URL, lets parse it and get the Packages.gz
  201.  
  202.   distro=${DISTRO_BINARY_COMPAT}
  203.   distro_ver=${2:-$DISTRO_COMPAT_VERSION}
  204.   repo_url=$(echo $1 | sed -e 's#/$##g')/
  205.   repo_stream=${3:-main}
  206.   repo_stream2=''
  207.   repo_stream3=''
  208.   repo_stream4=''
  209.   [ "$4" != '' ] && repo_stream2=${4}
  210.   [ "$5" != '' ] && repo_stream3=${5}
  211.   [ "$6" != '' ] && repo_stream4=${6}
  212.  
  213.   URL=$(echo $1 | sed -e 's#/$##g')/dists/${distro_ver}/${repo_stream}/binary-${arch}/Packages.gz
  214.  
  215. else
  216.  
  217.   # didnt get ppa:foo/bar, exit with usage
  218.   $0 -h
  219.   exit 1
  220.  
  221. fi
  222.  
  223. function set_PPA_NAME_name(){
  224.   # if we didn't get the name from the ppa:foo/bar style URL
  225.   local distro_input
  226.   if [[ ! "$1" =~ 'ppa:' ]]
  227.   then
  228.  
  229.     # check if this repo is already installed (find its name in Pkg sources files)
  230.     if [ -z "$repo_url" ]; then
  231.       PPA_NAME="$(grep -m1 "^${distro_ver}-${stream:-main}|" /root/.pkg/sources-all | cut -f1 -d'|' 2>/dev/null)"
  232.     else
  233.    
  234.       #e.g. "strech-main"
  235.       #Therefore we make sure the repo url also matches to avoid overwring the repo.
  236.       PPA_NAME="$(grep "^${distro_ver}-${stream:-main}|" /root/.pkg/sources-all | grep -m1 "$repo_url"  | cut -f1 -d'|' 2>/dev/null)"
  237.  
  238.       #e.g. "stretch-tor-main"
  239.       if [ -z "$PPA_NAME" ]; then
  240.          PPA_NAME="$(grep -E "^${distro_ver}-[^-]*-${stream:-main}|" /root/.pkg/sources-all | grep -m1 "$repo_url"  | cut -f1 -d'|' 2>/dev/null)"
  241.       fi      
  242.  
  243.       #e.g. "stretch-main-tor"
  244.       if [ -z "$PPA_NAME" ]; then
  245.          PPA_NAME="$(grep "^${distro_ver}-${stream:-main}-" /root/.pkg/sources-all | grep -m1 "$repo_url"  | cut -f1 -d'|' 2>/dev/null)"
  246.       fi
  247.      
  248.       #Perhaps a repo doesn't have seperate streams like the puppy repo.
  249.       if [ -z "$PPA_NAME" ]; then
  250.          PPA_NAME="$(grep "^${distro_ver}|" /root/.pkg/sources-all | grep -m1 "$repo_url"  | cut -f1 -d'|' 2>/dev/null)"
  251.       fi
  252.            
  253.     fi
  254.  
  255.     # get repo name and filename
  256.     if [ "$PPA_NAME" = "" ];then
  257.       while [ 1 -eq 1 ]
  258.         echo
  259.         read -e -p \
  260. "Enter a repo name, such as '${distro_ver}-${stream:-main}':  
  261. $(echo_when "$PKG_ALLOW_REPO_fname_via_CLI" "or to specify the distro enter the full repo file name such as: 'Packages-${distro}-${distro_ver}-${stream:-main}'"):
  262. " \
  263.                         -i "${distro_ver}-${stream:-main}" PPA_NAME
  264.         PPA_NAME="$( echo "${PPA_NAME// /-}" | tr '_' '-' | tr '[:upper:]' '[:lower:]' )"
  265.         parse_repoName "$PPA_NAME" #Usefull for error checking user input.
  266.  
  267.         #This line will only be executed if the user incorrectly
  268.         #supplies a filename rather than the repo name.
  269.         if [ $(( parse_repo_FLAGS & C_DISTRO_PARSED )) -eq 0 ]; then
  270.            echo -e "${yellow}Warning:${endcolour} user should supply simple repo name rather than a filename"
  271.            echo -e "This is an unsorported feature that may be removed in future versions."
  272.           if [ $(( parse_repo_FLAGS & C_DISTRO_MATCH )) -eq 0 ]; then
  273.          
  274.             echo -e "${yellow}Warning:${endcolour} filename given suggests distro=${distro_parsed}  "\
  275.             "but pkg expected distro=${distro}"
  276.             if [ $ASK = true ]; then
  277.               echo -e "Use expected distro name y/n (default = y)"
  278.               [ "$ASK" = true ] && read -n 1 CONFIRM </dev/tty || CONFIRM=y
  279.               if [ CONFIRM = n ] || [ CONFIRM = no ]; then
  280.                 echo -e "Using parsed repo name"              
  281.                 distro="$distro_parsed" #This is only needed for repo file name.
  282.                              
  283.               elif [ CONFIRM = y ] || [ CONFIRM = yes ]; then
  284.                 echo -e "Using expected repo name"
  285.               else
  286.                 echo -e "Invalid choice"
  287.               fi
  288.             fi
  289.           fi          
  290.            
  291.         fi
  292.  
  293.         if ; then #Sets distro, distro_ver and
  294.           echo "Invalid Repo Name"
  295.           break
  296.         fi
  297.        if [ -z $URL ]; then
  298.         URL=$(echo $1 | sed -e 's#/$##g')/dists/${distro_ver}/${repo_stream}/binary-${arch}/Packages.gz            
  299.       fi
  300.     else
  301.       PPA_NAME="$( echo "${PPA_NAME// /-}" | tr '_' '-' | tr '[:upper:]' '[:lower:]' )"
  302.       repo_name="$PPA_NAME" #Set via parse_repoName repo_filename  
  303.     fi
  304.  
  305.   fi
  306.  
  307. }
  308. function parse_distro_version(){
  309.   local distro_name=$1
  310.   local distro_version_last=$2
  311.   local maybe_distro_version=$3
  312.   local version-modifier=${1#*-}
  313.   case "$version-modifier" in
  314.   backports) echo "$maybe_distro_version" ;;
  315.   proposed-updates) echo "$maybe_distro_version" ;;
  316.   updates) echo "$maybe_distro_version" ;;
  317.   backports-sloppy) echo "$maybe_distro_version" ;;
  318.   *) echo "$distro_version_last" ;;
  319.   esac
  320. }
  321. function parse_repoName(){
  322.   Arg1="$(echo $1 | tr "-" " ")"
  323.   set -- $Arg1
  324.   state="parse-Package"
  325.   PPA_NAME=""
  326.   while [ $# -gt 0 ]; do  
  327.       case state in
  328.       parse-Package)
  329.         if [ "$arg" = "packages" ]  || [ "$arg" = "Packages" ] ; then
  330.           PPA_NAME=$2
  331.           distro_parsed="$2"
  332.           distro_ver_parsed="$3" #For now we'll only use this for error checking.
  333.           state="pare-Distro_Version"
  334.           shift 3
  335.        else
  336.           PPA_NAME="${PPA_NAME}-${1}"
  337.           distro="${DISTRO_BINARY_COMPAT}"
  338.           distro_ver="$1"
  339.           shift 1        
  340.        fi
  341.       ;;
  342.       pare-Distro_Version)
  343.           PPA_NAME="${PPA_NAME}-${1}"
  344.           distro_ver_parsed="$(parse_distro_version  "$distro" "$distro_ver_parsed" "$PPA_NAME")"          
  345.           shift 1; ;;      
  346.       *)
  347.           PPA_NAME="${PPA_NAME}-${1}"
  348.           shift 1; ;;
  349.     esac      
  350.   done
  351.   if [ ! -z "$distro_parsed" ]; then
  352.     distro="$distro_parsed"
  353.   fi
  354.   if [ -z "$distro_ver_parsed" ] || [ "$distro_ver_parsed" = "$distro_ver" ]; then
  355.     return 0
  356.   else
  357.     return 1
  358.   fi
  359. }
  360. PACKAGES_PATH=/tmp/ppa_Packages #TODO: use vars instead of litteral paths. See: https://github.com/s243a/woof-CE/blob/8e44442ca9144b202b73737101231115a87488f1/woof-code/rootfs-packages/PKG/usr/sbin/ppa2pup#L204
  361.  
  362. for stream in $repo_stream $repo_stream2 $repo_stream3 $repo_stream4
  363. do
  364.  
  365.   [ "$stream" = '' ] && continue
  366.  
  367.   if [ "$repo_type" = debian ]; then
  368.     distro="$(get_distro $repo_url $distro_ver $stream)"
  369.   fi
  370.  
  371.  
  372.   set_PPA_NAME_name $1
  373.   repo_filename="Packages-$distro-${PPA_NAME}"  
  374.  
  375.   rm /tmp/ppa_Packages /tmp/ppa_Packages.gz 2>/dev/null
  376.   download_failed=false
  377.  
  378.   download_url=${URL//$repo_stream/$stream}
  379.  
  380.   wget --quiet $download_url -O /tmp/ppa_Packages.gz 1>/dev/null \
  381.     || download_failed=true
  382.  
  383.   if [ ! -f /tmp/ppa_Packages.gz ] || [ $download_failed = true ];then
  384.     echo
  385.     echo "ERROR: the PPA repo '$repo_name' not found for $distro $distro_ver:"
  386.     echo
  387.     echo "  $download_url"
  388.     echo
  389.     echo "You could try a different version of the repo."
  390.     echo
  391.     $0 -h
  392.     exit 1
  393.   fi
  394.  
  395.  
  396.   gunzip /tmp/ppa_Packages.gz
  397.  
  398.  
  399.   # if Packages file is empty, dont create a repo for it
  400.   if [ -z /tmp/ppa_Packages ] || [ ! -s /tmp/ppa_Packages ];then
  401.     continue
  402.   fi
  403.  
  404.  
  405.   echo
  406.   echo "Found URL:"
  407.   echo
  408.   echo "  $download_url"
  409.   echo
  410.   echo "Repo to create:"
  411.   echo "   $repo_name"
  412.   echo
  413.   echo "Repo file to create:"
  414.   echo "   ~/.packages/$repo_filename"
  415.   echo
  416.  
  417.   rm /tmp/$repo_filename &>/dev/null
  418.  
  419.   cat "$PACKAGES_PATH" | awk -v PKGOS="$distro" -v PKGOSVER="$distro_ver" \
  420. 'function get_inequality(s){
  421.  switch(s){
  422.    case "<":
  423.      return "lt"
  424.      break
  425.    case ">":
  426.      return "gt"
  427.      break
  428.    case "<=":
  429.      return "le"
  430.      break
  431.    case ">=":
  432.      return "ge"
  433.      break
  434.    case "=":
  435.      return "eq"
  436.      break
  437.  
  438.    }
  439.    return ""
  440. }
  441. function fixdepends(s,   p,a,dep_i,dep_split,pkg_i,ver_i,v,ineq,sout) {
  442.  split(s,a,",")
  443.  for (p in a) {
  444.    match(a[p],/^[ \t]*([^ \t]+)[ \t]*(\((.*)\))?/,dep_split)
  445.    pkg_i = dep_split[1]
  446.    sout = sout ",+" pkg_i
  447.    if ( length(dep_split) > 1 ){
  448.      ver_i=dep_split[3]
  449.      split(ver_i,v," ")
  450.      ineq=get_inequality(v[1])
  451.      if ( length(v) > 1 ){
  452.        sout = sout "&" ineq '"$AWK_STRIP_EPOCH_DEPNDS"'\
  453.      }
  454.      }
  455.  }
  456.  sub(/^,/,"",sout) ;
  457.  sub(/(,)?$/,"",sout) ;
  458.  return sout;
  459. }
  460. '"$AWK_STRIP_EPOCH"'\
  461. /^Package:/     { sub(/^Package: /,"");  PKG=$0; }
  462. /^Version:/     { sub(/^Version: /,"");  PKGVER='"$AWK_STRIP_EPOCH_VERSION"'; }\
  463. /^Filename:/    { sub(/^Filename: /,""); PKGPATH=$0; sub(/\/[^\/]*$/,"",PKGPATH); sub(/.*\//,""); PKGFILE=$0; }
  464. /^Priority:/    { sub(/^Priority: /,""); PKGPRIO=$0; }
  465. /^Section:/     { sub(/^Section: /,"");  PKGSECTION=$0; }
  466. /^Installed-Size:/ { sub(/^Installed-Size: /,"");  PKGSIZE=$0; }
  467. /^Depends:/     { sub(/^Depends: /,"");     PKGDEP=fixdepends($0) "," PKGDEP; }
  468. /^Pre-Depends:/ { sub(/^Pre-Depends: /,""); PKGDEP=fixdepends($0) "," PKGDEP; }
  469. /^Description:/ { sub(/^Description: /,""); PKGINFO=substr($0,1,200); }
  470. /^$/            { print PKG "_" PKGVER "|" PKG "|" PKGVER "||" PKGSECTION "|" PKGSIZE "K|" PKGPATH "|" PKGFILE  "|" PKGDEP "|" PKGINFO "|" PKGOS "|" PKGOSVER  "|" ;
  471.  
  472.                  PKG=""; PKGVER=""; PKGSECTION=""; PKGSIZE=""; PKGFILE=""; PKGPATH=""; PKGDEP=""; PKGINFO=""; PKGPRIO="";    }
  473. ' > /tmp/$repo_filename
  474.  
  475.  
  476.  
  477.   rm /tmp/ppa_pkgs/* /tmp/${repo_filename}_sorted 2>/dev/null
  478.  
  479.  
  480.   # sort & move the repo file
  481.   sort -u /tmp/$repo_filename > /tmp/${repo_filename}_sorted 2>/dev/null
  482.  
  483.  
  484.   if [ ! -f /tmp/${repo_filename}_sorted ];then
  485.     echo "Error: Repo file not created!"
  486.     exit 1
  487.   fi
  488.  
  489.   mv  /tmp/${repo_filename}_sorted  ~/.packages/$repo_filename
  490.  
  491.   echo "Success! File created."
  492.   echo
  493.  
  494.   fallback_repos="$(pkg repo-list | grep -v $repo_name | tr '\n' ' ')"
  495.   repo_entry="$repo_name|deb|$repo_filename|$repo_url||||$fallback_repos"
  496.  
  497.  
  498.   # if already added to ~/.pkg/sources[-all], remove it
  499.   if [ "$(cat ~/.pkg/sources     | grep -m1 "^$repo_name|")" != "" ] || \
  500.      [ "$(cat ~/.pkg/sources-all | grep -m1 "^$repo_name|")" != "" ];then
  501.     cat ~/.pkg/sources | grep -v "^$repo_name|" > /tmp/pkgsources
  502.     cat ~/.pkg/sources-all | grep -v "^$repo_name|" > /tmp/pkgsources-all
  503.     mv /tmp/pkgsources ~/.pkg/sources
  504.     mv /tmp/pkgsources-all ~/.pkg/sources-all
  505.   fi
  506.  
  507.  
  508.   # add repo entry to ~/.pkg/sources
  509.   pkg add-source "$repo_entry"
  510.   echo
  511.  
  512.   # refresh list of available repos
  513.   pkg update-sources
  514.   echo
  515.   echo "Repo info:"
  516.   pkg repo-info $repo_name
  517.   echo
  518.  
  519.  
  520.   if [ "$(cat ~/.pkg/sources | grep -m1 "^$repo_name|")" != "" ];then
  521.     echo "Success! Repo added and available to use."
  522.     echo
  523.     echo "To use this repo, simply type the following and hit ENTER:"
  524.     echo "  pkg repo $repo_name"
  525.     echo
  526.   fi
  527.  
  528. done
  529.  
  530. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement