5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
25 # Description: Perform pkg related function:
26 # list repo, add repo, search repo and modify
31 # $1 can be "add","list","search" and "modify"
32 # $2 is the sub-argument for $1
33 # $3 is the sub-argument for $1
45 # Get all publishers info on the system
49 pfexec pkg publisher
-Ha > /tmp
/repo_temp_store
2>>$err_log
51 print
-u2 "$0: Error found when getting repo list"
54 repo_list
=$
(cat /tmp
/repo_temp_store | cut
-d " " -f 1 2>/dev
/null
)
55 repo_url
=$
(cat /tmp
/repo_temp_store | nawk
-F"http://" '{ print $2 }' \
57 repo_count
=$
(cat /tmp
/repo_temp_store |
wc -l 2>/dev
/null
)
61 # Output the publisher info in the following format:
62 # opensolaris.org http://ipkg.sfbay.sun.com/dev/
68 while [ $index -le ${repo_count} ]; do
69 repo_listi
=$
(echo ${repo_list} | nawk '{ print $'${index}' }')
70 repo_urli=$(echo ${repo_url} | nawk '{ print $'${index}' }')
71 printf "${repo_listi}\thttp://${repo_urli}\n"
77 # Output the publisher info with following format based on the input
79 # opensolaris.org http://ipkg.sfbay.sun.com/dev/
81 # Input paramenters can be:
82 # all: list all the publisher info.
83 # default: list preferred publisher info.
84 # publisher name: list specified pulibsher info.
89 if [ ${min_argu_1} == "all" ]; then #list all repo.
92 elif [ ${min_argu_1} == "default" ]; then #list default repo
93 pfexec pkg publisher
-HP > /tmp
/repo_default_store
2>>$err_log
94 repo_list
=$
(cat /tmp
/repo_default_store | cut
-d " " -f 1 2>/dev
/null
)
95 repo_url
=$
(cat /tmp
/repo_default_store | nawk
-F"http://" '{ print $2 }' \
97 repo_count
=$
(cat /tmp
/repo_default_store |
wc -l 2>/dev
/null
)
99 elif [ ! -z ${min_argu_1} ]; then #list a specific repo
100 repo_name
=${min_argu_1}
101 pfexec pkg publisher
${repo_name} |
grep "URI" \
102 > /tmp
/repo_spe_store
2>>$err_log
104 print
-u2 "$0: ${repo_name} is not a valid repo name!"
107 repo_url
=$
(cat /tmp
/repo_spe_store | nawk
-F"http://" '{ print $2 }' \
109 for repo_urli
in ${repo_url}
111 repo_url
="http://"${repo_urli}
112 printf "${repo_name}\t${repo_url}\n"
118 # Search for driver package via pulisher based on the device compatible string
122 if [ -z ${min_argu_2} ]; then
127 while [ $index -le ${repo_count} ]; do
128 repo_listi
=$
(echo ${repo_list} | nawk '{ print $'${index}' }')
129 repo_urli=$(echo ${repo_url} | nawk '{ print $'${index}' }')
131 repo_urli
="http://"${repo_urli}
133 pfexec pkg search
-p -s "${repo_urli}" "${min_argu_1}" \
134 2>>/dev
/null | nawk
-F"@" '{ print $1 }' | \
135 nawk
-F"pkg:/" '{ print $2 }' |
uniq > /tmp
/pkg_candi
137 pkgname
=$
(grep driver
/tmp
/pkg_candi |
tail -1 2>/dev
/null
)
138 if [ -z ${pkgname} ]; then
139 pkgname
=$
(tail -1 /tmp
/pkg_candi
2>/dev
/null
)
142 if [[ $?
!= 0 ||
-z ${pkgname} ]]; then
143 index
=$
(($index + 1))
147 depend_str
="depend:incorporate:${pkgname}"
148 pkg_ver
=$
(pfexec pkg search
-l ${depend_str} |
tail -1 2>>/dev
/null
)
150 if [ $?
-eq 0 ]; then
151 pkgvalue
=$
(echo ${pkg_ver} | nawk
'{ print $3 }')
152 if [ -z "`echo ${pkgvalue} | grep "pkg
:/"`" ]; then
153 pkgcondidate
=${pkgvalue}
155 pkgcondidate
=$
(echo ${pkgvalue} | nawk
-F"pkg:/" '{ print $2 }')
159 if [ -z ${pkgcondidate} ]; then
160 pkgcondidate
=${pkgname}
162 pfexec pkg info
-r pkg
://${repo_listi}/${pkgcondidate} \
163 >/dev
/null
2>>$err_log
164 if [ $?
-eq 0 ]; then
165 /usr
/bin
/printf "${repo_listi}\t${pkgcondidate}\n"
168 index
=$
(($index + 1))
171 repo_listi
=${min_argu_2}
173 repo_urli
=$
(pfexec pkg publisher
${repo_listi} |
grep "URI" \
174 | nawk
-F"http://" '{ print $2 }')
176 for repo_urli_i
in $repo_urli; do
177 repo_urli_i
="http://"${repo_urli_i}
179 pfexec pkg search
-p -s "${repo_urli_i}" "${min_argu_1}" \
180 2>>/dev
/null | nawk
-F"@" '{ print $1 }' | \
181 nawk
-F"pkg:/" '{ print $2 }' |
uniq > /tmp
/pkg_candi
183 pkgname
=$
(grep driver
/tmp
/pkg_candi |
tail -1 2>/dev
/null
)
184 if [ -z ${pkgname} ]; then
185 pkgname
=$
(tail -1 /tmp
/pkg_candi
2>/dev
/null
)
187 if [ ! -z ${pkgname} ]; then
192 if [[ $?
!= 0 ||
-z ${pkgname} ]]; then
196 depend_str
="depend:incorporate:${pkgname}"
197 pkg_ver
=$
(pfexec pkg search
-l ${depend_str} |
tail -1 2>>/dev
/null
)
199 if [ $?
-eq 0 ]; then
200 pkgvalue
=$
(echo ${pkg_ver} | nawk
'{ print $3 }')
201 if [ -z "`echo ${pkgvalue} | grep "pkg
:/"`" ]; then
202 pkgcondidate
=${pkgvalue}
204 pkgcondidate
=$
(echo ${pkgvalue} | nawk
-F"pkg:/" '{ print $2 }')
208 if [ -z ${pkgcondidate} ]; then
209 pkgcondidate
=${pkgname}
211 pfexec pkg info
-r pkg
://${repo_listi}/${pkgcondidate} \
212 >/dev
/null
2>>$err_log
213 if [ $?
-eq 0 ]; then
214 printf "${repo_listi}\t${pkgcondidate}\n"
218 if [ ${pakcage_found} -eq 0 ]; then
224 # Add publisher on the system
230 #add a repo and set it to default one if set.
232 if [ -z ${min_argu_2} ]; then
233 print
-u2 "\n$0: Third argument can not be null..."
236 publisher_name
=${min_argu_1}
237 publisher_url
=${min_argu_2}
238 pfexec pkg set-publisher
-O ${publisher_url} ${publisher_name} \
240 if [ $?
-ne 0 ]; then
241 print
-u2 "$0: Error found when adding repo: "
242 print
-u2 "${publisher_name} ${publisher_url}"
248 # Modify the existing publisher on the system via
249 # pkg set-publisher and pkg unset-publisher.
254 #modify a repo and set it to default one if set.
256 if [ -z ${min_argu_2} ]; then
257 print
-u2 "\n$0: Third argument can not be null..."
260 publisher_name
=${min_argu_1}
261 publisher_url
=${min_argu_2}
263 LC_ALL
="C" pfexec pkg publisher
${publisher_name} > \
264 /tmp
/spe_repo_temp_store
2>>$err_log
267 origin_uri
=`cat /tmp/spe_repo_temp_store | grep "Origin URI" | \
268 nawk -F ": " '{ print $2 }' 2>>$err_log`
270 mirror_uris
=`cat /tmp/spe_repo_temp_store | grep "Mirror URI" | \
271 nawk -F ": " '{ print $2 }' 2>>$err_log`
273 store_repo
=" -O "${origin_uri}
277 for mirror_uri
in ${mirror_uris}
279 extra_repo
=${extra_repo}" -m "${mirror_uri}
280 unset_extra_repo
=${unset_extra_repo}" -M "${mirror_uri}
283 extra_repo
=${extra_repo}" "${publisher_name}
285 pfexec pkg unset-publisher
${publisher_name} 2>>/dev
/null
1>&2
286 if [ $?
-ne 0 ]; then
287 print
-u2 "Warning: Can not remove repo ${publisher_name}"
289 pfexec pkg set-publisher
-O ${publisher_url} \
290 ${unset_extra_repo} \
293 if [ $?
-ne 0 ]; then
294 print
-u2 "$0: Error found when adding repo:"
295 print
-u2 "${publisher_name} ${publisher_url}"
298 echo ${store_repo} > /tmp
/spe_repo_store
299 echo ${extra_repo} >> /tmp
/spe_repo_store
302 echo ${store_repo} > /tmp
/spe_repo_store
303 echo ${extra_repo} >> /tmp
/spe_repo_store
308 # Restore the original publisher on the system
312 pfexec pkg set-publisher
${min_argu_1} ${min_argu_2} \
314 if [ $?
-ne 0 ]; then
315 print
-u2 "$0: Error found when restoring repo!"
323 rm -f /tmp
/repo_temp_store
/tmp
/repo_default_store \
324 /tmp
/repo_spe_store \
325 /tmp
/spe_repo_temp_store
/tmp
/pkg_candi
332 PATH
=/usr
/bin
:/usr
/sbin
:$PATH; export PATH
333 LD_LIBRARY_PATH
=${LD_LIBRARY_PATH}:/usr
/ddu
/lib
; export LD_LIBRARY_PATH
335 trap 'clean_up;exit 10' KILL INT
340 # Confirm the correct number of commnad line argument
342 if (( $# < 2 )) ||
(( $# > 3 )); then
343 print
-u2 "\n$0: Wrong number of arguments provided..."
348 print
-u2 "\n$0: First argument can not be null..."
353 print
-u2 "\n$0: Second argument can not be null..."
359 typeset min_argu_1
=$2
360 typeset min_argu_2
=$3
361 typeset repo_list repo_url repo_count
362 typeset repo_listi repo_urli repo_name pkgname
363 typeset depend_str pkg_ver pkgcondidate pakcage_found
365 typeset err_log
=/tmp
/ddu_err.log
368 # Copy /var/pkg to /tmp if booted off a ramdisk
369 # Needed by pkg utility so it can expand its bootkeeping files in swap space.
371 if [ -x /usr
/lib
/install
/live_img_pkg5_prep
] ; then
372 pfexec
/usr
/lib
/install
/live_img_pkg5_prep
2>>$err_log
374 print
-u2 "Error executing: /usr/lib/install/live_img_pkg5_prep."
386 *) print
-u2 "\n$0: ${main_argu} is not valid"