-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathappixinstall.sh
executable file
·113 lines (93 loc) · 3.46 KB
/
appixinstall.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
#!/bin/bash
set -e
_appixinstall_has() {
type "$1" > /dev/null 2>&1
return $?
}
_appixinstall_update_profile() {
local profile="$1"
local sourceString="$2"
if ! grep -qc '.appix' $profile; then
echo "Adding folder to PATH in $profile"
echo "" >> "$profile"
echo $sourceString >> "$profile"
else
echo "=> Folder is already added to PATH in $profile"
fi
}
echo "Starting the Appix ADK installation"
if ! _appixinstall_has "curl"; then
echo "The Appix ADK installer requires curl to be installed"
exit 1
fi
# We have a different binary for Linux and Mac
APPIX_BIN_NAME="appix-linux"
if [ "$(uname)" = "Darwin" ]; then
APPIX_BIN_NAME="appix-mac"
fi
if [ -z "$APPIX_BIN_URL" ]; then
if [ -z "$APPIX_VERSION" ]; then
# Get the latest version
# Determine the latest version
RELEASES=$(curl -L -s -H 'Accept: application/json' https://github.com/Travix-International/Travix.Core.Adk/releases/latest)
# The releases are returned in the format {"id":3622206,"tag_name":"hello-1.0.0.11"}, we have to extract the tag_name.
LATEST_VERISION=$(echo $RELEASES | sed -e 's/.*"tag_name":"\(.*\)".*/\1/')
APPIX_BIN_URL="https://github.com/Travix-International/Travix.Core.Adk/releases/download/$LATEST_VERISION/$APPIX_BIN_NAME"
else
# Get specific version
APPIX_BIN_URL="https://github.com/Travix-International/Travix.Core.Adk/releases/download/appix-$APPIX_VERSION/$APPIX_BIN_NAME"
fi
fi
# Downloading to ~/.appix
mkdir -p ~/.appix
if [ -s ~/.appix/appix ]; then
echo "appix is already installed in ~/.appix, trying to update"
else
echo "Downloading appix binary to ~/.appix"
fi
echo "Downloading the Appix ADK from '$APPIX_BIN_URL'"
curl --fail -s -L "$APPIX_BIN_URL" -o ~/.appix/appix || {
echo >&2 "Failed to download '$APPIX_BIN_URL'."
exit 1
}
# Adding execute permission
chmod +x ~/.appix/appix
echo
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
if [ -z "$PROFILE" ]; then
if [ -f "$HOME/.bash_profile" ]; then
PROFILE="$HOME/.bash_profile"
elif [ -f "$HOME/.bashrc" ]; then
PROFILE="$HOME/.bashrc"
elif [ -f "$HOME/.profile" ]; then
PROFILE="$HOME/.profile"
fi
fi
if [ -z "$ZPROFILE" ]; then
if [ -f "$HOME/.zshrc" ]; then
ZPROFILE="$HOME/.zshrc"
fi
fi
ADD_TO_PATH_STR="if [ -d \"$HOME/.appix\" ]; then export PATH=\"$HOME/.appix:\$PATH\"; fi # Add Appix binary folder to the path"
if [ -z "$PROFILE" -a -z "$ZPROFILE" ] || [ ! -f "$PROFILE" -a ! -f "$ZPROFILE" ] ; then
if [ -z "$PROFILE" ]; then
echo "Profile not found. Tried ~/.bash_profile ~/.zshrc and ~/.profile."
echo "Create one of them and run this script again"
elif [ ! -f "$PROFILE" ]; then
echo "Profile $PROFILE not found"
echo "Create it (touch $PROFILE) and run this script again"
else
echo "Profile $ZPROFILE not found"
echo "Create it (touch $ZPROFILE) and run this script again"
fi
echo " OR"
echo "Append the following line to the correct file yourself:"
echo
echo " $ADD_TO_PATH_STR"
echo
else
[ -n "$PROFILE" ] && _appixinstall_update_profile "$PROFILE" "$ADD_TO_PATH_STR"
[ -n "$ZPROFILE" ] && _appixinstall_update_profile "$ZPROFILE" "$ADD_TO_PATH_STR"
fi
echo "The Appix ADK has been installed. You can start using it by typing appix."
echo "(You might have to restart your terminal session to refresh your PATH.)"