1*b40554a2SAndroid Build Coastguard Worker#!/usr/bin/env bash 2*b40554a2SAndroid Build Coastguard Worker 3*b40554a2SAndroid Build Coastguard Worker# No undefined variables 4*b40554a2SAndroid Build Coastguard Workerset -u 5*b40554a2SAndroid Build Coastguard Worker 6*b40554a2SAndroid Build Coastguard Workerinit_logging() { 7*b40554a2SAndroid Build Coastguard Worker local _abs_libdir="$1" 8*b40554a2SAndroid Build Coastguard Worker local _logfile="$_abs_libdir/$TEMPLATE_REL_MANIFEST_DIR/install.log" 9*b40554a2SAndroid Build Coastguard Worker rm -f "$_logfile" 10*b40554a2SAndroid Build Coastguard Worker need_ok "failed to remove old installation log" 11*b40554a2SAndroid Build Coastguard Worker touch "$_logfile" 12*b40554a2SAndroid Build Coastguard Worker need_ok "failed to create installation log" 13*b40554a2SAndroid Build Coastguard Worker LOGFILE="$_logfile" 14*b40554a2SAndroid Build Coastguard Worker} 15*b40554a2SAndroid Build Coastguard Worker 16*b40554a2SAndroid Build Coastguard Workerlog_line() { 17*b40554a2SAndroid Build Coastguard Worker local _line="$1" 18*b40554a2SAndroid Build Coastguard Worker 19*b40554a2SAndroid Build Coastguard Worker if [ -n "${LOGFILE-}" -a -e "${LOGFILE-}" ]; then 20*b40554a2SAndroid Build Coastguard Worker echo "$_line" >> "$LOGFILE" 21*b40554a2SAndroid Build Coastguard Worker # Ignore errors, which may happen e.g. after the manifest dir is deleted 22*b40554a2SAndroid Build Coastguard Worker fi 23*b40554a2SAndroid Build Coastguard Worker} 24*b40554a2SAndroid Build Coastguard Worker 25*b40554a2SAndroid Build Coastguard Workermsg() { 26*b40554a2SAndroid Build Coastguard Worker local _line="install: ${1-}" 27*b40554a2SAndroid Build Coastguard Worker echo "$_line" 28*b40554a2SAndroid Build Coastguard Worker log_line "$_line" 29*b40554a2SAndroid Build Coastguard Worker} 30*b40554a2SAndroid Build Coastguard Worker 31*b40554a2SAndroid Build Coastguard Workerverbose_msg() { 32*b40554a2SAndroid Build Coastguard Worker if [ -n "${CFG_VERBOSE-}" ]; then 33*b40554a2SAndroid Build Coastguard Worker msg "${1-}" 34*b40554a2SAndroid Build Coastguard Worker else 35*b40554a2SAndroid Build Coastguard Worker log_line "install: ${1-}" 36*b40554a2SAndroid Build Coastguard Worker fi 37*b40554a2SAndroid Build Coastguard Worker} 38*b40554a2SAndroid Build Coastguard Worker 39*b40554a2SAndroid Build Coastguard Workerstep_msg() { 40*b40554a2SAndroid Build Coastguard Worker msg 41*b40554a2SAndroid Build Coastguard Worker msg "$1" 42*b40554a2SAndroid Build Coastguard Worker msg 43*b40554a2SAndroid Build Coastguard Worker} 44*b40554a2SAndroid Build Coastguard Worker 45*b40554a2SAndroid Build Coastguard Workerverbose_step_msg() { 46*b40554a2SAndroid Build Coastguard Worker if [ -n "${CFG_VERBOSE-}" ]; then 47*b40554a2SAndroid Build Coastguard Worker msg 48*b40554a2SAndroid Build Coastguard Worker msg "$1" 49*b40554a2SAndroid Build Coastguard Worker msg 50*b40554a2SAndroid Build Coastguard Worker else 51*b40554a2SAndroid Build Coastguard Worker log_line "" 52*b40554a2SAndroid Build Coastguard Worker log_line "install: $1" 53*b40554a2SAndroid Build Coastguard Worker log_line "" 54*b40554a2SAndroid Build Coastguard Worker fi 55*b40554a2SAndroid Build Coastguard Worker} 56*b40554a2SAndroid Build Coastguard Worker 57*b40554a2SAndroid Build Coastguard Workerwarn() { 58*b40554a2SAndroid Build Coastguard Worker local _line="install: WARNING: $1" 59*b40554a2SAndroid Build Coastguard Worker echo "$_line" >&2 60*b40554a2SAndroid Build Coastguard Worker log_line "$_line" 61*b40554a2SAndroid Build Coastguard Worker} 62*b40554a2SAndroid Build Coastguard Worker 63*b40554a2SAndroid Build Coastguard Workererr() { 64*b40554a2SAndroid Build Coastguard Worker local _line="install: error: $1" 65*b40554a2SAndroid Build Coastguard Worker echo "$_line" >&2 66*b40554a2SAndroid Build Coastguard Worker log_line "$_line" 67*b40554a2SAndroid Build Coastguard Worker exit 1 68*b40554a2SAndroid Build Coastguard Worker} 69*b40554a2SAndroid Build Coastguard Worker 70*b40554a2SAndroid Build Coastguard Worker# A non-user error that is likely to result in a corrupted install 71*b40554a2SAndroid Build Coastguard Workercritical_err() { 72*b40554a2SAndroid Build Coastguard Worker local _line="install: error: $1. see logs at '${LOGFILE-}'" 73*b40554a2SAndroid Build Coastguard Worker echo "$_line" >&2 74*b40554a2SAndroid Build Coastguard Worker log_line "$_line" 75*b40554a2SAndroid Build Coastguard Worker exit 1 76*b40554a2SAndroid Build Coastguard Worker} 77*b40554a2SAndroid Build Coastguard Worker 78*b40554a2SAndroid Build Coastguard Workerneed_ok() { 79*b40554a2SAndroid Build Coastguard Worker if [ $? -ne 0 ] 80*b40554a2SAndroid Build Coastguard Worker then 81*b40554a2SAndroid Build Coastguard Worker err "$1" 82*b40554a2SAndroid Build Coastguard Worker fi 83*b40554a2SAndroid Build Coastguard Worker} 84*b40554a2SAndroid Build Coastguard Worker 85*b40554a2SAndroid Build Coastguard Workercritical_need_ok() { 86*b40554a2SAndroid Build Coastguard Worker if [ $? -ne 0 ] 87*b40554a2SAndroid Build Coastguard Worker then 88*b40554a2SAndroid Build Coastguard Worker critical_err "$1" 89*b40554a2SAndroid Build Coastguard Worker fi 90*b40554a2SAndroid Build Coastguard Worker} 91*b40554a2SAndroid Build Coastguard Worker 92*b40554a2SAndroid Build Coastguard Workerwant_ok() { 93*b40554a2SAndroid Build Coastguard Worker if [ $? -ne 0 ]; then 94*b40554a2SAndroid Build Coastguard Worker warn "$1" 95*b40554a2SAndroid Build Coastguard Worker fi 96*b40554a2SAndroid Build Coastguard Worker} 97*b40554a2SAndroid Build Coastguard Worker 98*b40554a2SAndroid Build Coastguard Workerassert_nz() { 99*b40554a2SAndroid Build Coastguard Worker if [ -z "$1" ]; then err "assert_nz $2"; fi 100*b40554a2SAndroid Build Coastguard Worker} 101*b40554a2SAndroid Build Coastguard Worker 102*b40554a2SAndroid Build Coastguard Workerneed_cmd() { 103*b40554a2SAndroid Build Coastguard Worker if command -v $1 >/dev/null 2>&1 104*b40554a2SAndroid Build Coastguard Worker then verbose_msg "found $1" 105*b40554a2SAndroid Build Coastguard Worker else err "need $1" 106*b40554a2SAndroid Build Coastguard Worker fi 107*b40554a2SAndroid Build Coastguard Worker} 108*b40554a2SAndroid Build Coastguard Worker 109*b40554a2SAndroid Build Coastguard Workerrun() { 110*b40554a2SAndroid Build Coastguard Worker local _line="\$ $*" 111*b40554a2SAndroid Build Coastguard Worker "$@" 112*b40554a2SAndroid Build Coastguard Worker local _retval=$? 113*b40554a2SAndroid Build Coastguard Worker log_line "$_line" 114*b40554a2SAndroid Build Coastguard Worker return $_retval 115*b40554a2SAndroid Build Coastguard Worker} 116*b40554a2SAndroid Build Coastguard Worker 117*b40554a2SAndroid Build Coastguard Workerwrite_to_file() { 118*b40554a2SAndroid Build Coastguard Worker local _msg="$1" 119*b40554a2SAndroid Build Coastguard Worker local _file="$2" 120*b40554a2SAndroid Build Coastguard Worker local _line="$ echo \"$_msg\" > \"$_file\"" 121*b40554a2SAndroid Build Coastguard Worker echo "$_msg" > "$_file" 122*b40554a2SAndroid Build Coastguard Worker local _retval=$? 123*b40554a2SAndroid Build Coastguard Worker log_line "$_line" 124*b40554a2SAndroid Build Coastguard Worker return $_retval 125*b40554a2SAndroid Build Coastguard Worker} 126*b40554a2SAndroid Build Coastguard Worker 127*b40554a2SAndroid Build Coastguard Workerappend_to_file() { 128*b40554a2SAndroid Build Coastguard Worker local _msg="$1" 129*b40554a2SAndroid Build Coastguard Worker local _file="$2" 130*b40554a2SAndroid Build Coastguard Worker local _line="$ echo \"$_msg\" >> \"$_file\"" 131*b40554a2SAndroid Build Coastguard Worker echo "$_msg" >> "$_file" 132*b40554a2SAndroid Build Coastguard Worker local _retval=$? 133*b40554a2SAndroid Build Coastguard Worker log_line "$_line" 134*b40554a2SAndroid Build Coastguard Worker return $_retval 135*b40554a2SAndroid Build Coastguard Worker} 136*b40554a2SAndroid Build Coastguard Worker 137*b40554a2SAndroid Build Coastguard Workermake_dir_recursive() { 138*b40554a2SAndroid Build Coastguard Worker local _dir="$1" 139*b40554a2SAndroid Build Coastguard Worker local _line="$ umask 022 && mkdir -p \"$_dir\"" 140*b40554a2SAndroid Build Coastguard Worker umask 022 && mkdir -p "$_dir" 141*b40554a2SAndroid Build Coastguard Worker local _retval=$? 142*b40554a2SAndroid Build Coastguard Worker log_line "$_line" 143*b40554a2SAndroid Build Coastguard Worker return $_retval 144*b40554a2SAndroid Build Coastguard Worker} 145*b40554a2SAndroid Build Coastguard Worker 146*b40554a2SAndroid Build Coastguard Workerputvar() { 147*b40554a2SAndroid Build Coastguard Worker local t 148*b40554a2SAndroid Build Coastguard Worker local tlen 149*b40554a2SAndroid Build Coastguard Worker eval t=\$$1 150*b40554a2SAndroid Build Coastguard Worker eval tlen=\${#$1} 151*b40554a2SAndroid Build Coastguard Worker} 152*b40554a2SAndroid Build Coastguard Worker 153*b40554a2SAndroid Build Coastguard Workervalopt() { 154*b40554a2SAndroid Build Coastguard Worker VAL_OPTIONS="$VAL_OPTIONS $1" 155*b40554a2SAndroid Build Coastguard Worker 156*b40554a2SAndroid Build Coastguard Worker local op=$1 157*b40554a2SAndroid Build Coastguard Worker local default=$2 158*b40554a2SAndroid Build Coastguard Worker shift 159*b40554a2SAndroid Build Coastguard Worker shift 160*b40554a2SAndroid Build Coastguard Worker local doc="$*" 161*b40554a2SAndroid Build Coastguard Worker if [ $HELP -eq 0 ] 162*b40554a2SAndroid Build Coastguard Worker then 163*b40554a2SAndroid Build Coastguard Worker local uop=$(echo $op | tr 'a-z-' 'A-Z_') 164*b40554a2SAndroid Build Coastguard Worker local v="CFG_${uop}" 165*b40554a2SAndroid Build Coastguard Worker eval $v="$default" 166*b40554a2SAndroid Build Coastguard Worker for arg in $CFG_ARGS 167*b40554a2SAndroid Build Coastguard Worker do 168*b40554a2SAndroid Build Coastguard Worker if echo "$arg" | grep -q -- "--$op=" 169*b40554a2SAndroid Build Coastguard Worker then 170*b40554a2SAndroid Build Coastguard Worker local val=$(echo "$arg" | cut -f2 -d=) 171*b40554a2SAndroid Build Coastguard Worker eval $v=$val 172*b40554a2SAndroid Build Coastguard Worker fi 173*b40554a2SAndroid Build Coastguard Worker done 174*b40554a2SAndroid Build Coastguard Worker putvar $v 175*b40554a2SAndroid Build Coastguard Worker else 176*b40554a2SAndroid Build Coastguard Worker if [ -z "$default" ] 177*b40554a2SAndroid Build Coastguard Worker then 178*b40554a2SAndroid Build Coastguard Worker default="<none>" 179*b40554a2SAndroid Build Coastguard Worker fi 180*b40554a2SAndroid Build Coastguard Worker op="${op}=[${default}]" 181*b40554a2SAndroid Build Coastguard Worker printf " --%-30s %s\n" "$op" "$doc" 182*b40554a2SAndroid Build Coastguard Worker fi 183*b40554a2SAndroid Build Coastguard Worker} 184*b40554a2SAndroid Build Coastguard Worker 185*b40554a2SAndroid Build Coastguard Workeropt() { 186*b40554a2SAndroid Build Coastguard Worker BOOL_OPTIONS="$BOOL_OPTIONS $1" 187*b40554a2SAndroid Build Coastguard Worker 188*b40554a2SAndroid Build Coastguard Worker local op=$1 189*b40554a2SAndroid Build Coastguard Worker local default=$2 190*b40554a2SAndroid Build Coastguard Worker shift 191*b40554a2SAndroid Build Coastguard Worker shift 192*b40554a2SAndroid Build Coastguard Worker local doc="$*" 193*b40554a2SAndroid Build Coastguard Worker local flag="" 194*b40554a2SAndroid Build Coastguard Worker 195*b40554a2SAndroid Build Coastguard Worker if [ $default -eq 0 ] 196*b40554a2SAndroid Build Coastguard Worker then 197*b40554a2SAndroid Build Coastguard Worker flag="enable" 198*b40554a2SAndroid Build Coastguard Worker else 199*b40554a2SAndroid Build Coastguard Worker flag="disable" 200*b40554a2SAndroid Build Coastguard Worker doc="don't $doc" 201*b40554a2SAndroid Build Coastguard Worker fi 202*b40554a2SAndroid Build Coastguard Worker 203*b40554a2SAndroid Build Coastguard Worker if [ $HELP -eq 0 ] 204*b40554a2SAndroid Build Coastguard Worker then 205*b40554a2SAndroid Build Coastguard Worker for arg in $CFG_ARGS 206*b40554a2SAndroid Build Coastguard Worker do 207*b40554a2SAndroid Build Coastguard Worker if [ "$arg" = "--${flag}-${op}" ] 208*b40554a2SAndroid Build Coastguard Worker then 209*b40554a2SAndroid Build Coastguard Worker op=$(echo $op | tr 'a-z-' 'A-Z_') 210*b40554a2SAndroid Build Coastguard Worker flag=$(echo $flag | tr 'a-z' 'A-Z') 211*b40554a2SAndroid Build Coastguard Worker local v="CFG_${flag}_${op}" 212*b40554a2SAndroid Build Coastguard Worker eval $v=1 213*b40554a2SAndroid Build Coastguard Worker putvar $v 214*b40554a2SAndroid Build Coastguard Worker fi 215*b40554a2SAndroid Build Coastguard Worker done 216*b40554a2SAndroid Build Coastguard Worker else 217*b40554a2SAndroid Build Coastguard Worker if [ ! -z "${META-}" ] 218*b40554a2SAndroid Build Coastguard Worker then 219*b40554a2SAndroid Build Coastguard Worker op="$op=<$META>" 220*b40554a2SAndroid Build Coastguard Worker fi 221*b40554a2SAndroid Build Coastguard Worker printf " --%-30s %s\n" "$flag-$op" "$doc" 222*b40554a2SAndroid Build Coastguard Worker fi 223*b40554a2SAndroid Build Coastguard Worker} 224*b40554a2SAndroid Build Coastguard Worker 225*b40554a2SAndroid Build Coastguard Workerflag() { 226*b40554a2SAndroid Build Coastguard Worker BOOL_OPTIONS="$BOOL_OPTIONS $1" 227*b40554a2SAndroid Build Coastguard Worker 228*b40554a2SAndroid Build Coastguard Worker local op=$1 229*b40554a2SAndroid Build Coastguard Worker shift 230*b40554a2SAndroid Build Coastguard Worker local doc="$*" 231*b40554a2SAndroid Build Coastguard Worker 232*b40554a2SAndroid Build Coastguard Worker if [ $HELP -eq 0 ] 233*b40554a2SAndroid Build Coastguard Worker then 234*b40554a2SAndroid Build Coastguard Worker for arg in $CFG_ARGS 235*b40554a2SAndroid Build Coastguard Worker do 236*b40554a2SAndroid Build Coastguard Worker if [ "$arg" = "--${op}" ] 237*b40554a2SAndroid Build Coastguard Worker then 238*b40554a2SAndroid Build Coastguard Worker op=$(echo $op | tr 'a-z-' 'A-Z_') 239*b40554a2SAndroid Build Coastguard Worker local v="CFG_${op}" 240*b40554a2SAndroid Build Coastguard Worker eval $v=1 241*b40554a2SAndroid Build Coastguard Worker putvar $v 242*b40554a2SAndroid Build Coastguard Worker fi 243*b40554a2SAndroid Build Coastguard Worker done 244*b40554a2SAndroid Build Coastguard Worker else 245*b40554a2SAndroid Build Coastguard Worker if [ ! -z "${META-}" ] 246*b40554a2SAndroid Build Coastguard Worker then 247*b40554a2SAndroid Build Coastguard Worker op="$op=<$META>" 248*b40554a2SAndroid Build Coastguard Worker fi 249*b40554a2SAndroid Build Coastguard Worker printf " --%-30s %s\n" "$op" "$doc" 250*b40554a2SAndroid Build Coastguard Worker fi 251*b40554a2SAndroid Build Coastguard Worker} 252*b40554a2SAndroid Build Coastguard Worker 253*b40554a2SAndroid Build Coastguard Workervalidate_opt () { 254*b40554a2SAndroid Build Coastguard Worker for arg in $CFG_ARGS 255*b40554a2SAndroid Build Coastguard Worker do 256*b40554a2SAndroid Build Coastguard Worker local is_arg_valid=0 257*b40554a2SAndroid Build Coastguard Worker for option in $BOOL_OPTIONS 258*b40554a2SAndroid Build Coastguard Worker do 259*b40554a2SAndroid Build Coastguard Worker if test --disable-$option = $arg 260*b40554a2SAndroid Build Coastguard Worker then 261*b40554a2SAndroid Build Coastguard Worker is_arg_valid=1 262*b40554a2SAndroid Build Coastguard Worker fi 263*b40554a2SAndroid Build Coastguard Worker if test --enable-$option = $arg 264*b40554a2SAndroid Build Coastguard Worker then 265*b40554a2SAndroid Build Coastguard Worker is_arg_valid=1 266*b40554a2SAndroid Build Coastguard Worker fi 267*b40554a2SAndroid Build Coastguard Worker if test --$option = $arg 268*b40554a2SAndroid Build Coastguard Worker then 269*b40554a2SAndroid Build Coastguard Worker is_arg_valid=1 270*b40554a2SAndroid Build Coastguard Worker fi 271*b40554a2SAndroid Build Coastguard Worker done 272*b40554a2SAndroid Build Coastguard Worker for option in $VAL_OPTIONS 273*b40554a2SAndroid Build Coastguard Worker do 274*b40554a2SAndroid Build Coastguard Worker if echo "$arg" | grep -q -- "--$option=" 275*b40554a2SAndroid Build Coastguard Worker then 276*b40554a2SAndroid Build Coastguard Worker is_arg_valid=1 277*b40554a2SAndroid Build Coastguard Worker fi 278*b40554a2SAndroid Build Coastguard Worker done 279*b40554a2SAndroid Build Coastguard Worker if [ "$arg" = "--help" ] 280*b40554a2SAndroid Build Coastguard Worker then 281*b40554a2SAndroid Build Coastguard Worker echo 282*b40554a2SAndroid Build Coastguard Worker echo "No more help available for Configure options," 283*b40554a2SAndroid Build Coastguard Worker echo "check the Wiki or join our IRC channel" 284*b40554a2SAndroid Build Coastguard Worker break 285*b40554a2SAndroid Build Coastguard Worker else 286*b40554a2SAndroid Build Coastguard Worker if test $is_arg_valid -eq 0 287*b40554a2SAndroid Build Coastguard Worker then 288*b40554a2SAndroid Build Coastguard Worker err "Option '$arg' is not recognized" 289*b40554a2SAndroid Build Coastguard Worker fi 290*b40554a2SAndroid Build Coastguard Worker fi 291*b40554a2SAndroid Build Coastguard Worker done 292*b40554a2SAndroid Build Coastguard Worker} 293*b40554a2SAndroid Build Coastguard Worker 294*b40554a2SAndroid Build Coastguard Workerabsolutify() { 295*b40554a2SAndroid Build Coastguard Worker local file_path="$1" 296*b40554a2SAndroid Build Coastguard Worker local file_path_dirname="$(dirname "$file_path")" 297*b40554a2SAndroid Build Coastguard Worker local file_path_basename="$(basename "$file_path")" 298*b40554a2SAndroid Build Coastguard Worker local file_abs_path="$(abs_path "$file_path_dirname")" 299*b40554a2SAndroid Build Coastguard Worker local file_path="$file_abs_path/$file_path_basename" 300*b40554a2SAndroid Build Coastguard Worker # This is the return value 301*b40554a2SAndroid Build Coastguard Worker RETVAL="$file_path" 302*b40554a2SAndroid Build Coastguard Worker} 303*b40554a2SAndroid Build Coastguard Worker 304*b40554a2SAndroid Build Coastguard Worker# Prints the absolute path of a directory to stdout 305*b40554a2SAndroid Build Coastguard Workerabs_path() { 306*b40554a2SAndroid Build Coastguard Worker local path="$1" 307*b40554a2SAndroid Build Coastguard Worker # Unset CDPATH because it causes havok: it makes the destination unpredictable 308*b40554a2SAndroid Build Coastguard Worker # and triggers 'cd' to print the path to stdout. Route `cd`'s output to /dev/null 309*b40554a2SAndroid Build Coastguard Worker # for good measure. 310*b40554a2SAndroid Build Coastguard Worker (unset CDPATH && cd "$path" > /dev/null && pwd) 311*b40554a2SAndroid Build Coastguard Worker} 312*b40554a2SAndroid Build Coastguard Worker 313*b40554a2SAndroid Build Coastguard Workeruninstall_legacy() { 314*b40554a2SAndroid Build Coastguard Worker local _abs_libdir="$1" 315*b40554a2SAndroid Build Coastguard Worker 316*b40554a2SAndroid Build Coastguard Worker local _uninstalled_something=false 317*b40554a2SAndroid Build Coastguard Worker 318*b40554a2SAndroid Build Coastguard Worker # Replace commas in legacy manifest list with spaces 319*b40554a2SAndroid Build Coastguard Worker _legacy_manifest_dirs=`echo "$TEMPLATE_LEGACY_MANIFEST_DIRS" | sed "s/,/ /g"` 320*b40554a2SAndroid Build Coastguard Worker 321*b40554a2SAndroid Build Coastguard Worker # Uninstall from legacy manifests 322*b40554a2SAndroid Build Coastguard Worker local _md 323*b40554a2SAndroid Build Coastguard Worker for _md in $_legacy_manifest_dirs; do 324*b40554a2SAndroid Build Coastguard Worker # First, uninstall from the installation prefix. 325*b40554a2SAndroid Build Coastguard Worker # Errors are warnings - try to rm everything in the manifest even if some fail. 326*b40554a2SAndroid Build Coastguard Worker if [ -f "$_abs_libdir/$_md/manifest" ] 327*b40554a2SAndroid Build Coastguard Worker then 328*b40554a2SAndroid Build Coastguard Worker 329*b40554a2SAndroid Build Coastguard Worker # iterate through installed manifest and remove files 330*b40554a2SAndroid Build Coastguard Worker local _p; 331*b40554a2SAndroid Build Coastguard Worker while read _p; do 332*b40554a2SAndroid Build Coastguard Worker # the installed manifest contains absolute paths 333*b40554a2SAndroid Build Coastguard Worker msg "removing legacy file $_p" 334*b40554a2SAndroid Build Coastguard Worker if [ -f "$_p" ] 335*b40554a2SAndroid Build Coastguard Worker then 336*b40554a2SAndroid Build Coastguard Worker run rm -f "$_p" 337*b40554a2SAndroid Build Coastguard Worker want_ok "failed to remove $_p" 338*b40554a2SAndroid Build Coastguard Worker else 339*b40554a2SAndroid Build Coastguard Worker warn "supposedly installed file $_p does not exist!" 340*b40554a2SAndroid Build Coastguard Worker fi 341*b40554a2SAndroid Build Coastguard Worker done < "$_abs_libdir/$_md/manifest" 342*b40554a2SAndroid Build Coastguard Worker 343*b40554a2SAndroid Build Coastguard Worker # If we fail to remove $md below, then the 344*b40554a2SAndroid Build Coastguard Worker # installed manifest will still be full; the installed manifest 345*b40554a2SAndroid Build Coastguard Worker # needs to be empty before install. 346*b40554a2SAndroid Build Coastguard Worker msg "removing legacy manifest $_abs_libdir/$_md/manifest" 347*b40554a2SAndroid Build Coastguard Worker run rm -f "$_abs_libdir/$_md/manifest" 348*b40554a2SAndroid Build Coastguard Worker # For the above reason, this is a hard error 349*b40554a2SAndroid Build Coastguard Worker need_ok "failed to remove installed manifest" 350*b40554a2SAndroid Build Coastguard Worker 351*b40554a2SAndroid Build Coastguard Worker # Remove $template_rel_manifest_dir directory 352*b40554a2SAndroid Build Coastguard Worker msg "removing legacy manifest dir $_abs_libdir/$_md" 353*b40554a2SAndroid Build Coastguard Worker run rm -R "$_abs_libdir/$_md" 354*b40554a2SAndroid Build Coastguard Worker want_ok "failed to remove $_md" 355*b40554a2SAndroid Build Coastguard Worker 356*b40554a2SAndroid Build Coastguard Worker _uninstalled_something=true 357*b40554a2SAndroid Build Coastguard Worker fi 358*b40554a2SAndroid Build Coastguard Worker done 359*b40554a2SAndroid Build Coastguard Worker 360*b40554a2SAndroid Build Coastguard Worker RETVAL="$_uninstalled_something" 361*b40554a2SAndroid Build Coastguard Worker} 362*b40554a2SAndroid Build Coastguard Worker 363*b40554a2SAndroid Build Coastguard Workeruninstall_components() { 364*b40554a2SAndroid Build Coastguard Worker local _abs_libdir="$1" 365*b40554a2SAndroid Build Coastguard Worker local _dest_prefix="$2" 366*b40554a2SAndroid Build Coastguard Worker local _components="$3" 367*b40554a2SAndroid Build Coastguard Worker 368*b40554a2SAndroid Build Coastguard Worker # We're going to start by uninstalling existing components. This 369*b40554a2SAndroid Build Coastguard Worker local _uninstalled_something=false 370*b40554a2SAndroid Build Coastguard Worker 371*b40554a2SAndroid Build Coastguard Worker # First, try removing any 'legacy' manifests from before 372*b40554a2SAndroid Build Coastguard Worker # rust-installer 373*b40554a2SAndroid Build Coastguard Worker uninstall_legacy "$_abs_libdir" 374*b40554a2SAndroid Build Coastguard Worker assert_nz "$RETVAL", "RETVAL" 375*b40554a2SAndroid Build Coastguard Worker if [ "$RETVAL" = true ]; then 376*b40554a2SAndroid Build Coastguard Worker _uninstalled_something=true; 377*b40554a2SAndroid Build Coastguard Worker fi 378*b40554a2SAndroid Build Coastguard Worker 379*b40554a2SAndroid Build Coastguard Worker # Load the version of the installed installer 380*b40554a2SAndroid Build Coastguard Worker local _installed_version= 381*b40554a2SAndroid Build Coastguard Worker if [ -f "$abs_libdir/$TEMPLATE_REL_MANIFEST_DIR/rust-installer-version" ]; then 382*b40554a2SAndroid Build Coastguard Worker _installed_version=`cat "$_abs_libdir/$TEMPLATE_REL_MANIFEST_DIR/rust-installer-version"` 383*b40554a2SAndroid Build Coastguard Worker 384*b40554a2SAndroid Build Coastguard Worker # Sanity check 385*b40554a2SAndroid Build Coastguard Worker if [ ! -n "$_installed_version" ]; then critical_err "rust installer version is empty"; fi 386*b40554a2SAndroid Build Coastguard Worker fi 387*b40554a2SAndroid Build Coastguard Worker 388*b40554a2SAndroid Build Coastguard Worker # If there's something installed, then uninstall 389*b40554a2SAndroid Build Coastguard Worker if [ -n "$_installed_version" ]; then 390*b40554a2SAndroid Build Coastguard Worker # Check the version of the installed installer 391*b40554a2SAndroid Build Coastguard Worker case "$_installed_version" in 392*b40554a2SAndroid Build Coastguard Worker 393*b40554a2SAndroid Build Coastguard Worker # If this is a previous version, then upgrade in place to the 394*b40554a2SAndroid Build Coastguard Worker # current version before uninstalling. 395*b40554a2SAndroid Build Coastguard Worker 2 ) 396*b40554a2SAndroid Build Coastguard Worker # The only change between version 2 -> 3 is that components are placed 397*b40554a2SAndroid Build Coastguard Worker # in subdirectories of the installer tarball. There are no changes 398*b40554a2SAndroid Build Coastguard Worker # to the installed data format, so nothing to do. 399*b40554a2SAndroid Build Coastguard Worker ;; 400*b40554a2SAndroid Build Coastguard Worker 401*b40554a2SAndroid Build Coastguard Worker # This is the current version. Nothing need to be done except uninstall. 402*b40554a2SAndroid Build Coastguard Worker "$TEMPLATE_RUST_INSTALLER_VERSION") 403*b40554a2SAndroid Build Coastguard Worker ;; 404*b40554a2SAndroid Build Coastguard Worker 405*b40554a2SAndroid Build Coastguard Worker # If this is an unknown (future) version then bail. 406*b40554a2SAndroid Build Coastguard Worker * ) 407*b40554a2SAndroid Build Coastguard Worker echo "The copy of $TEMPLATE_PRODUCT_NAME at $_dest_prefix was installed using an" 408*b40554a2SAndroid Build Coastguard Worker echo "unknown version ($_installed_version) of rust-installer." 409*b40554a2SAndroid Build Coastguard Worker echo "Uninstall it first with the installer used for the original installation" 410*b40554a2SAndroid Build Coastguard Worker echo "before continuing." 411*b40554a2SAndroid Build Coastguard Worker exit 1 412*b40554a2SAndroid Build Coastguard Worker ;; 413*b40554a2SAndroid Build Coastguard Worker esac 414*b40554a2SAndroid Build Coastguard Worker 415*b40554a2SAndroid Build Coastguard Worker local _md="$_abs_libdir/$TEMPLATE_REL_MANIFEST_DIR" 416*b40554a2SAndroid Build Coastguard Worker local _installed_components="$(cat "$_md/components")" 417*b40554a2SAndroid Build Coastguard Worker 418*b40554a2SAndroid Build Coastguard Worker # Uninstall (our components only) before reinstalling 419*b40554a2SAndroid Build Coastguard Worker local _available_component 420*b40554a2SAndroid Build Coastguard Worker for _available_component in $_components; do 421*b40554a2SAndroid Build Coastguard Worker local _installed_component 422*b40554a2SAndroid Build Coastguard Worker for _installed_component in $_installed_components; do 423*b40554a2SAndroid Build Coastguard Worker if [ "$_available_component" = "$_installed_component" ]; then 424*b40554a2SAndroid Build Coastguard Worker msg "uninstalling component '$_available_component'" 425*b40554a2SAndroid Build Coastguard Worker local _component_manifest="$_md/manifest-$_installed_component" 426*b40554a2SAndroid Build Coastguard Worker 427*b40554a2SAndroid Build Coastguard Worker # Sanity check: there should be a component manifest 428*b40554a2SAndroid Build Coastguard Worker if [ ! -f "$_component_manifest" ]; then 429*b40554a2SAndroid Build Coastguard Worker critical_err "installed component '$_installed_component' has no manifest" 430*b40554a2SAndroid Build Coastguard Worker fi 431*b40554a2SAndroid Build Coastguard Worker 432*b40554a2SAndroid Build Coastguard Worker # Iterate through installed component manifest and remove files 433*b40554a2SAndroid Build Coastguard Worker local _directive 434*b40554a2SAndroid Build Coastguard Worker while read _directive; do 435*b40554a2SAndroid Build Coastguard Worker 436*b40554a2SAndroid Build Coastguard Worker local _command=`echo $_directive | cut -f1 -d:` 437*b40554a2SAndroid Build Coastguard Worker local _file=`echo $_directive | cut -f2 -d:` 438*b40554a2SAndroid Build Coastguard Worker 439*b40554a2SAndroid Build Coastguard Worker # Sanity checks 440*b40554a2SAndroid Build Coastguard Worker if [ ! -n "$_command" ]; then critical_err "malformed installation directive"; fi 441*b40554a2SAndroid Build Coastguard Worker if [ ! -n "$_file" ]; then critical_err "malformed installation directive"; fi 442*b40554a2SAndroid Build Coastguard Worker 443*b40554a2SAndroid Build Coastguard Worker case "$_command" in 444*b40554a2SAndroid Build Coastguard Worker file) 445*b40554a2SAndroid Build Coastguard Worker verbose_msg "removing file $_file" 446*b40554a2SAndroid Build Coastguard Worker if [ -f "$_file" ]; then 447*b40554a2SAndroid Build Coastguard Worker run rm -f "$_file" 448*b40554a2SAndroid Build Coastguard Worker want_ok "failed to remove $_file" 449*b40554a2SAndroid Build Coastguard Worker else 450*b40554a2SAndroid Build Coastguard Worker warn "supposedly installed file $_file does not exist!" 451*b40554a2SAndroid Build Coastguard Worker fi 452*b40554a2SAndroid Build Coastguard Worker ;; 453*b40554a2SAndroid Build Coastguard Worker 454*b40554a2SAndroid Build Coastguard Worker dir) 455*b40554a2SAndroid Build Coastguard Worker verbose_msg "removing directory $_file" 456*b40554a2SAndroid Build Coastguard Worker run rm -r "$_file" 457*b40554a2SAndroid Build Coastguard Worker want_ok "unable to remove directory $_file" 458*b40554a2SAndroid Build Coastguard Worker ;; 459*b40554a2SAndroid Build Coastguard Worker 460*b40554a2SAndroid Build Coastguard Worker *) 461*b40554a2SAndroid Build Coastguard Worker critical_err "unknown installation directive" 462*b40554a2SAndroid Build Coastguard Worker ;; 463*b40554a2SAndroid Build Coastguard Worker esac 464*b40554a2SAndroid Build Coastguard Worker 465*b40554a2SAndroid Build Coastguard Worker done < "$_component_manifest" 466*b40554a2SAndroid Build Coastguard Worker 467*b40554a2SAndroid Build Coastguard Worker # Remove the installed component manifest 468*b40554a2SAndroid Build Coastguard Worker verbose_msg "removing component manifest $_component_manifest" 469*b40554a2SAndroid Build Coastguard Worker run rm "$_component_manifest" 470*b40554a2SAndroid Build Coastguard Worker # This is a hard error because the installation is unrecoverable 471*b40554a2SAndroid Build Coastguard Worker local _err_cant_r_manifest="failed to remove installed manifest for component" 472*b40554a2SAndroid Build Coastguard Worker critical_need_ok "$_err_cant_r_manifest '$_installed_component'" 473*b40554a2SAndroid Build Coastguard Worker 474*b40554a2SAndroid Build Coastguard Worker # Update the installed component list 475*b40554a2SAndroid Build Coastguard Worker local _modified_components="$(sed "/^$_installed_component\$/d" "$_md/components")" 476*b40554a2SAndroid Build Coastguard Worker write_to_file "$_modified_components" "$_md/components" 477*b40554a2SAndroid Build Coastguard Worker critical_need_ok "failed to update installed component list" 478*b40554a2SAndroid Build Coastguard Worker fi 479*b40554a2SAndroid Build Coastguard Worker done 480*b40554a2SAndroid Build Coastguard Worker done 481*b40554a2SAndroid Build Coastguard Worker 482*b40554a2SAndroid Build Coastguard Worker # If there are no remaining components delete the manifest directory, 483*b40554a2SAndroid Build Coastguard Worker # but only if we're doing an uninstall - if we're doing an install, 484*b40554a2SAndroid Build Coastguard Worker # then leave the manifest directory around to hang onto the logs, 485*b40554a2SAndroid Build Coastguard Worker # and any files not managed by the installer. 486*b40554a2SAndroid Build Coastguard Worker if [ -n "${CFG_UNINSTALL-}" ]; then 487*b40554a2SAndroid Build Coastguard Worker local _remaining_components="$(cat "$_md/components")" 488*b40554a2SAndroid Build Coastguard Worker if [ ! -n "$_remaining_components" ]; then 489*b40554a2SAndroid Build Coastguard Worker verbose_msg "removing manifest directory $_md" 490*b40554a2SAndroid Build Coastguard Worker run rm -r "$_md" 491*b40554a2SAndroid Build Coastguard Worker want_ok "failed to remove $_md" 492*b40554a2SAndroid Build Coastguard Worker 493*b40554a2SAndroid Build Coastguard Worker maybe_unconfigure_ld 494*b40554a2SAndroid Build Coastguard Worker fi 495*b40554a2SAndroid Build Coastguard Worker fi 496*b40554a2SAndroid Build Coastguard Worker 497*b40554a2SAndroid Build Coastguard Worker _uninstalled_something=true 498*b40554a2SAndroid Build Coastguard Worker fi 499*b40554a2SAndroid Build Coastguard Worker 500*b40554a2SAndroid Build Coastguard Worker # There's no installed version. If we were asked to uninstall, then that's a problem. 501*b40554a2SAndroid Build Coastguard Worker if [ -n "${CFG_UNINSTALL-}" -a "$_uninstalled_something" = false ] 502*b40554a2SAndroid Build Coastguard Worker then 503*b40554a2SAndroid Build Coastguard Worker err "unable to find installation manifest at $CFG_LIBDIR/$TEMPLATE_REL_MANIFEST_DIR" 504*b40554a2SAndroid Build Coastguard Worker fi 505*b40554a2SAndroid Build Coastguard Worker} 506*b40554a2SAndroid Build Coastguard Worker 507*b40554a2SAndroid Build Coastguard Workerinstall_components() { 508*b40554a2SAndroid Build Coastguard Worker local _src_dir="$1" 509*b40554a2SAndroid Build Coastguard Worker local _abs_libdir="$2" 510*b40554a2SAndroid Build Coastguard Worker local _dest_prefix="$3" 511*b40554a2SAndroid Build Coastguard Worker local _components="$4" 512*b40554a2SAndroid Build Coastguard Worker 513*b40554a2SAndroid Build Coastguard Worker local _component 514*b40554a2SAndroid Build Coastguard Worker for _component in $_components; do 515*b40554a2SAndroid Build Coastguard Worker 516*b40554a2SAndroid Build Coastguard Worker msg "installing component '$_component'" 517*b40554a2SAndroid Build Coastguard Worker 518*b40554a2SAndroid Build Coastguard Worker # The file name of the manifest we're installing from 519*b40554a2SAndroid Build Coastguard Worker local _input_manifest="$_src_dir/$_component/manifest.in" 520*b40554a2SAndroid Build Coastguard Worker 521*b40554a2SAndroid Build Coastguard Worker # Sanity check: do we have our input manifests? 522*b40554a2SAndroid Build Coastguard Worker if [ ! -f "$_input_manifest" ]; then 523*b40554a2SAndroid Build Coastguard Worker critical_err "manifest for $_component does not exist at $_input_manifest" 524*b40554a2SAndroid Build Coastguard Worker fi 525*b40554a2SAndroid Build Coastguard Worker 526*b40554a2SAndroid Build Coastguard Worker # The installed manifest directory 527*b40554a2SAndroid Build Coastguard Worker local _md="$_abs_libdir/$TEMPLATE_REL_MANIFEST_DIR" 528*b40554a2SAndroid Build Coastguard Worker 529*b40554a2SAndroid Build Coastguard Worker # The file name of the manifest we're going to create during install 530*b40554a2SAndroid Build Coastguard Worker local _installed_manifest="$_md/manifest-$_component" 531*b40554a2SAndroid Build Coastguard Worker 532*b40554a2SAndroid Build Coastguard Worker # Create the installed manifest, which we will fill in with absolute file paths 533*b40554a2SAndroid Build Coastguard Worker touch "$_installed_manifest" 534*b40554a2SAndroid Build Coastguard Worker critical_need_ok "failed to create installed manifest" 535*b40554a2SAndroid Build Coastguard Worker 536*b40554a2SAndroid Build Coastguard Worker # Add this component to the installed component list 537*b40554a2SAndroid Build Coastguard Worker append_to_file "$_component" "$_md/components" 538*b40554a2SAndroid Build Coastguard Worker critical_need_ok "failed to update components list for $_component" 539*b40554a2SAndroid Build Coastguard Worker 540*b40554a2SAndroid Build Coastguard Worker # Now install, iterate through the new manifest and copy files 541*b40554a2SAndroid Build Coastguard Worker local _directive 542*b40554a2SAndroid Build Coastguard Worker while read _directive; do 543*b40554a2SAndroid Build Coastguard Worker 544*b40554a2SAndroid Build Coastguard Worker local _command=`echo $_directive | cut -f1 -d:` 545*b40554a2SAndroid Build Coastguard Worker local _file=`echo $_directive | cut -f2 -d:` 546*b40554a2SAndroid Build Coastguard Worker 547*b40554a2SAndroid Build Coastguard Worker # Sanity checks 548*b40554a2SAndroid Build Coastguard Worker if [ ! -n "$_command" ]; then critical_err "malformed installation directive"; fi 549*b40554a2SAndroid Build Coastguard Worker if [ ! -n "$_file" ]; then critical_err "malformed installation directive"; fi 550*b40554a2SAndroid Build Coastguard Worker 551*b40554a2SAndroid Build Coastguard Worker # Decide the destination of the file 552*b40554a2SAndroid Build Coastguard Worker local _file_install_path="$_dest_prefix/$_file" 553*b40554a2SAndroid Build Coastguard Worker 554*b40554a2SAndroid Build Coastguard Worker if echo "$_file" | grep "^etc/" > /dev/null 555*b40554a2SAndroid Build Coastguard Worker then 556*b40554a2SAndroid Build Coastguard Worker local _f="$(echo "$_file" | sed 's/^etc\///')" 557*b40554a2SAndroid Build Coastguard Worker _file_install_path="$CFG_SYSCONFDIR/$_f" 558*b40554a2SAndroid Build Coastguard Worker fi 559*b40554a2SAndroid Build Coastguard Worker 560*b40554a2SAndroid Build Coastguard Worker if echo "$_file" | grep "^bin/" > /dev/null 561*b40554a2SAndroid Build Coastguard Worker then 562*b40554a2SAndroid Build Coastguard Worker local _f="$(echo "$_file" | sed 's/^bin\///')" 563*b40554a2SAndroid Build Coastguard Worker _file_install_path="$CFG_BINDIR/$_f" 564*b40554a2SAndroid Build Coastguard Worker fi 565*b40554a2SAndroid Build Coastguard Worker 566*b40554a2SAndroid Build Coastguard Worker if echo "$_file" | grep "^lib/" > /dev/null 567*b40554a2SAndroid Build Coastguard Worker then 568*b40554a2SAndroid Build Coastguard Worker local _f="$(echo "$_file" | sed 's/^lib\///')" 569*b40554a2SAndroid Build Coastguard Worker _file_install_path="$CFG_LIBDIR/$_f" 570*b40554a2SAndroid Build Coastguard Worker fi 571*b40554a2SAndroid Build Coastguard Worker 572*b40554a2SAndroid Build Coastguard Worker if echo "$_file" | grep "^share" > /dev/null 573*b40554a2SAndroid Build Coastguard Worker then 574*b40554a2SAndroid Build Coastguard Worker local _f="$(echo "$_file" | sed 's/^share\///')" 575*b40554a2SAndroid Build Coastguard Worker _file_install_path="$CFG_DATADIR/$_f" 576*b40554a2SAndroid Build Coastguard Worker fi 577*b40554a2SAndroid Build Coastguard Worker 578*b40554a2SAndroid Build Coastguard Worker if echo "$_file" | grep "^share/man/" > /dev/null 579*b40554a2SAndroid Build Coastguard Worker then 580*b40554a2SAndroid Build Coastguard Worker local _f="$(echo "$_file" | sed 's/^share\/man\///')" 581*b40554a2SAndroid Build Coastguard Worker _file_install_path="$CFG_MANDIR/$_f" 582*b40554a2SAndroid Build Coastguard Worker fi 583*b40554a2SAndroid Build Coastguard Worker 584*b40554a2SAndroid Build Coastguard Worker # HACK: Try to support overriding --docdir. Paths with the form 585*b40554a2SAndroid Build Coastguard Worker # "share/doc/$product/" can be redirected to a single --docdir 586*b40554a2SAndroid Build Coastguard Worker # path. If the following detects that --docdir has been specified 587*b40554a2SAndroid Build Coastguard Worker # then it will replace everything preceeding the "$product" path 588*b40554a2SAndroid Build Coastguard Worker # component. The problem here is that the combined rust installer 589*b40554a2SAndroid Build Coastguard Worker # contains two "products": rust and cargo; so the contents of those 590*b40554a2SAndroid Build Coastguard Worker # directories will both be dumped into the same directory; and the 591*b40554a2SAndroid Build Coastguard Worker # contents of those directories are _not_ disjoint. Since this feature 592*b40554a2SAndroid Build Coastguard Worker # is almost entirely to support 'make install' anyway I don't expect 593*b40554a2SAndroid Build Coastguard Worker # this problem to be a big deal in practice. 594*b40554a2SAndroid Build Coastguard Worker if [ "$CFG_DOCDIR" != "<default>" ] 595*b40554a2SAndroid Build Coastguard Worker then 596*b40554a2SAndroid Build Coastguard Worker if echo "$_file" | grep "^share/doc/" > /dev/null 597*b40554a2SAndroid Build Coastguard Worker then 598*b40554a2SAndroid Build Coastguard Worker local _f="$(echo "$_file" | sed 's/^share\/doc\/[^/]*\///')" 599*b40554a2SAndroid Build Coastguard Worker _file_install_path="$CFG_DOCDIR/$_f" 600*b40554a2SAndroid Build Coastguard Worker fi 601*b40554a2SAndroid Build Coastguard Worker fi 602*b40554a2SAndroid Build Coastguard Worker 603*b40554a2SAndroid Build Coastguard Worker # Make sure there's a directory for it 604*b40554a2SAndroid Build Coastguard Worker make_dir_recursive "$(dirname "$_file_install_path")" 605*b40554a2SAndroid Build Coastguard Worker critical_need_ok "directory creation failed" 606*b40554a2SAndroid Build Coastguard Worker 607*b40554a2SAndroid Build Coastguard Worker # Make the path absolute so we can uninstall it later without 608*b40554a2SAndroid Build Coastguard Worker # starting from the installation cwd 609*b40554a2SAndroid Build Coastguard Worker absolutify "$_file_install_path" 610*b40554a2SAndroid Build Coastguard Worker _file_install_path="$RETVAL" 611*b40554a2SAndroid Build Coastguard Worker assert_nz "$_file_install_path" "file_install_path" 612*b40554a2SAndroid Build Coastguard Worker 613*b40554a2SAndroid Build Coastguard Worker case "$_command" in 614*b40554a2SAndroid Build Coastguard Worker file ) 615*b40554a2SAndroid Build Coastguard Worker 616*b40554a2SAndroid Build Coastguard Worker verbose_msg "copying file $_file_install_path" 617*b40554a2SAndroid Build Coastguard Worker 618*b40554a2SAndroid Build Coastguard Worker maybe_backup_path "$_file_install_path" 619*b40554a2SAndroid Build Coastguard Worker 620*b40554a2SAndroid Build Coastguard Worker if echo "$_file" | grep "^bin/" > /dev/null || test -x "$_src_dir/$_component/$_file" 621*b40554a2SAndroid Build Coastguard Worker then 622*b40554a2SAndroid Build Coastguard Worker run cp "$_src_dir/$_component/$_file" "$_file_install_path" 623*b40554a2SAndroid Build Coastguard Worker run chmod 755 "$_file_install_path" 624*b40554a2SAndroid Build Coastguard Worker else 625*b40554a2SAndroid Build Coastguard Worker run cp "$_src_dir/$_component/$_file" "$_file_install_path" 626*b40554a2SAndroid Build Coastguard Worker run chmod 644 "$_file_install_path" 627*b40554a2SAndroid Build Coastguard Worker fi 628*b40554a2SAndroid Build Coastguard Worker critical_need_ok "file creation failed" 629*b40554a2SAndroid Build Coastguard Worker 630*b40554a2SAndroid Build Coastguard Worker # Update the manifest 631*b40554a2SAndroid Build Coastguard Worker append_to_file "file:$_file_install_path" "$_installed_manifest" 632*b40554a2SAndroid Build Coastguard Worker critical_need_ok "failed to update manifest" 633*b40554a2SAndroid Build Coastguard Worker 634*b40554a2SAndroid Build Coastguard Worker ;; 635*b40554a2SAndroid Build Coastguard Worker 636*b40554a2SAndroid Build Coastguard Worker dir ) 637*b40554a2SAndroid Build Coastguard Worker 638*b40554a2SAndroid Build Coastguard Worker verbose_msg "copying directory $_file_install_path" 639*b40554a2SAndroid Build Coastguard Worker 640*b40554a2SAndroid Build Coastguard Worker maybe_backup_path "$_file_install_path" 641*b40554a2SAndroid Build Coastguard Worker 642*b40554a2SAndroid Build Coastguard Worker run cp -R "$_src_dir/$_component/$_file" "$_file_install_path" 643*b40554a2SAndroid Build Coastguard Worker critical_need_ok "failed to copy directory" 644*b40554a2SAndroid Build Coastguard Worker 645*b40554a2SAndroid Build Coastguard Worker # Set permissions. 0755 for dirs, 644 for files 646*b40554a2SAndroid Build Coastguard Worker run chmod -R u+rwX,go+rX,go-w "$_file_install_path" 647*b40554a2SAndroid Build Coastguard Worker critical_need_ok "failed to set permissions on directory" 648*b40554a2SAndroid Build Coastguard Worker 649*b40554a2SAndroid Build Coastguard Worker # Update the manifest 650*b40554a2SAndroid Build Coastguard Worker append_to_file "dir:$_file_install_path" "$_installed_manifest" 651*b40554a2SAndroid Build Coastguard Worker critical_need_ok "failed to update manifest" 652*b40554a2SAndroid Build Coastguard Worker ;; 653*b40554a2SAndroid Build Coastguard Worker 654*b40554a2SAndroid Build Coastguard Worker *) 655*b40554a2SAndroid Build Coastguard Worker critical_err "unknown installation directive" 656*b40554a2SAndroid Build Coastguard Worker ;; 657*b40554a2SAndroid Build Coastguard Worker esac 658*b40554a2SAndroid Build Coastguard Worker done < "$_input_manifest" 659*b40554a2SAndroid Build Coastguard Worker 660*b40554a2SAndroid Build Coastguard Worker done 661*b40554a2SAndroid Build Coastguard Worker} 662*b40554a2SAndroid Build Coastguard Worker 663*b40554a2SAndroid Build Coastguard Workermaybe_configure_ld() { 664*b40554a2SAndroid Build Coastguard Worker local _abs_libdir="$1" 665*b40554a2SAndroid Build Coastguard Worker 666*b40554a2SAndroid Build Coastguard Worker local _ostype="$(uname -s)" 667*b40554a2SAndroid Build Coastguard Worker assert_nz "$_ostype" "ostype" 668*b40554a2SAndroid Build Coastguard Worker 669*b40554a2SAndroid Build Coastguard Worker if [ "$_ostype" = "Linux" -a ! -n "${CFG_DISABLE_LDCONFIG-}" ]; then 670*b40554a2SAndroid Build Coastguard Worker 671*b40554a2SAndroid Build Coastguard Worker # Fedora-based systems do not configure the dynamic linker to look 672*b40554a2SAndroid Build Coastguard Worker # /usr/local/lib, which is our default installation directory. To 673*b40554a2SAndroid Build Coastguard Worker # make things just work, try to put that directory in 674*b40554a2SAndroid Build Coastguard Worker # /etc/ld.so.conf.d/rust-installer-v1 so ldconfig picks it up. 675*b40554a2SAndroid Build Coastguard Worker # Issue #30. 676*b40554a2SAndroid Build Coastguard Worker # 677*b40554a2SAndroid Build Coastguard Worker # This will get rm'd when the last component is uninstalled in 678*b40554a2SAndroid Build Coastguard Worker # maybe_unconfigure_ld. 679*b40554a2SAndroid Build Coastguard Worker if [ "$_abs_libdir" = "/usr/local/lib" -a -d "/etc/ld.so.conf.d" ]; then 680*b40554a2SAndroid Build Coastguard Worker echo "$_abs_libdir" > "/etc/ld.so.conf.d/rust-installer-v1-$TEMPLATE_REL_MANIFEST_DIR.conf" 681*b40554a2SAndroid Build Coastguard Worker if [ $? -ne 0 ]; then 682*b40554a2SAndroid Build Coastguard Worker # This shouldn't happen if we've gotten this far 683*b40554a2SAndroid Build Coastguard Worker # installing to /usr/local 684*b40554a2SAndroid Build Coastguard Worker warn "failed to update /etc/ld.so.conf.d. this is unexpected" 685*b40554a2SAndroid Build Coastguard Worker fi 686*b40554a2SAndroid Build Coastguard Worker fi 687*b40554a2SAndroid Build Coastguard Worker 688*b40554a2SAndroid Build Coastguard Worker verbose_msg "running ldconfig" 689*b40554a2SAndroid Build Coastguard Worker if [ -n "${CFG_VERBOSE-}" ]; then 690*b40554a2SAndroid Build Coastguard Worker ldconfig 691*b40554a2SAndroid Build Coastguard Worker else 692*b40554a2SAndroid Build Coastguard Worker ldconfig 2> /dev/null 693*b40554a2SAndroid Build Coastguard Worker fi 694*b40554a2SAndroid Build Coastguard Worker if [ $? -ne 0 ] 695*b40554a2SAndroid Build Coastguard Worker then 696*b40554a2SAndroid Build Coastguard Worker local _warn_s="failed to run ldconfig. this may happen when \ 697*b40554a2SAndroid Build Coastguard Workernot installing as root. run with --verbose to see the error" 698*b40554a2SAndroid Build Coastguard Worker warn "$_warn_s" 699*b40554a2SAndroid Build Coastguard Worker fi 700*b40554a2SAndroid Build Coastguard Worker fi 701*b40554a2SAndroid Build Coastguard Worker} 702*b40554a2SAndroid Build Coastguard Worker 703*b40554a2SAndroid Build Coastguard Workermaybe_unconfigure_ld() { 704*b40554a2SAndroid Build Coastguard Worker local _ostype="$(uname -s)" 705*b40554a2SAndroid Build Coastguard Worker assert_nz "$_ostype" "ostype" 706*b40554a2SAndroid Build Coastguard Worker 707*b40554a2SAndroid Build Coastguard Worker if [ "$_ostype" != "Linux" ]; then 708*b40554a2SAndroid Build Coastguard Worker return 0 709*b40554a2SAndroid Build Coastguard Worker fi 710*b40554a2SAndroid Build Coastguard Worker 711*b40554a2SAndroid Build Coastguard Worker rm "/etc/ld.so.conf.d/rust-installer-v1-$TEMPLATE_REL_MANIFEST_DIR.conf" 2> /dev/null 712*b40554a2SAndroid Build Coastguard Worker # Above may fail since that file may not have been created on install 713*b40554a2SAndroid Build Coastguard Worker} 714*b40554a2SAndroid Build Coastguard Worker 715*b40554a2SAndroid Build Coastguard Worker# Doing our own 'install'-like backup that is consistent across platforms 716*b40554a2SAndroid Build Coastguard Workermaybe_backup_path() { 717*b40554a2SAndroid Build Coastguard Worker local _file_install_path="$1" 718*b40554a2SAndroid Build Coastguard Worker 719*b40554a2SAndroid Build Coastguard Worker if [ -e "$_file_install_path" ]; then 720*b40554a2SAndroid Build Coastguard Worker msg "backing up existing file at $_file_install_path" 721*b40554a2SAndroid Build Coastguard Worker run mv -f "$_file_install_path" "$_file_install_path.old" 722*b40554a2SAndroid Build Coastguard Worker critical_need_ok "failed to back up $_file_install_path" 723*b40554a2SAndroid Build Coastguard Worker fi 724*b40554a2SAndroid Build Coastguard Worker} 725*b40554a2SAndroid Build Coastguard Worker 726*b40554a2SAndroid Build Coastguard Workerinstall_uninstaller() { 727*b40554a2SAndroid Build Coastguard Worker local _src_dir="$1" 728*b40554a2SAndroid Build Coastguard Worker local _src_basename="$2" 729*b40554a2SAndroid Build Coastguard Worker local _abs_libdir="$3" 730*b40554a2SAndroid Build Coastguard Worker 731*b40554a2SAndroid Build Coastguard Worker local _uninstaller="$_abs_libdir/$TEMPLATE_REL_MANIFEST_DIR/uninstall.sh" 732*b40554a2SAndroid Build Coastguard Worker msg "creating uninstall script at $_uninstaller" 733*b40554a2SAndroid Build Coastguard Worker run cp "$_src_dir/$_src_basename" "$_uninstaller" 734*b40554a2SAndroid Build Coastguard Worker critical_need_ok "unable to install uninstaller" 735*b40554a2SAndroid Build Coastguard Worker} 736*b40554a2SAndroid Build Coastguard Worker 737*b40554a2SAndroid Build Coastguard Workerdo_preflight_sanity_checks() { 738*b40554a2SAndroid Build Coastguard Worker local _src_dir="$1" 739*b40554a2SAndroid Build Coastguard Worker local _dest_prefix="$2" 740*b40554a2SAndroid Build Coastguard Worker 741*b40554a2SAndroid Build Coastguard Worker # Sanity check: can we can write to the destination? 742*b40554a2SAndroid Build Coastguard Worker verbose_msg "verifying destination is writable" 743*b40554a2SAndroid Build Coastguard Worker make_dir_recursive "$CFG_LIBDIR" 744*b40554a2SAndroid Build Coastguard Worker need_ok "can't write to destination. consider \`sudo\`." 745*b40554a2SAndroid Build Coastguard Worker touch "$CFG_LIBDIR/rust-install-probe" > /dev/null 746*b40554a2SAndroid Build Coastguard Worker if [ $? -ne 0 ] 747*b40554a2SAndroid Build Coastguard Worker then 748*b40554a2SAndroid Build Coastguard Worker err "can't write to destination. consider \`sudo\`." 749*b40554a2SAndroid Build Coastguard Worker fi 750*b40554a2SAndroid Build Coastguard Worker rm "$CFG_LIBDIR/rust-install-probe" 751*b40554a2SAndroid Build Coastguard Worker need_ok "failed to remove install probe" 752*b40554a2SAndroid Build Coastguard Worker 753*b40554a2SAndroid Build Coastguard Worker # Sanity check: don't install to the directory containing the installer. 754*b40554a2SAndroid Build Coastguard Worker # That would surely cause chaos. 755*b40554a2SAndroid Build Coastguard Worker verbose_msg "verifying destination is not the same as source" 756*b40554a2SAndroid Build Coastguard Worker local _prefix_dir="$(abs_path "$dest_prefix")" 757*b40554a2SAndroid Build Coastguard Worker if [ "$_src_dir" = "$_dest_prefix" -a "${CFG_UNINSTALL-}" != 1 ]; then 758*b40554a2SAndroid Build Coastguard Worker err "cannot install to same directory as installer" 759*b40554a2SAndroid Build Coastguard Worker fi 760*b40554a2SAndroid Build Coastguard Worker} 761*b40554a2SAndroid Build Coastguard Worker 762*b40554a2SAndroid Build Coastguard Workerverbose_msg "looking for install programs" 763*b40554a2SAndroid Build Coastguard Workerverbose_msg 764*b40554a2SAndroid Build Coastguard Worker 765*b40554a2SAndroid Build Coastguard Workerneed_cmd mkdir 766*b40554a2SAndroid Build Coastguard Workerneed_cmd printf 767*b40554a2SAndroid Build Coastguard Workerneed_cmd cut 768*b40554a2SAndroid Build Coastguard Workerneed_cmd grep 769*b40554a2SAndroid Build Coastguard Workerneed_cmd uname 770*b40554a2SAndroid Build Coastguard Workerneed_cmd tr 771*b40554a2SAndroid Build Coastguard Workerneed_cmd sed 772*b40554a2SAndroid Build Coastguard Workerneed_cmd chmod 773*b40554a2SAndroid Build Coastguard Workerneed_cmd env 774*b40554a2SAndroid Build Coastguard Workerneed_cmd pwd 775*b40554a2SAndroid Build Coastguard Worker 776*b40554a2SAndroid Build Coastguard WorkerCFG_ARGS="${@:-}" 777*b40554a2SAndroid Build Coastguard Worker 778*b40554a2SAndroid Build Coastguard WorkerHELP=0 779*b40554a2SAndroid Build Coastguard Workerif [ "${1-}" = "--help" ] 780*b40554a2SAndroid Build Coastguard Workerthen 781*b40554a2SAndroid Build Coastguard Worker HELP=1 782*b40554a2SAndroid Build Coastguard Worker shift 783*b40554a2SAndroid Build Coastguard Worker echo 784*b40554a2SAndroid Build Coastguard Worker echo "Usage: $0 [options]" 785*b40554a2SAndroid Build Coastguard Worker echo 786*b40554a2SAndroid Build Coastguard Worker echo "Options:" 787*b40554a2SAndroid Build Coastguard Worker echo 788*b40554a2SAndroid Build Coastguard Workerelse 789*b40554a2SAndroid Build Coastguard Worker verbose_step_msg "processing arguments" 790*b40554a2SAndroid Build Coastguard Workerfi 791*b40554a2SAndroid Build Coastguard Worker 792*b40554a2SAndroid Build Coastguard WorkerOPTIONS="" 793*b40554a2SAndroid Build Coastguard WorkerBOOL_OPTIONS="" 794*b40554a2SAndroid Build Coastguard WorkerVAL_OPTIONS="" 795*b40554a2SAndroid Build Coastguard Worker 796*b40554a2SAndroid Build Coastguard Workerflag uninstall "only uninstall from the installation prefix" 797*b40554a2SAndroid Build Coastguard Workervalopt destdir "" "set installation root" 798*b40554a2SAndroid Build Coastguard Workervalopt prefix "/usr/local" "set installation prefix" 799*b40554a2SAndroid Build Coastguard Worker 800*b40554a2SAndroid Build Coastguard Worker# Avoid prepending an extra / to the prefix path if there's no destdir 801*b40554a2SAndroid Build Coastguard Worker# NB: CFG vars here are undefined when passing --help 802*b40554a2SAndroid Build Coastguard Workerif [ -z "${CFG_DESTDIR-}" ]; then 803*b40554a2SAndroid Build Coastguard Worker CFG_DESTDIR_PREFIX="${CFG_PREFIX-}" 804*b40554a2SAndroid Build Coastguard Workerelse 805*b40554a2SAndroid Build Coastguard Worker CFG_DESTDIR_PREFIX="$CFG_DESTDIR/$CFG_PREFIX" 806*b40554a2SAndroid Build Coastguard Workerfi 807*b40554a2SAndroid Build Coastguard Worker 808*b40554a2SAndroid Build Coastguard Worker# NB This isn't quite the same definition as in `configure`. 809*b40554a2SAndroid Build Coastguard Worker# just using 'lib' instead of configure's CFG_LIBDIR_RELATIVE 810*b40554a2SAndroid Build Coastguard Workervalopt without "" "comma-separated list of components to not install" 811*b40554a2SAndroid Build Coastguard Workervalopt components "" "comma-separated list of components to install" 812*b40554a2SAndroid Build Coastguard Workerflag list-components "list available components" 813*b40554a2SAndroid Build Coastguard Workervalopt sysconfdir "$CFG_DESTDIR_PREFIX/etc" "install system configuration files" 814*b40554a2SAndroid Build Coastguard Workervalopt bindir "$CFG_DESTDIR_PREFIX/bin" "install binaries" 815*b40554a2SAndroid Build Coastguard Workervalopt libdir "$CFG_DESTDIR_PREFIX/lib" "install libraries" 816*b40554a2SAndroid Build Coastguard Workervalopt datadir "$CFG_DESTDIR_PREFIX/share" "install data" 817*b40554a2SAndroid Build Coastguard Worker# NB We repeat datadir default value because we don't set CFG_DATADIR in --help 818*b40554a2SAndroid Build Coastguard Workervalopt mandir "${CFG_DATADIR-"$CFG_DESTDIR_PREFIX/share"}/man" "install man pages in PATH" 819*b40554a2SAndroid Build Coastguard Worker# NB See the docdir handling in install_components for an explanation of this 820*b40554a2SAndroid Build Coastguard Worker# weird <default> string 821*b40554a2SAndroid Build Coastguard Workervalopt docdir "\<default\>" "install documentation in PATH" 822*b40554a2SAndroid Build Coastguard Workeropt ldconfig 1 "run ldconfig after installation (Linux only)" 823*b40554a2SAndroid Build Coastguard Workeropt verify 1 "obsolete" 824*b40554a2SAndroid Build Coastguard Workerflag verbose "run with verbose output" 825*b40554a2SAndroid Build Coastguard Worker 826*b40554a2SAndroid Build Coastguard Workerif [ $HELP -eq 1 ] 827*b40554a2SAndroid Build Coastguard Workerthen 828*b40554a2SAndroid Build Coastguard Worker echo 829*b40554a2SAndroid Build Coastguard Worker exit 0 830*b40554a2SAndroid Build Coastguard Workerfi 831*b40554a2SAndroid Build Coastguard Worker 832*b40554a2SAndroid Build Coastguard Workerverbose_step_msg "validating arguments" 833*b40554a2SAndroid Build Coastguard Workervalidate_opt 834*b40554a2SAndroid Build Coastguard Worker 835*b40554a2SAndroid Build Coastguard Worker# Template configuration. 836*b40554a2SAndroid Build Coastguard Worker# These names surrounded by '%%` are replaced by sed when generating install.sh 837*b40554a2SAndroid Build Coastguard Worker# FIXME: Might want to consider loading this from a file and not generating install.sh 838*b40554a2SAndroid Build Coastguard Worker 839*b40554a2SAndroid Build Coastguard Worker# Rust or Cargo 840*b40554a2SAndroid Build Coastguard WorkerTEMPLATE_PRODUCT_NAME='Rust' 841*b40554a2SAndroid Build Coastguard Worker# rustlib or cargo 842*b40554a2SAndroid Build Coastguard WorkerTEMPLATE_REL_MANIFEST_DIR=rustlib 843*b40554a2SAndroid Build Coastguard Worker# 'Rust is ready to roll.' or 'Cargo is cool to cruise.' 844*b40554a2SAndroid Build Coastguard WorkerTEMPLATE_SUCCESS_MESSAGE='clippy installed.' 845*b40554a2SAndroid Build Coastguard Worker# Locations to look for directories containing legacy, pre-versioned manifests 846*b40554a2SAndroid Build Coastguard WorkerTEMPLATE_LEGACY_MANIFEST_DIRS='rustlib,cargo' 847*b40554a2SAndroid Build Coastguard Worker# The installer version 848*b40554a2SAndroid Build Coastguard WorkerTEMPLATE_RUST_INSTALLER_VERSION='3' 849*b40554a2SAndroid Build Coastguard Worker 850*b40554a2SAndroid Build Coastguard Worker# OK, let's get installing ... 851*b40554a2SAndroid Build Coastguard Worker 852*b40554a2SAndroid Build Coastguard Worker# This is where we are installing from 853*b40554a2SAndroid Build Coastguard Workersrc_dir="$(abs_path $(dirname "$0"))" 854*b40554a2SAndroid Build Coastguard Worker 855*b40554a2SAndroid Build Coastguard Worker# The name of the script 856*b40554a2SAndroid Build Coastguard Workersrc_basename="$(basename "$0")" 857*b40554a2SAndroid Build Coastguard Worker 858*b40554a2SAndroid Build Coastguard Worker# If we've been run as 'uninstall.sh' (from the existing installation) 859*b40554a2SAndroid Build Coastguard Worker# then we're doing a full uninstall, as opposed to the --uninstall flag 860*b40554a2SAndroid Build Coastguard Worker# which just means 'uninstall my components'. 861*b40554a2SAndroid Build Coastguard Workerif [ "$src_basename" = "uninstall.sh" ]; then 862*b40554a2SAndroid Build Coastguard Worker if [ "${*:-}" != "" ]; then 863*b40554a2SAndroid Build Coastguard Worker # Currently don't know what to do with arguments in this mode 864*b40554a2SAndroid Build Coastguard Worker err "uninstall.sh does not take any arguments" 865*b40554a2SAndroid Build Coastguard Worker fi 866*b40554a2SAndroid Build Coastguard Worker CFG_UNINSTALL=1 867*b40554a2SAndroid Build Coastguard Worker CFG_DESTDIR_PREFIX="$(abs_path "$src_dir/../../")" 868*b40554a2SAndroid Build Coastguard Worker CFG_LIBDIR="$(abs_path "$src_dir/../")" 869*b40554a2SAndroid Build Coastguard Workerfi 870*b40554a2SAndroid Build Coastguard Worker 871*b40554a2SAndroid Build Coastguard Worker# This is where we are installing to 872*b40554a2SAndroid Build Coastguard Workerdest_prefix="$CFG_DESTDIR_PREFIX" 873*b40554a2SAndroid Build Coastguard Worker 874*b40554a2SAndroid Build Coastguard Worker# Open the components file to get the list of components to install. 875*b40554a2SAndroid Build Coastguard Worker# NB: During install this components file is read from the installer's 876*b40554a2SAndroid Build Coastguard Worker# source dir, during a full uninstall it's read from the manifest dir, 877*b40554a2SAndroid Build Coastguard Worker# and thus contains all installed components. 878*b40554a2SAndroid Build Coastguard Workercomponents=`cat "$src_dir/components"` 879*b40554a2SAndroid Build Coastguard Worker 880*b40554a2SAndroid Build Coastguard Worker# Sanity check: do we have components? 881*b40554a2SAndroid Build Coastguard Workerif [ ! -n "$components" ]; then 882*b40554a2SAndroid Build Coastguard Worker err "unable to find installation components" 883*b40554a2SAndroid Build Coastguard Workerfi 884*b40554a2SAndroid Build Coastguard Worker 885*b40554a2SAndroid Build Coastguard Worker# If the user asked for a component list, do that and exit 886*b40554a2SAndroid Build Coastguard Workerif [ -n "${CFG_LIST_COMPONENTS-}" ]; then 887*b40554a2SAndroid Build Coastguard Worker echo 888*b40554a2SAndroid Build Coastguard Worker echo "# Available components" 889*b40554a2SAndroid Build Coastguard Worker echo 890*b40554a2SAndroid Build Coastguard Worker for component in $components; do 891*b40554a2SAndroid Build Coastguard Worker echo "* $component" 892*b40554a2SAndroid Build Coastguard Worker done 893*b40554a2SAndroid Build Coastguard Worker echo 894*b40554a2SAndroid Build Coastguard Worker exit 0 895*b40554a2SAndroid Build Coastguard Workerfi 896*b40554a2SAndroid Build Coastguard Worker 897*b40554a2SAndroid Build Coastguard Worker# If the user specified which components to install/uninstall, 898*b40554a2SAndroid Build Coastguard Worker# then validate that they exist and select them for installation 899*b40554a2SAndroid Build Coastguard Workerif [ -n "$CFG_COMPONENTS" ]; then 900*b40554a2SAndroid Build Coastguard Worker # Remove commas 901*b40554a2SAndroid Build Coastguard Worker user_components="$(echo "$CFG_COMPONENTS" | sed "s/,/ /g")" 902*b40554a2SAndroid Build Coastguard Worker for user_component in $user_components; do 903*b40554a2SAndroid Build Coastguard Worker found=false 904*b40554a2SAndroid Build Coastguard Worker for my_component in $components; do 905*b40554a2SAndroid Build Coastguard Worker if [ "$user_component" = "$my_component" ]; then 906*b40554a2SAndroid Build Coastguard Worker found=true 907*b40554a2SAndroid Build Coastguard Worker fi 908*b40554a2SAndroid Build Coastguard Worker done 909*b40554a2SAndroid Build Coastguard Worker if [ "$found" = false ]; then 910*b40554a2SAndroid Build Coastguard Worker err "unknown component: $user_component" 911*b40554a2SAndroid Build Coastguard Worker fi 912*b40554a2SAndroid Build Coastguard Worker done 913*b40554a2SAndroid Build Coastguard Worker components="$user_components" 914*b40554a2SAndroid Build Coastguard Workerfi 915*b40554a2SAndroid Build Coastguard Worker 916*b40554a2SAndroid Build Coastguard Workerif [ -n "$CFG_WITHOUT" ]; then 917*b40554a2SAndroid Build Coastguard Worker without_components="$(echo "$CFG_WITHOUT" | sed "s/,/ /g")" 918*b40554a2SAndroid Build Coastguard Worker 919*b40554a2SAndroid Build Coastguard Worker # This does **not** check that all components in without_components are 920*b40554a2SAndroid Build Coastguard Worker # actually present in the list of available components. 921*b40554a2SAndroid Build Coastguard Worker # 922*b40554a2SAndroid Build Coastguard Worker # Currently that's considered good as it makes it easier to be compatible 923*b40554a2SAndroid Build Coastguard Worker # with multiple Rust versions (which may change the exact list of 924*b40554a2SAndroid Build Coastguard Worker # components) when writing install scripts. 925*b40554a2SAndroid Build Coastguard Worker new_comp="" 926*b40554a2SAndroid Build Coastguard Worker for component in $components; do 927*b40554a2SAndroid Build Coastguard Worker found=false 928*b40554a2SAndroid Build Coastguard Worker for my_component in $without_components; do 929*b40554a2SAndroid Build Coastguard Worker if [ "$component" = "$my_component" ]; then 930*b40554a2SAndroid Build Coastguard Worker found=true 931*b40554a2SAndroid Build Coastguard Worker fi 932*b40554a2SAndroid Build Coastguard Worker done 933*b40554a2SAndroid Build Coastguard Worker if [ "$found" = false ]; then 934*b40554a2SAndroid Build Coastguard Worker # If we didn't find the component in without, then add it to new list. 935*b40554a2SAndroid Build Coastguard Worker new_comp="$new_comp $component" 936*b40554a2SAndroid Build Coastguard Worker fi 937*b40554a2SAndroid Build Coastguard Worker done 938*b40554a2SAndroid Build Coastguard Worker components="$new_comp" 939*b40554a2SAndroid Build Coastguard Workerfi 940*b40554a2SAndroid Build Coastguard Worker 941*b40554a2SAndroid Build Coastguard Workerif [ -z "$components" ]; then 942*b40554a2SAndroid Build Coastguard Worker if [ -z "${CFG_UNINSTALL-}" ]; then 943*b40554a2SAndroid Build Coastguard Worker err "no components selected for installation" 944*b40554a2SAndroid Build Coastguard Worker else 945*b40554a2SAndroid Build Coastguard Worker err "no components selected for uninstallation" 946*b40554a2SAndroid Build Coastguard Worker fi 947*b40554a2SAndroid Build Coastguard Workerfi 948*b40554a2SAndroid Build Coastguard Worker 949*b40554a2SAndroid Build Coastguard Workerdo_preflight_sanity_checks "$src_dir" "$dest_prefix" 950*b40554a2SAndroid Build Coastguard Worker 951*b40554a2SAndroid Build Coastguard Worker# Using an absolute path to libdir in a few places so that the status 952*b40554a2SAndroid Build Coastguard Worker# messages are consistently using absolute paths. 953*b40554a2SAndroid Build Coastguard Workerabsolutify "$CFG_LIBDIR" 954*b40554a2SAndroid Build Coastguard Workerabs_libdir="$RETVAL" 955*b40554a2SAndroid Build Coastguard Workerassert_nz "$abs_libdir" "abs_libdir" 956*b40554a2SAndroid Build Coastguard Worker 957*b40554a2SAndroid Build Coastguard Worker# Create the manifest directory, where we will put our logs 958*b40554a2SAndroid Build Coastguard Workermake_dir_recursive "$abs_libdir/$TEMPLATE_REL_MANIFEST_DIR" 959*b40554a2SAndroid Build Coastguard Workerneed_ok "failed to create $TEMPLATE_REL_MANIFEST_DIR" 960*b40554a2SAndroid Build Coastguard Worker 961*b40554a2SAndroid Build Coastguard Worker# Log messages and commands 962*b40554a2SAndroid Build Coastguard Workerinit_logging "$abs_libdir" 963*b40554a2SAndroid Build Coastguard Worker 964*b40554a2SAndroid Build Coastguard Worker# First do any uninstallation, including from legacy manifests. This 965*b40554a2SAndroid Build Coastguard Worker# will also upgrade the metadata of existing installs. 966*b40554a2SAndroid Build Coastguard Workeruninstall_components "$abs_libdir" "$dest_prefix" "$components" 967*b40554a2SAndroid Build Coastguard Worker 968*b40554a2SAndroid Build Coastguard Worker# If we're only uninstalling then exit 969*b40554a2SAndroid Build Coastguard Workerif [ -n "${CFG_UNINSTALL-}" ] 970*b40554a2SAndroid Build Coastguard Workerthen 971*b40554a2SAndroid Build Coastguard Worker echo 972*b40554a2SAndroid Build Coastguard Worker echo " $TEMPLATE_PRODUCT_NAME is uninstalled." 973*b40554a2SAndroid Build Coastguard Worker echo 974*b40554a2SAndroid Build Coastguard Worker exit 0 975*b40554a2SAndroid Build Coastguard Workerfi 976*b40554a2SAndroid Build Coastguard Worker 977*b40554a2SAndroid Build Coastguard Worker# Create the manifest directory again! uninstall_legacy 978*b40554a2SAndroid Build Coastguard Worker# may have deleted it. 979*b40554a2SAndroid Build Coastguard Workermake_dir_recursive "$abs_libdir/$TEMPLATE_REL_MANIFEST_DIR" 980*b40554a2SAndroid Build Coastguard Workerneed_ok "failed to create $TEMPLATE_REL_MANIFEST_DIR" 981*b40554a2SAndroid Build Coastguard Worker 982*b40554a2SAndroid Build Coastguard Worker# Drop the version number into the manifest dir 983*b40554a2SAndroid Build Coastguard Workerwrite_to_file "$TEMPLATE_RUST_INSTALLER_VERSION" \ 984*b40554a2SAndroid Build Coastguard Worker"$abs_libdir/$TEMPLATE_REL_MANIFEST_DIR/rust-installer-version" 985*b40554a2SAndroid Build Coastguard Worker 986*b40554a2SAndroid Build Coastguard Workercritical_need_ok "failed to write installer version" 987*b40554a2SAndroid Build Coastguard Worker 988*b40554a2SAndroid Build Coastguard Worker# Install the uninstaller 989*b40554a2SAndroid Build Coastguard Workerinstall_uninstaller "$src_dir" "$src_basename" "$abs_libdir" 990*b40554a2SAndroid Build Coastguard Worker 991*b40554a2SAndroid Build Coastguard Worker# Install each component 992*b40554a2SAndroid Build Coastguard Workerinstall_components "$src_dir" "$abs_libdir" "$dest_prefix" "$components" 993*b40554a2SAndroid Build Coastguard Worker 994*b40554a2SAndroid Build Coastguard Worker# Make dynamic libraries available to the linker 995*b40554a2SAndroid Build Coastguard Workermaybe_configure_ld "$abs_libdir" 996*b40554a2SAndroid Build Coastguard Worker 997*b40554a2SAndroid Build Coastguard Workerecho 998*b40554a2SAndroid Build Coastguard Workerecho " $TEMPLATE_SUCCESS_MESSAGE" 999*b40554a2SAndroid Build Coastguard Workerecho 1000