Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 124 lines (110 sloc) 3.507 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
#!/bin/zsh
# Declare colours for easy access
GREEN='\e[1;32m'
RED='\e[1;31m'
YELLOW='\e[1;33m'
WHITE='\e[1;37m'
COLRESET='\e[0m'

# Set EDITOR to user default, falling back on vi
EDITOR=${EDITOR:-/usr/bin/vi}

# Unset problematic variables, and reset _built
unset _built
unset epoch

# cd to build directory, download PKGBUILD, show for editing, then automatically build package
function normalbuild () {
  if [ -e PKGBUILD ]; then
    "${EDITOR}" PKGBUILD && sudo extra-x86_64-build && _built=true
  else
    echo "${RED}==>${WHITE} No PKGBUILD found${COLRESET}"
    return 1
  fi
}

function multibuild {
  if [ -e PKGBUILD ]; then
    "${EDITOR}" PKGBUILD && sudo multilib-build && _built=true
  else
    echo "${RED}==>${WHITE} No PKGBUILD found${COLRESET}"
    return 1
  fi
}

function getsources {
  cd ~/builds
  if [[ ! $2 == "skip" ]]; then
    echo "${YELLOW}==>${WHITE} Downloading sources${COLRESET}"
    yaourt -G $1
  fi
  if [ -d $1 ]; then
    cd $1
  else
    echo "${RED}==> ERROR:${WHITE} No such package${COLRESET}"
    return 1
  fi
}

# If build was successful
function postbuild {
  # If DISPLAY is set and notify-send is installed, send an "urgent" notification
  # that compilation has finished, either successfully or otherwise.
  if [ $DISPLAY ]; then
    if [ -x "$(where notify-send)" ]; then
      STATUS="FAILED"
      [ $_built ] && STATUS="SUCCESS"
      notify-send -u critical -a xfce4-notifyd -i xfce4-notifyd "Compilation of package $1 is now complete. Compilation ${STATUS}!"
    fi
  fi
      
  if [ $_built ]; then
    unset all
    # Load PKGBUILD variables
    source PKGBUILD &> /dev/null

    # Check for package archetecture
    if [[ $arch != "any" ]]; then
      arch=$(uname -m)
    fi

    # Create _ver
    _ver=${pkgver}-${pkgrel}-${arch}.pkg.tar.xz

    # Check for epoch var, and add to _ver if present
    [ $epoch ] && _ver=${epoch}:${_ver}

    # Check for multi-package
    if [[ $(echo $pkgname | wc -w) -gt 1 ]]; then
      # Add package names to array
      x=1
      foreach i in $pkgname; do
        all[${x}]=${i}-${_ver}
        x=$((x+1))
      done
      # Check first package exists, confirm completion, and prompt user to install
      [ -f ${pkgname[1]}-${_ver} ] && echo "${GREEN}==>${WHITE} Compilation complete. Multiple packages detected. Names stored in \$all${COLRESET}"
      return 0
    fi

    # Declare _pkg for easy installation/copying
    _pkg=${pkgname}-${_ver}
  
    # Check package exists, confirm completion, and prompt user to install
    if [ -f ${_pkg} ]; then
      echo "${GREEN}==>${WHITE} Compilation complete, installing...${COLRESET}"
      term="/dev/$(ps -p$$ -o tty="")"
      exec < $term
      sudo pacman -U ${_pkg}
    else
      echo "${RED}==>${WHITE} Could not find '${_pkg}', install manually${COLRESET}"
      return 1
    fi
    return 0
  fi
}

function getfiles {
  cd ~/builds
  echo "${YELLOW}==>${WHITE} Downloading sources${COLRESET}"
  _rawhtml=$(curl -s -f "https://projects.archlinux.org/svntogit/packages.git/plain/$1/trunk/" || curl -s -f "https://projects.archlinux.org/svntogit/community.git/plain/$1/trunk/")
  if [ ! $_rawhtml ] && return 1
  _filelist=$(echo $_rawhtml | grep "\<li\>" | sed 1d | cut -d "'" -f 2)
  if [ -d $1 ]; then
    cd $1
  else
    mkdir $1
    cd $1
  fi
  for _file in $(echo $_filelist); do
    _filename=$(echo $_file | cut -d "/" -f 6 | sed 's:\?.*::')
    rm -f $_filename
    curl -s -O "https://projects.archlinux.org/$_file" > $_filename
  done
}
Something went wrong with that request. Please try again.