]>
Commit | Line | Data |
---|---|---|
3815fa0c MF |
1 | #!/bin/bash |
2 | ||
9db26d84 | 3 | GS_SYNC=true |
3815fa0c MF |
4 | GS_RSYNC=false |
5 | GS_EUPDATEDB=true | |
6 | GS_FETCH=false | |
7 | GS_UPWORLD=true | |
d3768020 | 8 | GS_LAYMAN=true |
603039f0 | 9 | GS_DEBUG=false |
3815fa0c MF |
10 | conf="/etc/gentoo-sync.conf" |
11 | [[ -e ${conf} ]] && . "${conf}" | |
12 | ||
6ef68d0c MF |
13 | bootstrap() { |
14 | [[ $(id -u) -eq 0 ]] || exec sudo env -uUNSHARE HOME="$HOME" "$0" "$@" | |
15 | ||
16 | if [[ -z ${UNSHARE} ]] ; then | |
17 | mount_args= | |
18 | if type -P unshare >&/dev/null ; then | |
19 | test_arg() { unshare "$@" -- true >&/dev/null && uargs+=( "$@" ) || :; } | |
20 | uargs=( -m ) | |
21 | test_arg -u | |
22 | test_arg -i | |
23 | test_arg -p -f --mount-proc | |
24 | test_arg --propagation=private | |
25 | UNSHARE=true exec unshare "${uargs[@]}" -- "$0" "$@" | |
26 | fi | |
27 | else | |
28 | mount_args='-n' | |
29 | fi | |
30 | unset UNSHARE | |
31 | } | |
32 | bootstrap "$@" | |
33 | ||
603039f0 MF |
34 | usage() { |
35 | cat <<-EOF | |
36 | Usage: ${0##*/} [options] | |
37 | ||
38 | Options: | |
39 | -h, --help | |
40 | -a, --all, -na, --noall | |
41 | -s, --sync, -ns, --nosync ${GS_SYNC} | |
42 | -r, --rsync, -nr, --norsync ${GS_RSYNC} | |
43 | -d, --database, -nd, --nodatabase ${GS_EUPDATEDB} | |
44 | -f, --fetch, -nf, --nofetch ${GS_FETCH} | |
45 | -w, --world, -nw, --noworld ${GS_UPWORLD} | |
46 | -l, --layman, -nl, --nolayman ${GS_LAYMAN} | |
47 | -x, --debug, -nx, --nodebug ${GS_DEBUG} | |
48 | EOF | |
49 | exit 0 | |
50 | } | |
51 | ||
52 | s() { | |
53 | local x val=$1 | |
54 | shift | |
55 | for x ; do | |
56 | eval GS_${x}=${val}; | |
57 | done | |
58 | } | |
59 | for x ; do | |
60 | case ${x} in | |
61 | -h|--help) usage;; | |
62 | -a|--all) s true SYNC RSYNC EUPDATEDB FETCH UPWORLD LAYMAN DEBUG;; | |
63 | -na|--noall) s false SYNC RSYNC EUPDATEDB FETCH UPWORLD LAYMAN DEBUG;; | |
64 | -s|--sync) s true SYNC;; | |
65 | -ns|--nosync) s false SYNC;; | |
66 | -r|--rsync) s true RSYNC;; | |
67 | -nr|--norsync) s false RSYNC;; | |
68 | -d|--database) s true EUPDATEDB;; | |
69 | -nd|--nodatabase) s false EUPDATEDB;; | |
70 | -f|--fetch) s true FETCH;; | |
71 | -nf|--nofetch) s false FETCH;; | |
72 | -w|--world) s true UPWORLD;; | |
73 | -nw|--noworld) s false UPWORLD;; | |
74 | -l|--layman) s true LAYMAN;; | |
75 | -nl|--nolayman) s false LAYMAN;; | |
76 | -x|--debug) s true DEBUG;; | |
77 | -nx|--nodebug) s false DEBUG;; | |
78 | *) usage;; | |
79 | esac | |
80 | done | |
81 | ||
603039f0 MF |
82 | ${GS_DEBUG} && set -x |
83 | ||
84 | logdir="/var/log" | |
85 | sync_log="${logdir}/rsync.log" | |
86 | up_log="${logdir}/emerge-updates.log" | |
87 | ||
3815fa0c MF |
88 | export NOCOLOR=true |
89 | ||
90 | ( | |
91 | date | |
92 | ||
93 | if ${GS_RSYNC} ; then | |
94 | # For slow systems, run rsync directly. | |
95 | for f in make.globals make.conf ; do | |
96 | for d in /etc /etc/portage /usr/share/portage/config ; do | |
97 | f="${d}/make.globals" | |
98 | [[ -e ${f} ]] && . ${f} && break | |
99 | done | |
100 | done | |
d144418d | 101 | > "${up_log}" |
3815fa0c MF |
102 | : ${PORTAGE_RSYNC_OPTS:=-azO --delete --exclude=/distfiles --exclude=/local --exclude=/packages} |
103 | : ${SYNC:=rsync://rsync.gentoo.org/gentoo-portage} | |
104 | : ${PORTDIR:=/usr/portage} | |
d144418d | 105 | exec rsync ${PORTAGE_RSYNC_OPTS} ${PORTAGE_RSYNC_EXTRA_OPTS} ${SYNC}/ ${PORTDIR}/ >& "${sync_log}" |
3815fa0c MF |
106 | fi |
107 | ||
9db26d84 MF |
108 | if ${GS_SYNC} ; then |
109 | emerge --sync -q | |
110 | date | |
111 | ${GS_EUPDATEDB} && $(type -P eupdatedb) | |
112 | date | |
113 | ${GS_LAYMAN} && l=$(type -P layman) && ${l} -S -q | |
114 | date | |
115 | ${GS_FETCH} && emerge world -Duf | |
116 | #q -qr | |
117 | fi | |
118 | ||
3815fa0c MF |
119 | date |
120 | ) >& ${sync_log} | |
121 | ||
122 | if ${GS_UPWORLD} ; then | |
123 | ( | |
047f042e MF |
124 | repos=( |
125 | $(portageq repositories_configuration / | awk '$1 == "location" { $1 = $2 = ""; print }') | |
126 | ) | |
9db26d84 MF |
127 | bad_pkgs=() |
128 | good_pkgs=() | |
129 | for p in `qlist -ICS` ; do | |
047f042e MF |
130 | good=false |
131 | for repo in ${repos[@]} ; do | |
132 | if [[ -d ${repo}/${p%:*} ]] ; then | |
133 | good=true | |
134 | break | |
135 | fi | |
136 | done | |
137 | ||
138 | if ${good} ; then | |
9db26d84 MF |
139 | good_pkgs+=( ${p} ) |
140 | else | |
141 | bad_pkgs+=( ${p} ) | |
142 | fi | |
143 | done | |
047f042e | 144 | |
9db26d84 MF |
145 | if [[ ${#bad_pkgs[@]} -gt 0 ]] ; then |
146 | echo 'These packages no longer exist:' | |
147 | printf '\t%s\n' "${bad_pkgs[@]}" | |
148 | echo | |
149 | fi | |
d4aab056 | 150 | echo 'emerge -u1v --quiet-build y --keep-going $(awk '\''$2 ~ /\// {print $2}'\'' '${up_log}')' |
047f042e MF |
151 | emerge -upq --cols \ |
152 | $(printf '%s\n' ${good_pkgs[*]} | grep -v '^cross-') | |
3815fa0c MF |
153 | ) >& ${up_log} |
154 | fi |