OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 | 2 # This script is no longer needed. This stub is here to avoid immediate |
3 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 3 # buildbot breakage and will be removed soon. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 exit 0 |
5 # found in the LICENSE file. | |
6 | |
7 # Load common constants. This should be the first executable line. | |
8 # The path to common.sh should be relative to your script's location. | |
9 . "$(dirname "$0")/common.sh" | |
10 | |
11 # Script must be run outside the chroot and as a regular user. | |
12 assert_outside_chroot | |
13 assert_not_root_user | |
14 | |
15 DEFAULT_DEST="$GCLIENT_ROOT/repo" | |
16 DEFAULT_DEV_PKGLIST="$SRC_ROOT/package_repo/repo_list_dev.txt" | |
17 DEFAULT_IMG_PKGLIST="$SRC_ROOT/package_repo/repo_list_image.txt" | |
18 | |
19 # Command line options | |
20 DEFINE_string suite "$DEFAULT_EXT_SUITE" "Ubuntu suite to pull packages from." | |
21 DEFINE_string mirror "$DEFAULT_EXT_MIRROR" "Ubuntu repository mirror to use." | |
22 DEFINE_string mirror2 "" "Optional Chromium repository mirror to use." | |
23 DEFINE_string dest "$DEFAULT_DEST" "Destination directory for repository." | |
24 DEFINE_string devlist "$DEFAULT_DEV_PKGLIST" \ | |
25 "File listing packages to use for development." | |
26 DEFINE_string imglist "$DEFAULT_IMG_PKGLIST" \ | |
27 "File listing packages to use for image." | |
28 DEFINE_string devsuite "$DEFAULT_DEV_SUITE" "Dev suite to update." | |
29 DEFINE_string imgsuite "$DEFAULT_IMG_SUITE" "Image suite to update." | |
30 DEFINE_boolean updev $FLAGS_TRUE "Update development repository." | |
31 DEFINE_boolean upimg $FLAGS_TRUE "Update image repository." | |
32 | |
33 # Parse command line flags | |
34 FLAGS "$@" || exit 1 | |
35 eval set -- "${FLAGS_ARGV}" | |
36 | |
37 # Die on error | |
38 set -e | |
39 | |
40 # Architectures and sections to support in local mirror | |
41 REPO_ARCH="i386 armel" | |
42 REPO_SECTIONS="main restricted multiverse universe" | |
43 | |
44 # Where to store packages downloaded from external repository, inside the | |
45 # chroot. | |
46 DEB_CACHE_DIR="/var/cache/make_local_repo" | |
47 | |
48 CHROOT=`readlink -f $FLAGS_dest` | |
49 REPO_SUBDIR="apt" | |
50 REPO="$CHROOT/$REPO_SUBDIR" | |
51 | |
52 #------------------------------------------------------------------------------ | |
53 # Functions | |
54 | |
55 # Run a command in the chroot | |
56 function in_chroot { | |
57 sudo chroot "$CHROOT" "$@" | |
58 } | |
59 | |
60 # Run a bash command line in the chroot | |
61 function bash_chroot { | |
62 # Use $* not $@ since 'bash -c' needs a single arg | |
63 sudo chroot "$CHROOT" bash -c "$*" | |
64 } | |
65 | |
66 # Clean up chroot mount points | |
67 function cleanup_chroot_mounts { | |
68 # Clear the trap from setup_chroot_mounts, now that we're unmounting. | |
69 trap - EXIT | |
70 | |
71 mount | grep "on $(readlink -f "$CHROOT")" | awk '{print $3}' \ | |
72 | xargs -r -L1 sudo umount | |
73 } | |
74 | |
75 # Set up chroot mount points | |
76 function setup_chroot_mounts { | |
77 if [ ! -e "$CHROOT/proc" ]; then mkdir -p "$CHROOT/proc"; fi | |
78 sudo mount none -t proc "$CHROOT/proc" | |
79 if [ ! -e "$CHROOT/dev/pts" ]; then mkdir -p "$CHROOT/dev/pts"; fi | |
80 sudo mount none -t devpts "$CHROOT/dev/pts" | |
81 | |
82 # Make sure we clean up the mounts on exit | |
83 trap cleanup_chroot_mounts EXIT | |
84 } | |
85 | |
86 # Make a minimal chroot | |
87 function make_chroot { | |
88 echo "Creating chroot to build local package repository..." | |
89 mkdir -p "$CHROOT" | |
90 | |
91 # Install packages which may not be installed on the local system | |
92 install_if_missing debootstrap | |
93 | |
94 # Add debootstrap link for the suite, if it doesn't exist. | |
95 if [ ! -e "/usr/share/debootstrap/scripts/$FLAGS_suite" ] | |
96 then | |
97 sudo ln -s /usr/share/debootstrap/scripts/gutsy \ | |
98 "/usr/share/debootstrap/scripts/$FLAGS_suite" | |
99 fi | |
100 | |
101 # Run debootstrap | |
102 sudo debootstrap --arch=i386 --variant=minbase \ | |
103 --include=gnupg \ | |
104 "$FLAGS_suite" "$CHROOT" "$FLAGS_mirror" | |
105 | |
106 # Set up chroot mounts, since the package installs below need them | |
107 setup_chroot_mounts | |
108 | |
109 # Install packages into chroot | |
110 bash_chroot "echo deb $FLAGS_mirror $FLAGS_suite $REPO_SECTIONS \ | |
111 > /etc/apt/sources.list" | |
112 in_chroot apt-get update | |
113 in_chroot apt-get --yes --force-yes install reprepro wget | |
114 | |
115 # Clean up chroot mounts | |
116 cleanup_chroot_mounts | |
117 } | |
118 | |
119 # Create reprepro repository | |
120 function make_repo { | |
121 echo "Creating repository directory..." | |
122 sudo rm -rf "$REPO" | |
123 sudo mkdir -p "$REPO" | |
124 sudo chown $USER "$REPO" | |
125 mkdir -p "$REPO/conf" | |
126 mkdir -p "$REPO/incoming" | |
127 | |
128 # Create the distributions conf file | |
129 CONF="$REPO/conf/distributions" | |
130 rm -f "$CONF" | |
131 cat <<EOF > $CONF | |
132 Origin: $FLAGS_mirror | |
133 Label: Chrome OS Dev | |
134 Suite: stable | |
135 Codename: $FLAGS_devsuite | |
136 Version: 3.1 | |
137 Architectures: $REPO_ARCH | |
138 Components: $REPO_SECTIONS | |
139 Description: Chrome OS Development | |
140 | |
141 Origin: $FLAGS_mirror | |
142 Label: Chrome OS | |
143 Suite: stable | |
144 Codename: $FLAGS_imgsuite | |
145 Version: 3.1 | |
146 Architectures: $REPO_ARCH | |
147 Components: $REPO_SECTIONS | |
148 Description: Chrome OS Image | |
149 EOF | |
150 } | |
151 | |
152 # Update a suite in the repository from a list of packages | |
153 function update_suite { | |
154 SUITE="${1:?}" | |
155 PKGLIST="${2:?}" | |
156 | |
157 echo "Updating $SUITE from $PKGLIST..." | |
158 | |
159 # Clear the suite first | |
160 # Since packages are either source or not, this removes all of them. | |
161 in_chroot reprepro -b "$REPO_SUBDIR" removefilter "$SUITE" "!Source" | |
162 in_chroot reprepro -b "$REPO_SUBDIR" removefilter "$SUITE" "Source" | |
163 | |
164 # Add packages to the suite | |
165 echo "Downloading packages..." | |
166 grep -v '^#' < $PKGLIST | while read DEB DEB_VER DEB_PRIO DEB_SECTION DEB_PATH | |
167 do | |
168 [ -z "$DEB" ] && continue | |
169 echo "Adding $DEB..." | |
170 | |
171 DEB_FILE=$DEB_CACHE_DIR/${DEB_PATH##*/} | |
172 | |
173 # Download the package if necessary | |
174 if [ ! -s "$CHROOT/$DEB_FILE" ] | |
175 then | |
176 if [ -n "FLAGS_mirror2" ]; then | |
177 in_chroot wget --no-verbose "$FLAGS_mirror/${DEB_PATH}" -O "$DEB_FILE" |
| \ | |
178 in_chroot wget --no-verbose "$FLAGS_mirror2/${DEB_PATH}" -O "$DEB_FILE" | |
179 else | |
180 in_chroot wget --no-verbose "$FLAGS_mirror/${DEB_PATH}" -O "$DEB_FILE" | |
181 fi | |
182 fi | |
183 | |
184 # Copy the file into the target suite with the correct priority | |
185 in_chroot reprepro -b "$REPO_SUBDIR" -P "$DEB_PRIO" -S "$DEB_SECTION" \ | |
186 includedeb "$SUITE" "$DEB_FILE" | |
187 done | |
188 } | |
189 | |
190 #------------------------------------------------------------------------------ | |
191 | |
192 # Create a minimal chroot in which we can run reprepro, if one doesn't | |
193 # already exist. Necessary since the version of reprepro available on | |
194 # older systems is buggy. | |
195 if [ ! -e "$CHROOT" ] | |
196 then | |
197 make_chroot | |
198 fi | |
199 | |
200 # Set up chroot mounts | |
201 setup_chroot_mounts | |
202 | |
203 # Create/update repo. Need to run this every time so we rebuild the | |
204 # distributions file. | |
205 make_repo | |
206 | |
207 # Create cache directory for downloaded .debs. This needs to be outside the | |
208 # repository so we can delete and rebuild the repository without needing to | |
209 # re-download all the .debs. | |
210 if [ ! -e "$CHROOT/$DEB_CACHE_DIR" ] | |
211 then | |
212 sudo mkdir -p "$CHROOT/$DEB_CACHE_DIR" | |
213 sudo chown $USER "$CHROOT/$DEB_CACHE_DIR" | |
214 fi | |
215 | |
216 # Update the development and image suites | |
217 if [ $FLAGS_updev -eq $FLAGS_TRUE ] | |
218 then | |
219 update_suite $FLAGS_devsuite $FLAGS_devlist | |
220 fi | |
221 | |
222 if [ $FLAGS_upimg -eq $FLAGS_TRUE ] | |
223 then | |
224 update_suite $FLAGS_imgsuite $FLAGS_imglist | |
225 fi | |
226 | |
227 # Clean up the chroot mounts | |
228 cleanup_chroot_mounts | |
229 | |
230 echo "Done." | |
OLD | NEW |