-
Notifications
You must be signed in to change notification settings - Fork 6
/
install.sh
executable file
·69 lines (58 loc) · 1.73 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
#!/usr/bin/env bash
version="latest"
usage() {
echo "usage: $0 [arguments]"
echo ""
echo "Arguments:"
echo " -v or --version Specify faker's version"
echo " -h or --help Show help"
}
while [ "$1" != "" ]; do
case $1 in
-v | --version ) shift
version=$1
;;
-h | --help ) usage
exit 0
;;
* ) usage
exit 1
esac
shift
done
# Set default latest version
if [[ "$version" == "latest" ]]; then
version=$(curl --silent "https://api.github.com/repos/dotronglong/faker/releases/latest" |
grep '"tag_name":' |
sed -E 's/v//g' |
sed -E 's/.*"([^"]+)".*/\1/')
fi
DIR_FAKER=.faker
DIR_ROOT=$HOME/$DIR_FAKER
DIR_INSTALL=$DIR_ROOT/$version
FAKER=$DIR_INSTALL/faker.jar
FAKER_BIN=$DIR_ROOT/fakerio
# Create folder if missing
if [[ ! -d "$DIR_INSTALL" ]]; then
mkdir -p "$DIR_INSTALL"
fi
# Download if necessary
if [[ ! -f "$FAKER" ]]; then
echo "Downloading faker $version ..."
curl -o "${FAKER}" -#SLO "https://github.com/dotronglong/faker/releases/download/v${version}/faker.jar"
fi
# Update alias
rm -rf "$DIR_ROOT/faker.jar"
ln -s "$FAKER" "$DIR_ROOT/faker.jar"
if [[ ! -f "${FAKER_BIN}" ]]; then
curl -o "${FAKER_BIN}" -sSLO https://raw.githubusercontent.com/dotronglong/faker/master/faker.sh
chmod +x "${FAKER_BIN}"
fi
# Check for environment variable
check=$(echo $PATH | grep "${DIR_FAKER}")
if [[ -z "${check}" ]]; then
echo "Please add \$HOME/${DIR_FAKER} to PATH environment variable"
echo "export PATH=\$PATH:\$HOME/${DIR_FAKER}"
fi
# Success
echo "Use version: $version"