treewide: replace /bin/ksh93 hashbangs with /bin/sh
[unleashed-userland.git] / components / osol / ddu / srcs / usr / ddu / scripts / 3rd_drv_ins.sh
blob673c1f022fac1ffd8fbd0e625e16ff62ff4e9bce
1 #!/bin/sh
3 # CDDL HEADER START
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]
20 # CDDL HEADER END
22 # Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 # Description: Download the driver package from the
25 # network, use pkg_check.sh to uncompress
26 # the package if the package is compressed,
27 # then use load_driver.sh to install the
28 # driver.
30 # Usage:
31 # 3rd_drv_int.sh pkg_type download_url root_path
32 # $1 is for package type.(IPS, DU, SVR4, P5I, UNK)
33 # $2 is the driver download URL
34 # $3 is root path for installation, can be null.
37 builtin chmod
38 builtin cp
39 builtin mkdir
40 builtin mv
41 builtin rm
42 builtin cat
45 function clean_up
48 if [ -s $f_dir_file ]; then
49 for f_dir in $(cat $f_dir_file); do
50 rm -f $f_dir
51 done
52 rm -f $f_dir_file
54 if [ -s $pkg_loc ]; then
55 d_name=$(echo $pkg_loc | cut -d'/' -f3)
56 cd /tmp; rm -rf $d_name
58 } >/dev/null 2>&1
62 #Main()
64 trap 'clean_up;exit 10' KILL INT
65 trap 'clean_up' EXIT
67 PATH=/usr/bin:/usr/sbin:$PATH; export PATH
68 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/ddu/lib; export LD_LIBRARY_PATH
71 # Confirm the correct number of commnad line argument
73 if (( $# < 2 )) || (( $# > 3 )); then
74 print -u2 "\n $0: Wrong number of arguments provided..."
75 exit 1
79 # Validate the arguments
82 case $1 in
83 IPS | DU | SVR4 | P5I | UNK);;
84 *) print -u2 "\n... $0: $1 is not valid."; exit 1;;
85 esac
87 echo "$2" | egrep -e \
88 "((https?|ftp|gopher|telnet|file|notes|ms-help):((//)|(\\\\))[\w\d:#%/;$()~_?\\-=\\\.&]*)" \
89 >/dev/null 2>&1
91 if [ $? -ne 0 ]; then
92 print -u2 "\n... $0: $2 is not valid URL."
93 exit 1
96 if [ ! -z $3 ]; then
97 if [ ! -d $3 ]; then
98 print -u2 "\n... $0: $3 specified is not a valid path."
99 exit 1
103 typeset -r base_dir=$(dirname $0)
104 typeset pkg_type="$1"
105 typeset -r root_path="$3"
107 print -u1 "\nDownloading from URL $2 ..."
109 if [[ ! -x $base_dir/url_down.py ]]; then
110 print -u2 "$base_dir/url_down.py not found."
111 exit 1
114 typeset pkg_info pkg_type pkg_loc
115 typeset -r f_dir_file=/tmp/f_dir_file_$$
118 try_time=0
119 while [ $try_time -le 5 ]; do
120 $base_dir/url_down.py download "$2" > $f_dir_file
121 if [ $? -ne 0 ]; then
122 sleep 10 &
123 idle_time=$!
124 while [ -d /proc/${idle_time} ]; do
126 done
127 try_time=$((try_time + 1))
128 else
129 break
131 done
134 if [ $try_time -le 5 ] && [ -s $f_dir_file ]; then
135 for f_dir in $(cat $f_dir_file); do
136 7za t "$f_dir" >/dev/null 2>&1
137 if [ $? -eq 0 ]; then
139 # For compressed data
141 if [[ ! -x $base_dir/pkg_check.sh ]]; then
142 print -u2 "$base_dir/pkg_check.sh not found."
143 exit 1
146 if [[ ! -x $base_dir/load_driver.sh ]]; then
147 print -u2 "$base_dir/load_driver.sh not found."
148 exit 1
151 pkg_info=$($base_dir/pkg_check.sh $f_dir)
152 if [ $? -eq 0 ] && [ ! -z $pkg_info ]; then
153 for i in $pkg_info; do
154 pkg_type=$(echo $i | cut -d'|' -f1)
155 pkg_loc=$(echo $i | cut -d'|' -f2)
156 if [ ! -z $pkg_type ] && [ ! -z $pkg_loc ]; then
158 # Add quote for $pkg_loc for spaces in the variable
161 $base_dir/load_driver.sh $pkg_type "$pkg_loc" $root_path
162 if [ $? -ne 0 ]; then
163 print -u2 "Error executing: $base_dir/load_driver.sh."
164 exit 1
166 else
167 print -u2 "Package type and location can not be null."
168 exit 1
170 done
171 else
172 print -u2 "Error executing: $base_dir/pkg_check.sh."
173 exit 1
175 else
177 # plain file
180 # Add quote for $f_dir for spaces in the variable
182 $base_dir/load_driver.sh $pkg_type "$f_dir" $root_path
183 if [ $? -ne 0 ]; then
184 print -u2 "Error executing: $base_dir/load_driver.sh."
185 exit 1
188 done
189 else
190 print -u2 "\nDownload $2 failed!"
191 exit 1