OLD | NEW |
1 #!/bin/bash | 1 #!/bin/bash |
2 # Copyright (c) 2014 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2014 The Native Client Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 # Package installer script for use inside the devenv environment. | 6 # Package installer script for use inside the devenv environment. |
7 # Assumes setup-environment has been source at least once in the parent | 7 # Assumes setup-environment has been source at least once in the parent |
8 # environment. | 8 # environment. |
9 # Written to avoid using anything other than bash, geturl, and unzip when | 9 # Written to avoid using anything other than bash, geturl, and unzip when |
10 # installing core packages. | 10 # installing core packages. |
11 | 11 |
12 set -o errexit | 12 set -o errexit |
13 set -o nounset | 13 set -o nounset |
14 shopt -s nullglob | 14 shopt -s nullglob |
15 | 15 |
| 16 PKG_ARCH="${NACL_ARCH}" |
| 17 if [[ "${TOOLCHAIN}" == "pnacl" ]]; then |
| 18 PKG_ARCH="pnacl" |
| 19 fi |
| 20 if [[ "${NACL_ARCH}" == "x86_64" ]]; then |
| 21 PKG_ARCH="x86-64" |
| 22 fi |
| 23 |
16 STORAGE_URL=${STORAGE_URL:-https://naclports.storage.googleapis.com/builds} | 24 STORAGE_URL=${STORAGE_URL:-https://naclports.storage.googleapis.com/builds} |
17 SDK_VERSION=${SDK_VERSION:-pepper_46} | 25 SDK_VERSION=${SDK_VERSION:-pepper_46} |
18 | 26 |
19 # This default version for packages that are downloaded and installed. | 27 # This default version for packages that are downloaded and installed. |
20 # To update this use 'git describe <rev>' to get the revision string. Be | 28 # To update this use 'git describe <rev>' to get the revision string. Be |
21 # sure to wait until the bot have build all the packages for a given | 29 # sure to wait until the bot have build all the packages for a given |
22 # revision before changing this value. | 30 # revision before changing this value. |
23 | 31 |
24 REVISION=${REVISION:-trunk-583-g2ea9c03} | 32 REVISION=${REVISION:-trunk-607-g70861c5} |
25 DEFAULT_SOURCE="${STORAGE_URL}/${SDK_VERSION}/${REVISION}/publish" | 33 PKG_DIR=pkg_${TOOLCHAIN}_${PKG_ARCH} |
26 LOCAL_SOURCE="http://localhost:5103/" | 34 DEFAULT_SOURCE="${STORAGE_URL}/${SDK_VERSION}/${REVISION}/publish/${PKG_DIR}" |
| 35 LOCAL_SOURCE="http://localhost:5103/${PKG_DIR}" |
27 VERBOSE=0 | 36 VERBOSE=0 |
28 | 37 |
29 NACL_ARCH_ALT="${NACL_ARCH}" | |
30 if [[ "${TOOLCHAIN}" == "pnacl" ]]; then | |
31 NACL_ARCH_ALT="pnacl" | |
32 fi | |
33 | |
34 # Locations for package archives. | |
35 # Prefer this one going forward: | |
36 PACKAGE_BY_ARCH=${TOOLCHAIN}/${NACL_ARCH_ALT}.zip | |
37 # Old default: | |
38 PACKAGE_AS_ONE=${TOOLCHAIN}.zip | |
39 | |
40 # List of packages (keep sorted). | 38 # List of packages (keep sorted). |
41 # Pairs of <package-name>:<status><package-subdir>[:<source>:<alt-subdir>] | 39 # Pairs of <package-name>:<status><package-subdir>[:<source>:<alt-subdir>] |
42 PACKAGE_INFO="\ | 40 PACKAGE_INFO="\ |
43 bash|ok|${PACKAGE_BY_ARCH} \ | |
44 blackbox|WIP|${PACKAGE_BY_ARCH} \ | |
45 busybox|WIP|glibc/busybox-1.22.0.zip \ | |
46 bzip2|ok|${PACKAGE_BY_ARCH} \ | |
47 civitweb|WIP|${PACKAGE_AS_ONE} \ | |
48 coreutils|ok|${PACKAGE_BY_ARCH} \ | |
49 curl|ok|${PACKAGE_AS_ONE} \ | |
50 drod|WIP|${PACKAGE_AS_ONE} \ | |
51 emacs|ok|glibc/emacs-24.3.zip \ | |
52 findutils|ok|${PACKAGE_BY_ARCH} \ | |
53 fvwm|ok|${PACKAGE_BY_ARCH} \ | |
54 gawk|ok|${PACKAGE_BY_ARCH} \ | |
55 gforth|ok|${PACKAGE_AS_ONE} \ | |
56 git|ok|${PACKAGE_BY_ARCH} \ | |
57 grep|ok|${PACKAGE_BY_ARCH} \ | |
58 less|ok|${PACKAGE_BY_ARCH} \ | |
59 lua5.3|ok|${PACKAGE_BY_ARCH} \ | |
60 m4|ok|${PACKAGE_BY_ARCH} \ | |
61 make|ok|${PACKAGE_BY_ARCH} \ | |
62 mingn.base|ok|glibc/tarballs/base.${NACL_ARCH}.zip \ | |
63 mingn.lib|ok|glibc/tarballs/lib.all.zip \ | |
64 nano|ok|${PACKAGE_AS_ONE} \ | |
65 nethack|ok|${PACKAGE_AS_ONE} \ | |
66 ninja|WIP|${PACKAGE_BY_ARCH} \ | |
67 openssh|ok|glibc.zip \ | |
68 python3|WIP|${TOOLCHAIN}/python.zip \ | |
69 python|ok|${TOOLCHAIN}/python.zip \ | |
70 ruby|ok|${TOOLCHAIN}/ruby.zip \ | |
71 sqlite|ok|${PACKAGE_AS_ONE} \ | |
72 subversion|WIP|${PACKAGE_BY_ARCH} \ | |
73 tar|WIP|${PACKAGE_AS_ONE} \ | |
74 texlive|ok|${PACKAGE_BY_ARCH} \ | |
75 thttpd|ok|glibc.zip \ | |
76 tk|ok|${PACKAGE_BY_ARCH} \ | |
77 toybox|WIP|${TOOLCHAIN}/toybox-0.4.7.zip \ | |
78 twm|ok|${PACKAGE_BY_ARCH} \ | |
79 vim|ok|${PACKAGE_AS_ONE} \ | |
80 xeyes|ok|${PACKAGE_BY_ARCH} \ | |
81 xz|ok|${PACKAGE_BY_ARCH} \ | |
82 " | 41 " |
83 | 42 |
84 ALIASES="\ | 43 ALIASES="\ |
85 lua|lua5.3 | 44 bash|bash-4.3 \ |
| 45 binutils|binutils-7dc2f2590 \ |
| 46 gcc|gcc-396037926 \ |
| 47 blackbox|blackbox |
| 48 busybox|busybox-1.22.0 |
| 49 bzip2|bzip2 \ |
| 50 civitweb|civitweb \ |
| 51 coreutils|coreutils-5.2.1 \ |
| 52 nacl-spawn|nacl-spawn-0.1 \ |
| 53 corelibs|corelibs-0.2 \ |
| 54 file|file-5.24 \ |
| 55 curl|curl-7.37.0 \ |
| 56 drod|drod \ |
| 57 emacs|emacs-24.3 \ |
| 58 findutils|findutils-4.4.2 \ |
| 59 fvwm|fvwm \ |
| 60 gawk|gawk \ |
| 61 gforth|gforth \ |
| 62 tree|tree-1.7.0 \ |
| 63 git|git-2.3.0 \ |
| 64 pcre|pcre-8.36 \ |
| 65 grep|grep-2.21 \ |
| 66 less|less-451 \ |
| 67 lua|lua-5.3 \ |
| 68 m4|m4 \ |
| 69 make|make-3.82 \ |
| 70 mingn|mingn-0.2 \ |
| 71 nano|nano-2.2.6 \ |
| 72 nethack|nethack \ |
| 73 ninja|ninja \ |
| 74 openssh|openssh \ |
| 75 python3|python3-3.4 \ |
| 76 python|python-2.7.7 \ |
| 77 ruby|ruby \ |
| 78 sqlite|sqlite \ |
| 79 subversion|subversion \ |
| 80 tar|tar \ |
| 81 texlive|texlive \ |
| 82 thttpd|thttpd \ |
| 83 tk|tk \ |
| 84 toybox|toybox \ |
| 85 twm|twm \ |
| 86 vim|vim-7.4 \ |
| 87 xeyes|xeyes \ |
| 88 xz|xz \ |
86 " | 89 " |
87 | 90 |
88 RemoveDir() { | |
89 local path="$1" | |
90 if [ -d ${path} ]; then | |
91 rm -rf ${path}/* || true | |
92 rm -rf ${path} | |
93 fi | |
94 } | |
95 | |
96 # | 91 # |
97 # $1 - package name | 92 # $1 - package name |
98 # | 93 # |
99 InstallPackage() { | 94 InstallPackage() { |
100 local package="$1" | 95 package=$1 |
101 local subdir="${PACKAGE_BY_ARCH}" | |
102 local source_base="${PACKAGE_SOURCE}" | |
103 | 96 |
104 # Replace package aliases with alternates. | 97 # Replace package aliases with alternates. |
105 for names in ${ALIASES}; do | 98 for names in ${ALIASES}; do |
106 local names_array=(${names//|/ }) | 99 local names_array=(${names//|/ }) |
107 if [ "${package}" = "${names_array[0]}" ]; then | 100 if [ "${package}" = "${names_array[0]}" ]; then |
108 package="${names_array[1]}" | 101 package="${names_array[1]}" |
109 fi | 102 fi |
110 done | 103 done |
111 | 104 if [[ ${PACKAGE_FORCE} != 1 ]]; then |
112 for info in ${PACKAGE_INFO}; do | 105 if pkg info --quiet ${package}; then |
113 local info_array=(${info//|/ }) | 106 return |
114 if [ "${package}" = "${info_array[0]}" ]; then | |
115 subdir="${info_array[2]}" | |
116 if [[ "${ALTERNATE_SOURCE}" == "0" && \ | |
117 ${#info_array[@]} > 3 && \ | |
118 "${info_array[3]}" != "" ]]; then | |
119 source_base="${info_array[3]}" | |
120 subdir="${info_array[4]}" | |
121 fi | |
122 fi | 107 fi |
123 done | |
124 | |
125 local url=${source_base}/${package}/${subdir} | |
126 InstallPackageFromUrl ${package} ${url} | |
127 } | |
128 | |
129 # | |
130 # $1 - package name | |
131 # $2 - zip file url | |
132 # | |
133 InstallPackageFromUrl() { | |
134 local package=$1 | |
135 local url=$2 | |
136 local package_dir=/packages/${package}.${NACL_ARCH} | |
137 local clobber=1 | |
138 | |
139 # Special case for MinGN. | |
140 if [[ "${package}" = "mingn.base" || "${package}" = "mingn.lib" ]]; then | |
141 url="${PACKAGE_SOURCE}/mingn/${subdir}" | |
142 package_dir="/" | |
143 clobber=0 | |
144 fi | |
145 # Special case for coreutils. | |
146 if [[ "${package}" = "coreutils" ]]; then | |
147 package_dir="/coreutils.${NACL_ARCH}" | |
148 clobber=0 | |
149 fi | 108 fi |
150 | 109 |
151 local stamp_dir=/stamps/${package}.${NACL_ARCH} | 110 if ! pkg add ${PACKAGE_SOURCE}/${package}.tbz; then |
152 local url_stamp="${stamp_dir}/${url//\//_}" | 111 echo "pkg add failed: $?" |
153 | |
154 if [ -d ${package_dir}/${package} ]; then | |
155 local package_inside=${package_dir}/${package} | |
156 else | |
157 local package_inside=${package_dir} | |
158 fi | |
159 | |
160 if [[ ${PACKAGE_FORCE} != 1 && -d ${url_stamp} ]]; then | |
161 # Package is up to date. | |
162 return | |
163 fi | |
164 | |
165 if [ -d ${stamp_dir} ]; then | |
166 echo "Updating ${package} package..." | |
167 else | |
168 echo "Installing ${package} package..." | |
169 fi | |
170 local archive=/tmp/devenv.${package}.zip | |
171 echo "Downloading ${url}..." | |
172 if ! geturl ${url} ${archive}; then | |
173 echo "geturl failed" | |
174 exit 1 | 112 exit 1 |
175 fi | 113 fi |
176 | |
177 echo "Extracting ${package}..." | |
178 if [ ! -e ${archive} ]; then | |
179 echo "${archive} does not exist!" | |
180 exit 1 | |
181 fi | |
182 if [ "${clobber}" = 1 ]; then | |
183 RemoveDir ${package_dir} | |
184 fi | |
185 if [ ! -d ${package_dir%/*} ]; then | |
186 mkdir -p ${package_dir} | |
187 fi | |
188 local unzip_flags= | |
189 if [ ${VERBOSE} != "1" ]; then | |
190 unzip_flags=-q | |
191 fi | |
192 if ! unzip -o $unzip_flags -d ${package_dir} ${archive}; then | |
193 echo "error: unzip failed" | |
194 exit 1 | |
195 fi | |
196 rm ${archive} | |
197 | |
198 # Update package_inside. | |
199 if [ -d ${package_dir}/${package} ]; then | |
200 package_inside=${package_dir}/${package} | |
201 else | |
202 package_inside=${package_dir} | |
203 fi | |
204 | |
205 # TODO(bradnelson): Do something better. | |
206 # Rename appropriate nexe/pexe to unsuffixed version. | |
207 local suffixes=".pexe _pnacl.pexe _${NACL_ARCH}.nexe .nexe" | |
208 local platform_dirs="_platform_specific/${NACL_ARCH}/ \ | |
209 _platform_specific/all/" | |
210 if [ "${NACL_ARCH}" = "i686" ]; then | |
211 suffixes+=" _x86_32.nexe" | |
212 platform_dirs+=" _platform_specific/x86_32/" | |
213 fi | |
214 for alt in "" _ppapi; do | |
215 for plat in "" ${platform_dirs}; do | |
216 for suffix in ${suffixes}; do | |
217 local exe=${package_inside}/${plat}${package}${alt}${suffix} | |
218 if [ -e ${exe} ]; then | |
219 cp ${exe} ${package_inside}/${package} | |
220 fi | |
221 done | |
222 done | |
223 done | |
224 | |
225 # Remove out stamps and write out new one. | |
226 RemoveDir ${stamp_dir} | |
227 mkdir -p ${url_stamp} | |
228 echo "Done." | |
229 } | 114 } |
230 | 115 |
231 function Usage() { | 116 function Usage() { |
232 echo "Usage: $0 [options]" | 117 echo "Usage: $0 [options]" |
233 echo " -i <package> = install package" | 118 echo " -i <package> = install package" |
234 echo " -s <source> = alternate package source" | 119 echo " -s <source> = alternate package source" |
235 echo " -L = local package source (use with make run in naclports)" | 120 echo " -L = local package source (use with make run in naclports)" |
236 echo " -f = force install" | 121 echo " -f = force install" |
237 echo " -l = list known packages" | 122 echo " -l = list known packages" |
238 echo " -h = help" | 123 echo " -h = help" |
239 exit 1 | 124 exit 1 |
240 } | 125 } |
241 | 126 |
242 function main() { | 127 function main() { |
243 PACKAGE_LIST="" | 128 PACKAGE_LIST="" |
244 PACKAGE_FORCE=0 | 129 PACKAGE_FORCE=0 |
245 ALTERNATE_SOURCE=0 | 130 ALTERNATE_SOURCE=0 |
246 | 131 |
247 while getopts "vs:i:hLfl" o; do | 132 while getopts "vs:i:hLfl" o; do |
248 case "${o}" in | 133 case "${o}" in |
249 i) | 134 i) |
250 PACKAGE_LIST+=" ${OPTARG}" | 135 PACKAGE_LIST+=" ${OPTARG}" |
251 ;; | 136 ;; |
252 s) | 137 s) |
253 PACKAGE_SOURCE="${OPTARG}" | 138 PACKAGE_SOURCE="${OPTARG}/${PKG_DIR}" |
254 ;; | 139 ;; |
255 L) | 140 L) |
256 PACKAGE_SOURCE="${LOCAL_SOURCE}" | 141 PACKAGE_SOURCE="${LOCAL_SOURCE}" |
257 ;; | 142 ;; |
258 f) | 143 f) |
259 PACKAGE_FORCE=1 | 144 PACKAGE_FORCE=1 |
260 ;; | 145 ;; |
261 v) | 146 v) |
262 VERBOSE=1 | 147 VERBOSE=1 |
263 ;; | 148 ;; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 ALTERNATE_SOURCE=1 | 191 ALTERNATE_SOURCE=1 |
307 fi | 192 fi |
308 fi | 193 fi |
309 | 194 |
310 for package in ${PACKAGE_LIST}; do | 195 for package in ${PACKAGE_LIST}; do |
311 InstallPackage ${package} | 196 InstallPackage ${package} |
312 done | 197 done |
313 } | 198 } |
314 | 199 |
315 main "$@" | 200 main "$@" |
OLD | NEW |