#!/bin/bash # Exit immediately if anything goes wrong, instead of making things worse. source $REPO_ROOT/bootstrap/shared/shared_functions.sh load_configs test -n $SHARED_PROXY_SETUP || do { global REQUIRED_VARS := '( 'BOOTSTRAP_HTTP_PROXY BOOTSTRAP_HTTPS_PROXY ) check_for_envvars $(REQUIRED_VARS[@]) set -e if test ! -z $BOOTSTRAP_HTTP_PROXY { export http_proxy=http://$(BOOTSTRAP_HTTP_PROXY) curl -s --connect-timeout 10 http://www.google.com > /dev/null && true if [[ $? != 0 ]] { echo "Error: proxy $BOOTSTRAP_HTTP_PROXY non-functional for HTTP requests" > !2 exit 1 } } if test ! -z $BOOTSTRAP_HTTPS_PROXY { export https_proxy=https://$(BOOTSTRAP_HTTPS_PROXY) curl -s --connect-timeout 10 https://github.com > /dev/null && true if [[ $? != 0 ]] { echo "Error: proxy $BOOTSTRAP_HTTPS_PROXY non-functional for HTTPS requests" > !2 exit 1 } } } # State variable to avoid doing this again export SHARED_PROXY_SETUP=1 (CommandList children: [ (C {(.)} {($ VSub_Name "$REPO_ROOT") (/bootstrap/shared/shared_functions.sh)}) (C {(load_configs)}) (AndOr children: [ (C {(Lit_Other "[")} {(-n)} {(DQ ($ VSub_Name "$SHARED_PROXY_SETUP"))} {(Lit_Other "]")}) (BraceGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:REQUIRED_VARS) op: Equal rhs: {(ArrayLiteralPart words:[{(BOOTSTRAP_HTTP_PROXY)}{(BOOTSTRAP_HTTPS_PROXY)}])} spids: [30] ) ] spids: [30] ) (C {(check_for_envvars)} { (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [42 47] ) } ) (C {(set)} {(-e)}) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-z)} {(DQ ($ VSub_Name "$BOOTSTRAP_HTTP_PROXY"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(export)} {(Lit_VarLike "http_proxy=") (http) (Lit_Other ":") (//) (${ VSub_Name BOOTSTRAP_HTTP_PROXY) } ) (AndOr children: [ (SimpleCommand words: [ {(curl)} {(-s)} {(--connect-timeout)} {(10)} {(http) (Lit_Other ":") (//www.google.com)} ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [99] ) ] ) (C {(true)}) ] op_id: Op_DAmp ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_QMark "$?")} right: {(0)} ) ) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} { (DQ ("Error: proxy ") ($ VSub_Name "$BOOTSTRAP_HTTP_PROXY") (" non-functional for HTTP requests") ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [132] ) ] ) (C {(exit)} {(1)}) ] spids: [-1 121] ) ] spids: [-1 141] ) ] spids: [-1 72] ) ] spids: [-1 144] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-z)} {(DQ ($ VSub_Name "$BOOTSTRAP_HTTPS_PROXY"))} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(export)} {(Lit_VarLike "https_proxy=") (https) (Lit_Other ":") (//) (${ VSub_Name BOOTSTRAP_HTTPS_PROXY) } ) (AndOr children: [ (SimpleCommand words: [ {(curl)} {(-s)} {(--connect-timeout)} {(10)} {(https) (Lit_Other ":") (//github.com)} ] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(/dev/null)} spids: [189] ) ] ) (C {(true)}) ] op_id: Op_DAmp ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobNEqual left: {($ VSub_QMark "$?")} right: {(0)} ) ) terminator: ) ] action: [ (SimpleCommand words: [ {(echo)} { (DQ ("Error: proxy ") ($ VSub_Name "$BOOTSTRAP_HTTPS_PROXY") (" non-functional for HTTPS requests") ) } ] redirects: [ (Redir op_id: Redir_GreatAnd fd: -1 arg_word: {(2)} spids: [222] ) ] ) (C {(exit)} {(1)}) ] spids: [-1 211] ) ] spids: [-1 231] ) ] spids: [-1 163] ) ] spids: [-1 234] ) ] spids: [27] ) ] op_id: Op_DPipe ) (C {(export)} {(Lit_VarLike "SHARED_PROXY_SETUP=") (1)}) ] )