-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathizon2.sh
More file actions
113 lines (104 loc) · 3.35 KB
/
Copy pathizon2.sh
File metadata and controls
113 lines (104 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
function __readDependency() {
local base_path="."
if [[ $4 != "" ]]; then
base_path=$4
fi
if [ -e $base_path/version.json ]; then
local dependency=$1
local url_var=$2
local tag_var=$3
local path=$(sed -n "/$dependency/p" $base_path/version.json | awk -F'"' '{print $4}')
local url=$(echo $path | awk -F"#" '{print $1}')
local tag=$(echo $path | awk -F"#" '{print $2}')
eval $url_var="$url"
eval $tag_var="$tag"
else
echo "Unable to find version.json file"
exit 1
fi
}
function __version() {
local base_path="."
if [ -n $1 ]; then
base_path=$1
fi
local version=""
if [ -e $base_path/VERSION ]; then
version=$(cat VERSION)
elif [ -e $base_path/version.json ]; then
version=$(grep version version.json | cut -f 2 -d: | cut -f 2 -d \")
else
echo "Unable to find VERSION/version.json file"
exit 1
fi
}
function getUsingCurl() {
if [ -z $1 ]; then
echo "Link not passed"
exit 1
fi
if [[ $1 = *"github.build.ge"* ]]; then
if [[ -n "$GITHUB_BUILD_TOKEN" ]]; then
SHORT_LINK=${1##*//}
URL="https://$GITHUB_BUILD_TOKEN@$SHORT_LINK"
echo "Downloading the file $1"
curl -s -O $URL
if [ $? -ne 0 ]; then
echo "Please check proxy env vars, e.g. HTTP_PROXY and HTTPS_PROXY"
exit 1
fi
else
echo "Please ensure env var GITHUB_BUILD_TOKEN for github.build.ge.com token is set"
exit 1
fi
else
echo "Downloading the file $1"
curl -s -O $1
fi
}
function getVersionFile() {
#if needed, get the version.json that resolves dependent repos from another github repo
if [ ! -f "$VERSION_JSON" ]; then
if [[ $currentDir == *"$REPO_NAME" ]]; then
if [[ ! -f manifest.yml ]]; then
echo "We noticed you are in a directory named $REPO_NAME but the usual contents (version.json) are not here, please rename the dir or do a git clone of the whole repo. If you rename the dir, the script will get the repo."
exit 1
fi
fi
echo $VERSION_JSON_URL
getUsingCurl $VERSION_JSON_URL
cat version.json
fi
}
function getLocalSetupFuncs() {
GITHUB_RAW=$1
GITHUB_ORG=$2
#get the predix-scripts url and branch from the version.json
__readDependency $PREDIX_SCRIPTS PREDIX_SCRIPTS_URL PREDIX_SCRIPTS_BRANCH
LOCAL_SETUP_FUNCS_URL="$GITHUB_RAW/$GITHUB_ORG/$PREDIX_SCRIPTS/$PREDIX_SCRIPTS_BRANCH/bash/scripts/local-setup-funcs.sh"
# Getting the proxy scripts
getProxyScripts $GITHUB_RAW $GITHUB_ORG
# Deleting any old file and downloading a new one
rm -rf local-setup-funcs.sh
getUsingCurl $LOCAL_SETUP_FUNCS_URL
source local-setup-funcs.sh
}
function getProxyScripts() {
GITHUB_RAW=$1
GITHUB_ORG=$2
#get the predix-scripts url and branch from the version.json
__readDependency $PREDIX_SCRIPTS PREDIX_SCRIPTS_URL PREDIX_SCRIPTS_BRANCH
VERIFY_PROXY_URL="$GITHUB_RAW/$GITHUB_ORG/$PREDIX_SCRIPTS/$PREDIX_SCRIPTS_BRANCH/bash/common/proxy/verify-proxy.sh"
TOGGLE_PROXY_URL="$GITHUB_RAW/$GITHUB_ORG/$PREDIX_SCRIPTS/$PREDIX_SCRIPTS_BRANCH/bash/common/proxy/toggle-proxy.sh"
# Deleting any old files and downloading new ones
rm -rf verify-proxy.sh
rm -rf toggle-proxy.sh
getUsingCurl $VERIFY_PROXY_URL
getUsingCurl $TOGGLE_PROXY_URL
echo
echo "Verifying proxy settings using verify-proxy.sh"
chmod 755 verify-proxy.sh
./verify-proxy.sh
chmod 755 toggle-proxy.sh
}