Skip to content

Commit

Permalink
Ver 2.9 - Database metadata for local AUR packages. Add --gendb, --no…
Browse files Browse the repository at this point in the history
…database flags. Add -P AUR patched pkgfile passthrough. Update manpages
  • Loading branch information
oshazard committed Sep 30, 2016
1 parent 58c2838 commit 7893814
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 19 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,32 @@ ArchLinux User Repository (AUR) helper ![AUR](https://img.shields.io/aur/votes/a

**Total:** ![all downloads badge](https://img.shields.io/github/downloads/oshazard/apacman/total.svg)

**Previous:** ![previous release badge](https://img.shields.io/github/downloads/oshazard/apacman/v2.5/total.svg)
**Previous:** ![previous release badge](https://img.shields.io/github/downloads/oshazard/apacman/v2.6/total.svg)

**Current:** ![downloads badge](https://img.shields.io/github/downloads/oshazard/apacman/latest/total.svg)


[Migrate wizard for AUR4](https://gist.github.com/oshazard/370c7ed631af2181ee51)

Changelog:
* **NEW** improve -U to display packages removed from AUR as "unresolvable"
* **NEW** bug fix for --devel
* **NEW** merged fix that improves curl debugging
* **NEW** merged fix that removes split package support
==========
* **NEW** -P parameter uses AUR passthrough for pkgfile
* **NEW** Save installed AUR package metadata to database
* **NEW** --nodatabase parameter does not store AUR database
* **NEW** --gendb parameter to generate AUR database files
* **NEW** Display remaining packages in queue
* **NEW** --notify parameter for notify-send notifications
* **NEW** --noprogress to disable transaction progress
* **NEW** Enabled terminal title progress by default
* **NEW** --edit parameter to override 'noedit' option in config file
* **NEW** fix CLI flag precedence over config file

Version 2.6
-----------
* improve -U to display packages removed from AUR as "unresolvable"
* bug fix for --devel
* merged fix that improves curl debugging
* merged fix that removes split package support
* merged pull requests for AUR5 support
* improved virtual package support
* improved -U handling
Expand All @@ -28,13 +42,19 @@ Changelog:
* --purgekeys parameter removes trusted PGP keys
* fix for piping output
* fix for yes/no dialog

Version 2.0
-----------
* Split package support and shared source
* Improved AUR4 support
* Bug fix for AUR4 -Si
* Bug fix for built/failed
* --legacy flag for AUR3
* Preliminary AUR4 support
* Signed package support

Version 1.6
-----------
* Display [installed], [installed: VER], or [local: VER] in -Ss
* --progress parameter sets terminal title to package status
* Add AUR link to -Si info
Expand All @@ -46,13 +66,19 @@ Changelog:
* --nofail parameter to quit if a package does not build
* --purgebuild parameter to remove unneeded build depends
* --skiptest to avoid installing unit test packages

Version 1.0
-----------
* Config file support (/etc/apacman.conf)
* Cleaned up manpages
* Replacement for pacsysclean (-L list installed packages by size)
* -G now supports ABS + AUR packages
* --noaur parameter to skip AUR packages
* --warn parameter makes errors non-fatal (only enable if you know what you are doing)
* Run as root workaround for Pacman 4.2+

Version 0.6
-----------
* All features from packer
* Saves built AUR packages to /var/cache/apacman/pkg
* Uses AUR package cache directory if applicable
Expand Down
111 changes: 106 additions & 5 deletions apacman
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/bin/bash
######################################################################
# apacman - AUR wrapper forked from packer
version="2.8"
version="2.9"
# Copyright OS Hazard <oshazard+aur@gmail.com>
#
# New Features:
# * -P patched AUR passthrough for pkgfile
# * Save installed AUR package metadata to database
# * Enabled --progress by default
# * Fix CLI switch precedence over config file
# * Improved support for virtual packages
Expand All @@ -21,10 +23,12 @@ version="2.8"
# * --asdeps install AUR packages non-explicitly
# * --asexplicit install AUR packages explicitly
# * --edit always ask to edit PKGBUILD
# * --gendb generate AUR database files
# * --keepkeys do not remove imported PGP keys
# * --purgekeys remove imported PGP keys
# * --legacy backwards compatability for AUR3 (deprecated)
# * --progress transaction status in terminal titlebar
# * --nodatabase do not store AUR database
# * --nosource for security do not source PKGBUILDs (WIP)
# * --noprogress no transaction status in titlebar
# * --notify transaction status in notification
Expand Down Expand Up @@ -68,6 +72,10 @@ apacmanconf='/etc/apacman.conf'
gpgconf='/etc/pacman.d/gnupg/gpg.conf'
downdir='/var/cache/pacman/pkg'
savedir='/var/cache/apacman/pkg'
database='/var/lib/apacman'
pacmandb='/var/lib/pacman/sync/aur.db'
pkgfiledb='/var/cache/pkgfile/aur.files'
localrepo='aur'
builddir="${TMPDIR:-/tmp}/pkgbuild-$UID"
tmpdir="${TMPDIR:-/tmp}/apacmantmp-$UID"

Expand Down Expand Up @@ -139,6 +147,7 @@ usage() {
echo ' -Si - outputs info for package'
echo ' -G - download and extract aur tarball only'
echo ' -L - list installed packages by size'
echo ' -P - passthrough for pkgfile command'
echo ' -W - view web comments for package'
echo
echo ' --asdeps - install AUR packages marked as dependencies'
Expand All @@ -149,13 +158,15 @@ usage() {
echo ' --cachevcs - installs cached VCS packages newer than AUR PKGBUILDs'
echo ' --devel - update VCS (git, svn, hg) packages during -Su'
echo ' --edit - always ask to edit PKGBUILD'
echo ' --gendb - generate AUR database files'
echo ' --ignore - takes a comma-separated list of packages to ignore'
echo ' --ignorearch - ignore a missing or incomplete architecture field'
echo ' --keepkeys - do not remove imported PGP keys'
echo ' --legacy - uses AUR3.0 instead of AUR4.0 (deprecated)'
echo ' --needed - do not install up-to-date packages'
echo ' --noaur - do not actions for AUR'
echo ' --noconfirm - do not prompt for any confirmation'
echo ' --nodatabase - do not store AUR database'
echo ' --noedit - do not prompt to edit files'
echo ' --nofail - do not continue if a package fails to build'
echo ' --noprogress - no transaction status in titlebar'
Expand Down Expand Up @@ -191,13 +202,15 @@ varstatus() {
}

infoconf() {
vars="apacmanconf builddir downdir editor makepkgconf pacmanconf savedir tmpdir usermakepkgconf"
vars="apacmanconf builddir database downdir editor localrepo makepkgconf"
vars="$vars pacmanconf pacmandb pkgfiledb savedir tmpdir usermakepkgconf"
for i in $vars; do
varstatus $i
done

vars="asdeps asexplicit auronly buildonly cachevcs ignorearch keepkeys legacy needed noaur noconfirm"
vars="$vars noedit nofail preview progress purgebuild purgekeys quiet skipcache skipinteg skiptest warn"
vars="asdeps asexplicit auronly buildonly cachevcs ignorearch keepkeys legacy"
vars="$vars needed noaur noconfirm nodatabase noedit nofail preview progress"
vars="$vars purgebuild purgekeys quiet skipcache skipinteg skiptest warn"
for j in $vars; do
varstatus $j
done
Expand Down Expand Up @@ -571,6 +584,59 @@ isoutofdate() {
[[ "$(jshon -Q -e results -a -e OutOfDate -u < "$tmpdir/$1.info")" = "1" ]]
}

# Generate local AUR database
aurgendb() {
echo -e "${COLOR5}::${COLOR1} Generating AUR database...${ENDCOLOR}"
progress "Generating AUR DB"
runasroot mkdir -p ${database}/{local,raw}
savedpkgs=$(ls ${savedir}/*-*-{any,${makearch}}.pkg.{tar,tar.xz} 2>/dev/null)
runasroot repo-add ${database}/raw/aur.db.tar.gz $savedpkgs
runasroot tar -xzf ${database}/raw/aur.files.tar.gz -C ${database}/local/
runasroot ln -s ${database}/raw/aur.db.tar.gz $pacmandb 2>/dev/null
}

# Update AUR pkgfile database
aurpkgfile() {
pkgdir=$(mktemp -d)

if [[ -d ${database}/local ]]; then
cd ${database}/local
aurlist=$(ls)
for aurpkg in $aurlist; do
grep -v "^%" $aurpkg/files | sed 's/^/\//' > $pkgdir/$aurpkg
done
fi

cd "$pkgdir"
runasroot tar -czf ${database}/raw/pkgfile.tar.gz *
cd - >/dev/null
rm -r "$pkgdir"
runasroot ln -s ${database}/raw/pkgfile.tar.gz "$pkgfiledb" 2>/dev/null
echo -e "${COLOR5}::${COLOR1} Updated AUR database${ENDCOLOR}"
}

# Update local AUR database ($1 is package, $2 is filename)
aurlocaldb() {
if [[ $nodatabase ]]; then
return
elif [[ ! -d $database ]] || [[ ! -f $pacmandb ]]; then
runasroot mkdir -p ${database}/{local,raw}
echo -e "${COLOR5}::${COLOR1} Checking AUR database${ENDCOLOR}"
savecount=$(ls $savedir 2>/dev/null | wc -l)
if [[ $savecount -gt 0 ]]; then
echo -e "${COLOR7}warning:${ENDCOLOR} need to run ${COLOR1}apacman --gendb${ENDCOLOR} (found $savecount AUR files!)"
else
runasroot repo-add -q ${database}/raw/aur.db.tar.gz 2>/dev/null
runasroot ln -s ${database}/raw/aur.db.tar.gz $pacmandb 2>/dev/null
fi
fi

runasroot repo-add -q ${database}/raw/aur.db.tar.gz "$2" 2>/dev/null
pkgnamever=$(echo "$2" | awk -F "$savedir/" '{print $2}' | sed "s/-any.pkg.tar.*//g;s/-${makearch}.pkg.tar.*//g")
runasroot tar -C ${database}/local/ -x "$pkgnamever/" -zf ${database}/raw/aur.files.tar.gz &&
aurpkgfile
}

# List bundle package files
listbundle() {
if [[ $bundle ]]; then
Expand Down Expand Up @@ -610,20 +676,22 @@ buildstatus() {
buildinstall() {
if [[ $2 = dependency ]]; then
runasroot $PACMAN ${PACOPTS[@]} --asdeps -U "$3"
aurlocaldb "$1" "$3"
[[ $buildonly = 1 ]] && bundle+=("$3")
[[ $buildonly = 1 ]] && purgedeps+=("$1")
elif [[ $2 = explicit ]]; then
[[ $buildonly = 1 ]] && echo -e "${COLOR6}notice:${ENDCOLOR} $1 built -- not installing"
[[ $buildonly = 1 ]] && bundle+=("$3")
[[ $buildonly != 1 ]] && progress "Installing ${pkgnum}/${totalcount} $1"
[[ $buildonly != 1 ]] && runasroot $PACMAN ${PACOPTS[@]} -U "$3"
[[ $buildonly != 1 ]] && aurlocaldb "$1" "$3"
fi
}

# Checks if aur cache is newer than aur ($1 is package, $2 is aur version)
checkvcs() {
cachefile=$(ls -t ${savedir}/${1}-*-{any,${makearch}}.pkg.{tar,tar.xz} 2>/dev/null | awk NR==1 | awk -F "${savedir}/${1}-" '{print $2}');
cachever=$(echo "$cachefile" | sed "s/-any.pkg.tar.xz//g;s/-any.pkg.tar//g;s/-${makearch}.pkg.tar.xz//g;s/-${makearch}.pkg.tar//g");
cachever=$(echo "$cachefile" | sed "s/-any.pkg.tar.*//g;s/-${makearch}.pkg.tar.*//g");
if [[ "$(LC_ALL=C vercmp "$cachever" "$2")" -gt 0 ]]; then
echo -e "${COLOR7}warning:${ENDCOLOR} $1 -- ${COLOR7}verify cache newer than AUR${ENDCOLOR} ($pkgver-$pkgrel)"
pkgfile="${savedir}/${1}-${cachefile}";
Expand Down Expand Up @@ -827,6 +895,25 @@ aurinstall() {
fi
}

# Passthrough for pkgfile
pkgfilehandling() {
if ! deptest pkgfile; then
err "${COLOR7}error:${ENDCOLOR} $1 requires \`pkgfile'"
return
fi

if [[ ! -f $pacmandb ]]; then
echo -e "${COLOR7}warning:${ENDCOLOR} need to run ${COLOR1}apacman --gendb${ENDCOLOR}"
fi

if [[ $1 = -P* ]] && [[ $1 != -P ]]; then
Parg=$(echo $1 | sed 's/P//g')
fi

shift
pkgfile -C <(cat $pacmanconf | sed "$ a [$localrepo]") $Parg "$@"
}

# Install local packages (-U)
localhandling() {
pacmanarg="$1"
Expand Down Expand Up @@ -1072,6 +1159,10 @@ pacwrap() {
$pacmanbin "$@";
elif [[ $1 = -U* ]]; then
localhandling "$@"
elif [[ $1 = -P* ]]; then
pkgfilehandling "$@";
elif [[ $1 = --pkgfile ]]; then
pkgfilehandling "$@";
else
runasroot $pacmanbin "$@";
fi;
Expand Down Expand Up @@ -1103,6 +1194,7 @@ while [[ $1 ]]; do
'--devel') devel='1' ;;
'--edit') unset noedit ;;
'--force') force='1' PACOPTS+=("--force");;
'--gendb') option=gendb ; escaperope='1' ;;
'--ignore') ignorearg="$2" ; PACOPTS+=("--ignore" "$2") ; shift ;;
'--ignorearch') MAKEPKGOPTS+=("--ignorearch");;
'--keepkeys') keepkeys='1' ; export keepkeys ;;
Expand All @@ -1111,11 +1203,13 @@ while [[ $1 ]]; do
'--needed') needed='1' PACOPTS+=("--needed");;
'--noaur') noaur='1' ; unset auronly ;;
'--noconfirm') noconfirm='1' PACOPTS+=("--noconfirm") ; export noconfirm ;;
'--nodatabase') nodatabase='1' ;;
'--noedit') noedit='1' ;;
'--nofail') nofail='1' ;;
'--noprogress') unset progress ;;
'--nosource') nosource='1' ;;
'--notify') progress='2' ;;
'--pkgfile') pacwrap "$@" ;;
'--preview') preview='1' ;;
'--progress') progress='1' ;;
'--purgebuild') purgebuild='1' ;;
Expand All @@ -1131,6 +1225,7 @@ while [[ $1 ]]; do
'-V'|'--version') version ;;
'--') shift ; packageargs+=("$@") ; break ;;
-D*) pacwrap "$@" ;;
-P*) pacwrap "$@" ;;
-Q*) pacwrap "$@" ;;
-R*) pacwrap "$@" ;;
-S*) pacwrap "$@" ;;
Expand Down Expand Up @@ -1162,6 +1257,12 @@ fi
[[ $escaperope != 1 && -z $packageargs ]] && err "${COLOR7}error:${ENDCOLOR} must specify a package."
[[ $auronly && $noaur ]] && err "Parameters --auronly and --noaur conflict."

# Generate DB (--gendb) handling
if [[ $option = gendb ]]; then
aurgendb
exit
fi

# List (-L) handling
if [[ $option = list ]]; then
getlistpackages
Expand Down
Loading

0 comments on commit 7893814

Please sign in to comment.