]> git.wh0rd.org - home.git/blob - .bin/gentoo-sync
gentoo-sync: add an option for syncing, and do world update based on slot
[home.git] / .bin / gentoo-sync
1 #!/bin/bash
2
3 [ "${FLOCKER}" != "$0" ] && exec env FLOCKER="$0" flock -en "$0" "$0" "$@" || :
4
5 logdir="/var/log"
6 sync_log="${logdir}/rsync.log"
7 up_log="${logdir}/emerge-updates.log"
8
9 GS_SYNC=true
10 GS_RSYNC=false
11 GS_EUPDATEDB=true
12 GS_FETCH=false
13 GS_UPWORLD=true
14 GS_LAYMAN=true
15 conf="/etc/gentoo-sync.conf"
16 [[ -e ${conf} ]] && . "${conf}"
17
18 export NOCOLOR=true
19
20 (
21 date
22
23 if ${GS_RSYNC} ; then
24 # For slow systems, run rsync directly.
25 for f in make.globals make.conf ; do
26 for d in /etc /etc/portage /usr/share/portage/config ; do
27 f="${d}/make.globals"
28 [[ -e ${f} ]] && . ${f} && break
29 done
30 done
31 > "${up_log}"
32 : ${PORTAGE_RSYNC_OPTS:=-azO --delete --exclude=/distfiles --exclude=/local --exclude=/packages}
33 : ${SYNC:=rsync://rsync.gentoo.org/gentoo-portage}
34 : ${PORTDIR:=/usr/portage}
35 exec rsync ${PORTAGE_RSYNC_OPTS} ${PORTAGE_RSYNC_EXTRA_OPTS} ${SYNC}/ ${PORTDIR}/ >& "${sync_log}"
36 fi
37
38 if ${GS_SYNC} ; then
39 emerge --sync -q
40 date
41 ${GS_EUPDATEDB} && $(type -P eupdatedb)
42 date
43 ${GS_LAYMAN} && l=$(type -P layman) && ${l} -S -q
44 date
45 ${GS_FETCH} && emerge world -Duf
46 #q -qr
47 fi
48
49 date
50 ) >& ${sync_log}
51
52 if ${GS_UPWORLD} ; then
53 (
54 eval $(portageq envvar -v PORTDIR)
55 cd "${PORTDIR}"
56 bad_pkgs=()
57 good_pkgs=()
58 for p in `qlist -ICS` ; do
59 if [[ -d ${p%:*} ]] ; then
60 good_pkgs+=( ${p} )
61 else
62 bad_pkgs+=( ${p} )
63 fi
64 done
65 if [[ ${#bad_pkgs[@]} -gt 0 ]] ; then
66 echo 'These packages no longer exist:'
67 printf '\t%s\n' "${bad_pkgs[@]}"
68 echo
69 fi
70 echo 'emerge -u1 --keep-going $(awk '\''$2 ~ /\// {print $2}'\'' '${up_log}')'
71 emerge ${good_pkgs[*]} -upq --cols
72 ) >& ${up_log}
73 fi