-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
154 lines (154 loc) · 3.46 KB
/
install.sh
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env bash
PACKAGE_MANAGER=yarn
NPX=npx
OS="`uname`"
function main() {
get_os
for i in "$@"; do
case $i in
-h|--help)
print_usage
exit 0
;;
-p=*|--package_manager=*)
PACKAGE_MANAGER="${i#*=}"
;;
*)
echo "invalid option"
print_usage
exit 1
;;
esac
done
if [ "$PACKAGE_MANAGER" == "yarn" ]; then
echo "installing using yarn ("$OS") ..."
elif [ "$PACKAGE_MANAGER" == "npm" ]; then
echo "installing using npm"
else
echo "invalid package manager"
exit 1
fi
PACKAGE_MANAGER_PATH=$(which $PACKAGE_MANAGER 2>/dev/null)
if [ -z "$PACKAGE_MANAGER_PATH" ]; then
echo "$PACKAGE_MANAGER not found"
exit 1
fi
rm -rf ./javascriptsource/didcomm_survey/node_modules
if [ "$PACKAGE_MANAGER" == "yarn" ]; then
rm -rf ./javascriptsource/didcomm_survey/yarn.lock
elif [ "$PACKAGE_MANAGER" == "npm" ]; then
rm -rf ./javascriptsource/didcomm_survey/package-lock.json
fi
rm -rf ./javascriptsource/agent_sdk/node_modules
if [ "$PACKAGE_MANAGER" == "yarn" ]; then
rm -rf ./javascriptsource/agent_sdk/yarn.lock
elif [ "$PACKAGE_MANAGER" == "npm" ]; then
rm -rf ./javascriptsource/agent_sdk/package-lock.json
fi
rm -rf ./javascriptsource/keymanagement/node_modules
if [ "$PACKAGE_MANAGER" == "yarn" ]; then
rm -rf ./javascriptsource/keymanagement/yarn.lock
elif [ "$PACKAGE_MANAGER" == "npm" ]; then
rm -rf ./javascriptsource/keymanagement/package-lock.json
fi
cd ./javascriptsource/didcomm_survey/
if [ "$PACKAGE_MANAGER" == "yarn" ]; then
retry 100 yarn install
elif [ "$PACKAGE_MANAGER" == "npm" ]; then
retry 100 npm install --legacy-peer-deps
fi
find ./node_modules -type d -name __tests__ -prune -exec rm -rf {} \;
cd ../agent_sdk
if [ "$PACKAGE_MANAGER" == "yarn" ]; then
retry 100 yarn install
elif [ "$PACKAGE_MANAGER" == "npm" ]; then
retry 100 npm install --legacy-peer-deps --save-dev
fi
if [ -z "$NPX" ]; then
echo "$NPX not found"
echo "not patching"
exit 1
else
echo "patching"
retry 100 npx patch-package
fi
find ./node_modules -type d -name __tests__ -prune -exec rm -rf {} \;
cd ../keymanagement
if [ "$PACKAGE_MANAGER" == "yarn" ]; then
retry 100 yarn install
elif [ "$PACKAGE_MANAGER" == "npm" ]; then
retry 100 npm install --legacy-peer-deps
fi
find ./node_modules -type d -name __tests__ -prune -exec rm -rf {} \;
exit 0
}
function print_usage() {
echo "Usage: $0 [-p|--package_manager|-h|--help]"
echo " -p=PACKAGE_MANAGER"
echo " install using PACKAGE_MANAGER"
echo " --package_manager=PACKAGE_MANAGER"
echo " install using PACKAGE_MANAGER"
echo " --h"
echo " prints help"
echo " --help"
echo " prints help"
echo " PACKAGE_MANAGER"
echo " yarn (default)"
echo " npm"
}
function get_os() {
case $OS in
'Linux')
if [[ $(grep -i Microsoft /proc/version) ]]; then
OS='WSL'
else
OS='Linux'
fi
;;
'FreeBSD')
OS='FreeBSD'
;;
'WindowsNT')
OS='Windows'
;;
'Darwin')
OS='Mac'
;;
'SunOS')
OS='Solaris'
;;
'AIX')
OS='AIX'
;;
'msys')
OS='MSYS'
;;
*)
OS='unknown'
case $OSTYPE in
'msys')
OS='MSYS'
;;
*)
OS='unknown'
;;
esac
;;
esac
}
retry() {
local -r -i max_attempts="$1"; shift
local -i attempt_num=1
until "$@"
do
if ((attempt_num==max_attempts))
then
echo "Attempt $attempt_num failed and there are no more attempts left!"
return 1
else
echo "Attempt $attempt_num failed! Trying again in $attempt_num seconds..."
sleep $((attempt_num++))
fi
done
}
main "$@"