Advertisement
Guest User

Packer Abs

a guest
Mar 2nd, 2012
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.56 KB | None | 0 0
  1. --- packer.old/packer 2012-02-25 03:49:45.000000000 -0800
  2. +++ packer.new/packer 2012-02-25 03:28:49.088184439 -0800
  3. @@ -23,6 +23,8 @@
  4. makepkgconf='/etc/makepkg.conf'
  5. usermakepkgconf="$HOME/.makepkg.conf"
  6. pacmanconf='/etc/pacman.conf'
  7. +absconf='/etc/abs.conf'
  8. +userabsconf='~.abs.conf'
  9.  
  10. RPCURL="https://aur.archlinux.org/rpc.php?type"
  11. PKGURL="https://aur.archlinux.org"
  12. @@ -56,6 +58,7 @@
  13. echo
  14. echo ' -S - installs package'
  15. echo ' -Syu|-Su - updates all packages, also takes -uu and -yy options'
  16. + echo ' -Sb - builds from ABS; use the ABSPKG variable for updates'
  17. echo ' -Ss|-Ssq - searches for package'
  18. echo ' -Si - outputs info for package'
  19. echo ' -G - download and extract aur tarball only'
  20. @@ -89,6 +92,12 @@
  21. [[ -r "$usermakepkgconf" ]] && . "$usermakepkgconf"
  22. }
  23.  
  24. +# Source abs.conf file
  25. +sourceabsconf() {
  26. + . "$absconf"
  27. + [[ -r "$userabsconf" ]] && . "$userabsconf"
  28. +}
  29. +
  30. # Parse IgnorePkg and --ignore, put in globally accessible ignoredpackages array
  31. getignoredpackages() {
  32. IFS=',' read -ra ignoredpackages <<< "$ignorearg"
  33. @@ -108,7 +117,7 @@
  34.  
  35. # Tests whether $1 exists in pacman
  36. existsinpacman() {
  37. - pacman -Si -- "$1" &>/dev/null
  38. + $PACMAN -Si -- "$1" &>/dev/null
  39. }
  40.  
  41. # Tests whether $1 is provided in pacman, sets globally accessibly providepkg var
  42. @@ -118,23 +127,79 @@
  43.  
  44. # Tests whether $1 exists in a pacman group
  45. existsinpacmangroup() {
  46. - [[ $(pacman -Sgq "$1") ]]
  47. + [[ $($PACMAN -Sgq "$1") ]]
  48. }
  49.  
  50. # Tests whether $1 exists locally
  51. existsinlocal() {
  52. - pacman -Qq -- "$1" &>/dev/null
  53. + $PACMAN -Qq -- "$1" &>/dev/null
  54. +}
  55. +
  56. +# Runs customizepkg on AUR/ABS PKGBUILDs to ensure accurate deps
  57. +custdeps() {
  58. + if [[ -f "/etc/customizepkg.d/$1" ]] && type -t customizepkg &>/dev/null; then
  59. + mkdir "$tmpdir/$1"
  60. + mv "$tmpdir/$1.PKGBUILD" "$tmpdir/$1/PKGBUILD"
  61. + cd "$tmpdir/$1"
  62. + customizepkg --modify &>/dev/null
  63. + mv "$tmpdir/$1/PKGBUILD" "$tmpdir/$1.PKGBUILD"
  64. + cd "$tmpdir"
  65. + rm -rf "$tmpdir/$1"
  66. + fi
  67. }
  68.  
  69. # Scrapes the aur deps from PKGBUILDS and puts in globally available dependencies array
  70. scrapeaurdeps() {
  71. pkginfo "$1"
  72. + custdeps "$1"
  73. . "$tmpdir/$1.PKGBUILD"
  74. IFS=$'\n'
  75. dependencies=( $(echo -e "${depends[*]}\n${makedepends[*]}" | sed -e 's/=.*//' -e 's/>.*//' -e 's/<.*//'| sort -u) )
  76. unset IFS
  77. }
  78.  
  79. +# Gets ABS PKGBUILD
  80. +absinfo() {
  81. + if ! [[ -f "$tmpdir/$1.PKGBUILD" ]]; then
  82. + sourceabsconf
  83. + if existsinpacman $1; then
  84. + pkgrepo="$($PACMAN -Si -- "$1" 2>/dev/null | sed -e 's/Repository : //g' -e '1q;d')"
  85. + if [[ -n "$pkgrepo" && "${REPOS[*]}" =~ "$pkgrepo" ]]; then
  86. + if ! rsync -mrtvq --no-motd --no-p --no-o --no-g "$SYNCSERVER::abs/$ARCH/$pkgrepo/$1/PKGBUILD" "$tmpdir/$1.PKGBUILD"; then
  87. + abserr=1
  88. + fi
  89. + else
  90. + err "Could not determine repo!"
  91. + fi
  92. + else
  93. + err "Package does not exist in pacman!"
  94. + fi
  95. + fi
  96. +}
  97. +
  98. +# Scrapes the deps from abs PKGBUILDS and puts in globally available dependencies array
  99. +scrapeabsdeps() {
  100. + absinfo $1 PKGBUILD
  101. + custdeps "$1"
  102. + . "$tmpdir/$1.PKGBUILD"
  103. + IFS=$'\n'
  104. + dependencies=( $(echo -e "${depends[*]}\n${makedepends[*]}" | sed -e 's/=.*//' -e 's/>.*//' -e 's/<.*//'| sort -u) )
  105. + unset IFS
  106. +}
  107. +
  108. +# Gets the version from the pkgbuild.
  109. +scrapeabsver() {
  110. + if [ -e "$tmpdir/$1.PKGBUILD" ]; then
  111. + rm -f "$tmpdir/$1.PKGBUILD"
  112. + fi
  113. + absinfo $1 PKGBUILD
  114. + if [ -z "$abserr" ]; then
  115. + custdeps "$1"
  116. + . "$tmpdir/$1.PKGBUILD"
  117. + version=${pkgver}-${pkgrel}
  118. + fi
  119. +}
  120. +
  121. # Finds dependencies of package $1
  122. # Sets pacmandeps and aurdeps array, which can be accessed globally after function runs
  123. finddeps() {
  124. @@ -142,7 +207,7 @@
  125. pacmandeps=()
  126. aurdeps=()
  127. scrapeaurdeps "$1"
  128. - missingdeps=( $(pacman -T "${dependencies[@]}") )
  129. + missingdeps=( $($PACMAN -T "${dependencies[@]}") )
  130. while [[ $missingdeps ]]; do
  131. checkdeps=()
  132. for dep in "${missingdeps[@]}"; do
  133. @@ -170,7 +235,48 @@
  134. for dep in "${checkdeps[@]}"; do
  135. scrapeaurdeps "$dep"
  136. for depdep in "${dependencies[@]}"; do
  137. - [[ $(pacman -T "$depdep") ]] && missingdeps+=("$depdep")
  138. + [[ $($PACMAN -T "$depdep") ]] && missingdeps+=("$depdep")
  139. + done
  140. + done
  141. + done
  142. + return 0
  143. +}
  144. +
  145. +# Finds dependencies of package $1 (ABS packages)
  146. +findabsdeps() {
  147. + # loop through dependencies, if not installed, determine if pacman or aur deps
  148. + pacmandeps=()
  149. + aurdeps=()
  150. + scrapeabsdeps "$1"
  151. + missingdeps=( $($PACMAN -T "${dependencies[@]}") )
  152. + while [[ $missingdeps ]]; do
  153. + checkdeps=()
  154. + for dep in "${missingdeps[@]}"; do
  155. + if [[ " $1 ${aurdeps[@]} ${pacmandeps[@]} " =~ " $dep " ]]; then
  156. + continue
  157. + fi
  158. + if existsinpacman "$dep"; then
  159. + pacmandeps+=("$dep")
  160. + elif existsinaur "$dep"; then
  161. + if [[ $aurdeps ]]; then
  162. + aurdeps=("$dep" "${aurdeps[@]}")
  163. + else
  164. + aurdeps=("$dep")
  165. + fi
  166. + checkdeps+=("$dep")
  167. + elif providedinpacman "$dep"; then
  168. + pacmandeps+=("$providepkg")
  169. + else
  170. + [[ $option = "install" ]] && err "Dependency \`$dep' of \`$1' does not exist."
  171. + echo "Dependency \`$dep' of \`$1' does not exist."
  172. + return 1
  173. + fi
  174. + done
  175. + missingdeps=()
  176. + for dep in "${checkdeps[@]}"; do
  177. + scrapeabsdeps "$dep"
  178. + for depdep in "${dependencies[@]}"; do
  179. + [[ $($PACMAN -T "$depdep") ]] && missingdeps+=("$depdep")
  180. done
  181. done
  182. done
  183. @@ -236,8 +342,8 @@
  184.  
  185. pkginfo() {
  186. if ! [[ -f "$tmpdir/$1.PKGBUILD" ]]; then
  187. - pkgpath=$(pkglink $1)
  188. - curl -Lfs "${pkgpath%/*}/PKGBUILD" > "$tmpdir/$1.PKGBUILD"
  189. + pkgpath=$(pkglink $1)
  190. + curl -Lfs "${pkgpath%/*}/PKGBUILD" > "$tmpdir/$1.PKGBUILD"
  191. fi
  192. }
  193.  
  194. @@ -319,6 +425,64 @@
  195. fi
  196. }
  197.  
  198. +# Gets ABS PKGBUILD, $1 is package name
  199. +getabspkgbuild() {
  200. + sourceabsconf
  201. + pkgrepo="$($PACMAN -Si -- "$1" 2>/dev/null | sed -e 's/Repository : //g' -e '1q;d')"
  202. + if [[ -n "$pkgrepo" && "${REPOS[*]}" =~ "$pkgrepo" ]]; then
  203. + rsync -mrtvq --no-motd --no-p --no-o --no-g "$SYNCSERVER::abs/$ARCH/$pkgrepo/$1/" .
  204. + else
  205. + err "Could not determine repo!"
  206. + fi
  207. +}
  208. +
  209. +# Installs packages from aur ($1 is package, $2 is dependency or explicit)
  210. +absinstall() {
  211. + dir="${TMPDIR:-/tmp}/packerbuild-$UID/$1"
  212. +
  213. + # Prepare the installation directory
  214. + # If there is an old directory delete it.
  215. + [[ -d $dir ]] && rm -rf $dir
  216. + mkdir -p "$dir"
  217. + cd "$dir"
  218. + mkdir "$1"
  219. + cd "$1"
  220. + getabspkgbuild "$1"
  221. +
  222. + # customizepkg
  223. + if [[ -f "/etc/customizepkg.d/$1" ]] && type -t customizepkg &>/dev/null; then
  224. + echo "Applying customizepkg instructions..."
  225. + customizepkg --modify
  226. + fi
  227. + #fi
  228. +
  229. + # Allow user to edit PKGBUILD
  230. + confirm_edit "${COLOR6}Edit $1 PKGBUILD with \$EDITOR? [Y/n]${ENDCOLOR} " PKGBUILD
  231. + if ! [[ -f PKGBUILD ]]; then
  232. + err "No PKGBUILD found in directory."
  233. + fi
  234. +
  235. + # Allow user to edit .install
  236. + unset install
  237. + . PKGBUILD
  238. + confirm_edit "${COLOR6}Edit $install with \$EDITOR? [Y/n]${ENDCOLOR} " "$install"
  239. +
  240. + # Installation (makepkg and pacman)
  241. + if [[ $UID -eq 0 ]]; then
  242. + makepkg $MAKEPKGOPTS --asroot -f
  243. + else
  244. + makepkg $MAKEPKGOPTS -f
  245. + fi
  246. +
  247. +
  248. + [[ $? -ne 0 ]] && echo "The build failed." && return 1
  249. + if [[ $2 = dependency ]]; then
  250. + runasroot $PACMAN ${PACOPTS[@]} --asdeps -U $pkgname-*$PKGEXT
  251. + elif [[ $2 = explicit ]]; then
  252. + runasroot $PACMAN ${PACOPTS[@]} -U $pkgname-*$PKGEXT
  253. + fi
  254. +}
  255. +
  256. # Goes through all of the install tests and execution ($@ is packages to be installed)
  257. installhandling() {
  258. packageargs=("$@")
  259. @@ -326,8 +490,15 @@
  260. sourcemakepkgconf
  261. # Figure out all of the packages that need to be installed
  262. for package in "${packageargs[@]}"; do
  263. + # Determine if repo package is to be built from source
  264. + if ! [[ $auronly ]] && existsinpacman "$package" && [[ $abs = yes ]] ; then
  265. + if findabsdeps "$package"; then
  266. + # here is where dep dupes are created
  267. + abspackages+=("$package")
  268. + pacmandepends+=("${pacmandeps[@]}")
  269. + fi
  270. # Determine whether package is in pacman repos
  271. - if ! [[ $auronly ]] && existsinpacman "$package"; then
  272. + elif ! [[ $auronly ]] && existsinpacman "$package"; then
  273. pacmanpackages+=("$package")
  274. elif ! [[ $auronly ]] && existsinpacmangroup "$package"; then
  275. pacmanpackages+=("$package")
  276. @@ -370,13 +541,14 @@
  277. if [[ $pacmanpackages ]]; then
  278. runasroot $PACMAN "${PACOPTS[@]}" -S -- "${pacmanpackages[@]}"
  279. fi
  280. - if [[ -z $aurtargets ]]; then
  281. + if [[ -z $aurtargets && -z $abspackages ]]; then
  282. exit
  283. fi
  284. +
  285. # Test if aurpackages are already installed; echo warning if so
  286. for pkg in "${aurtargets[@]}"; do
  287. if existsinlocal "$pkg"; then
  288. - localversion="$(pacman -Qs "$pkg" | grep -F "local/$pkg" | cut -d ' ' -f 2)"
  289. + localversion="$($PACMAN -Qs "$pkg" | grep -F "local/$pkg" | cut -d ' ' -f 2)"
  290. if ! aurversionisnewer "$pkg" "$localversion"; then
  291. echo -e "${COLOR6}warning:$ENDCOLOR $pkg-$localversion is up to date -- reinstalling"
  292. fi
  293. @@ -395,9 +567,12 @@
  294. if [[ $aurdepends ]]; then
  295. num="$((${#aurdepends[@]}+${#aurtargets[@]}))"
  296. echo -e "${COLOR6}Aur Targets ($num):${ENDCOLOR} ${aurdepends[@]} ${aurtargets[@]}"
  297. - else
  298. + elif [[ $aurtargets ]]; then
  299. echo -e "${COLOR6}Aur Targets ($((${#aurtargets[@]}))):${ENDCOLOR} ${aurtargets[@]}"
  300. fi
  301. + if [[ $abspackages ]]; then
  302. + echo -e "${COLOR6}Abs Targets ($((${#abspackages[@]}))):${ENDCOLOR} ${abspackages[@]}"
  303. + fi
  304. if [[ $pacmandepends ]]; then
  305. IFS=$'\n' read -rd '' -a pacmandepends < \
  306. <(printf "%s\n" "${pacmandepends[@]}" | sort -u)
  307. @@ -425,14 +600,28 @@
  308. fi
  309.  
  310. # Install the aur packages
  311. - for package in "${aurtargets[@]}"; do
  312. - scrapeaurdeps "$package"
  313. - if pacman -T "${dependencies[@]}" &>/dev/null; then
  314. - aurinstall "$package" "explicit"
  315. - else
  316. - echo "Dependencies for \`$package' are not met, not building..."
  317. - fi
  318. - done
  319. + if [[ $aurtargets ]]; then
  320. + for package in "${aurtargets[@]}"; do
  321. + scrapeaurdeps "$package"
  322. + if $PACMAN -T "${dependencies[@]}" &>/dev/null; then
  323. + aurinstall "$package" "explicit"
  324. + else
  325. + echo "Dependencies for \`$package' are not met, not building..."
  326. + fi
  327. + done
  328. + fi
  329. +
  330. + # Install the abs packages
  331. + if [[ $abspackages ]]; then
  332. + for package in "${abspackages[@]}"; do
  333. + scrapeabsdeps "$package"
  334. + if $PACMAN -T "${dependencies[@]}" &>/dev/null; then
  335. + absinstall "$package" "explicit"
  336. + else
  337. + echo "Dependencies for \`$package' are not met, not building..."
  338. + fi
  339. + done
  340. + fi
  341. }
  342.  
  343. # proceed with installation prompt
  344. @@ -458,6 +647,7 @@
  345. while [[ $1 ]]; do
  346. case "$1" in
  347. '-S') option=install ;;
  348. + '-Sb') option=install ; abs=yes ;;
  349. '-Ss') option=search ;;
  350. '-Ssq'|'-Sqs') option=search ; quiet='1' ;;
  351. '-Si') option=info ;;
  352. @@ -472,7 +662,8 @@
  353. '--devel') devel='1' ;;
  354. '--skipinteg') MAKEPKGOPTS="--skipinteg" ;;
  355. '--') shift ; packageargs+=("$@") ; break ;;
  356. - -*) echo "packer: Option \`$1' is not valid." ; exit 5 ;;
  357. + -Q*) $PACMAN $@; exit 5;;
  358. + -*) runasroot $PACMAN $@; exit 5;;
  359. *) packageargs+=("$1") ;;
  360. esac
  361. shift
  362. @@ -492,11 +683,40 @@
  363. if [[ $option = update ]]; then
  364. getignoredpackages
  365. sourcemakepkgconf
  366. +
  367. + # Abs update
  368. + if [[ "$ABSPKGS" ]]; then
  369. + echo -e "${COLOR5}:: ${COLOR1}Checking ABS Packages...${ENDCOLOR}"
  370. + absarray=($ABSPKGS)
  371. + absupdate=()
  372. + for i in ${absarray[@]}; do
  373. + instver="$($PACMAN -Qi -- "$i" 2>/dev/null | sed -e 's/Version : //g' -e '2q;d')"
  374. + scrapeabsver $i
  375. + if [ "$abserr" = 1 ]; then
  376. + echo "Error while checking ABS Packages!"
  377. + echo
  378. + absupdate=""
  379. + break
  380. + fi
  381. + if [ $(vercmp $version $instver) -gt 0 ]; then
  382. + absupdate+=("$i")
  383. + fi
  384. + done
  385. + if [[ "$absupdate" ]]; then
  386. + abs=yes
  387. + installhandling "${absupdate[@]}"
  388. + unset abs
  389. + else
  390. + absignore=$(echo "$ABSPKGS" | tr ' ' ',')
  391. + PACOPTS+=("--ignore" "$absignore")
  392. + fi
  393. + fi
  394. +
  395. # Pacman update
  396. if ! [[ $auronly ]]; then
  397. runasroot $PACMAN "${PACOPTS[@]}" "$pacmanarg"
  398. fi
  399. -
  400. +
  401. # Aur update
  402. echo -e "${COLOR5}:: ${COLOR1}Synchronizing aur database...${ENDCOLOR}"
  403. IFS=$'\n' read -rd '' -a packages < <(pacman -Qm)
  404. @@ -592,18 +812,26 @@
  405. # Pacman searching
  406. if ! [[ $auronly ]]; then
  407. if [[ $quiet ]]; then
  408. - results="$(pacman -Ssq -- "${packageargs[@]}")"
  409. + results="$($PACMAN -Ssq -- "${packageargs[@]}")"
  410. else
  411. - results="$(pacman -Ss -- "${packageargs[@]}")"
  412. + results="$($PACMAN -Ss -- "${packageargs[@]}")"
  413. + # Repo
  414. results="$(sed -r "s|^[^ ][^/]*/|$S${COLOR3}&$S${COLOR1}|" <<< "$results")"
  415. + # Package
  416. results="$(sed -r "s|^([^ ]+) ([^ ]+)(.*)$|\1 $S${COLOR2}\2$S${ENDCOLOR}\3|" <<< "$results")"
  417. + # Group
  418. + results="$(sed -r "s|^([^ ]+ [^ ]+ \[.*\]) (\(.*\))(.*)$|\1 $S${COLOR5}\2$S${ENDCOLOR}\3|" <<< "$results")"
  419. + # Status
  420. + results="$(sed -r "s|^([^ ]+ [^ ]+ \[.*\].*) (\[.*\])$|\1 $S${COLOR4}\2$S${ENDCOLOR}|" <<< "$results")"
  421. + fi
  422. + if [ "$results" ]; then
  423. + if [[ $option = search ]]; then
  424. + echo -e "$results" | fmt -"$_WIDTH" -s
  425. + else # interactive
  426. + echo -e "$results" | fmt -"$_WIDTH" -s | nl -v 0 -w 1 -s ' ' -b 'p^[^ ]'
  427. + fi | sed '/^$/d'
  428. fi
  429. - if [[ $option = search ]]; then
  430. - echo -e "$results" | fmt -"$_WIDTH" -s
  431. - else # interactive
  432. - echo -e "$results" | fmt -"$_WIDTH" -s | nl -v 0 -w 1 -s ' ' -b 'p^[^ ]'
  433. - fi | sed '/^$/d'
  434. - pacname=( $(pacman -Ssq -- "${packageargs[@]}") )
  435. + pacname=( $($PACMAN -Ssq -- "${packageargs[@]}") )
  436. pactotal="${#pacname[@]}"
  437. else
  438. pactotal=0
  439. @@ -687,7 +915,7 @@
  440. sourcemakepkgconf
  441. for package in "${packageargs[@]}"; do
  442. if ! [[ $auronly ]] && existsinpacman "$package"; then
  443. - results="$(pacman -Si -- "$package")"
  444. + results="$($PACMAN -Si -- "$package")"
  445. results="$(sed -r "s|^(Repository[^:]*:)(.*)$|\1$S${COLOR3}\2$S${ENDCOLOR}|" <<< "$results")"
  446. results="$(sed -r "s|^(Name[^:]*:)(.*)$|\1$S${COLOR1}\2$S${ENDCOLOR}|" <<< "$results")"
  447. results="$(sed -r "s|^(Version[^:]*:)(.*)$|\1$S${COLOR2}\2$S${ENDCOLOR}|" <<< "$results")"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement