-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall
executable file
·138 lines (118 loc) · 3.5 KB
/
install
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
#!/bin/bash
echo ""
echo " **************************"
echo " *** templify installer ***"
echo " **************************"
echo ""
yesFlag=false
version="latest"
homePath=$HOME/.templify
macOS=false
# parse the flags
while getopts v:p:y flag
do
case "${flag}" in
v) version=${OPTARG};;
p) homePath=${OPTARG};;
y) yesFlag=true;;
esac
done
if [ "$(uname)" == "Darwin" ]; then
macOS=true
fi
if [[ $version == v* ]]; then
version=${version:1}
fi
if [[ $version == 0.* ]]; then
echo "Error: Version $version is not supported"
exit 1
fi
if [ "$macOS" = true ]; then
echo "Installing templify for macOS..."
else
echo "Installing templify for Linux..."
fi
echo "This will install a binary to $homePath and add it to your PATH."
if [ "$yesFlag" = false ]; then
read -p "Are you sure you want to continue? (y/N) " response < /dev/tty
if [[ ! "$response" =~ ^([yY][eE][sS]|[yY])+$ ]]; then
# echo in line with the prompt
echo "No"
echo "Aborting."
exit 1
fi
fi
echo "Yes"
# print to the console in same line
echo "Installing..."
# get version
if [ "$version" = "latest" ]; then
echo "Looking for the latest release..."
## Get meta data from the latest release
json=$(curl -s https://api.github.com/repos/cophilot/templify/releases/latest)
# get the tag name of the latest release
if [ "$macOS" = true ]; then
version=$(echo $json | grep -o '"tag_name": ".*"' | cut -d '"' -f4)
else
version=$(echo $json | grep -Po '"tag_name": "\K.*?(?=")')
fi
echo "Found version: $version"
else
echo "Looking for the release with the tag $version..."
#check if the tag exists
json=$(curl -s https://api.github.com/repos/cophilot/templify/releases/tags/$version)
if [ "$macOS" = true ]; then
msg=$(echo $json | grep -o '"message": ".*"' | cut -d '"' -f4)
else
msg=$(echo $json | grep -Po '"message": "\K.*?(?=")')
fi
if [ "$msg" = "Not Found" ]; then
echo "Error: No release found with the tag $version"
exit 1
fi
fi
url=https://github.com/cophilot/templify/releases/download/$version/tpy
if [ "$macOS" = true ]; then
url="$url-macos"
else
url="$url-linux"
fi
echo "Creating installation directory $homePath..."
mkdir -p $homePath/bin
# remove any existing binary
echo "Removing existing binary..."
rm -f $homePath/bin/tpy
# download the binary and save as an executable
echo "Downloading binary from $url ..."
curl -L $url -o $homePath/bin/tpy
# check if the download was successful
if [ $? -ne 0 ]; then
echo "Download failed! Exiting."
exit 1
fi
echo "Download successful!"
chmod +x $homePath/bin/tpy
# add the binary to the PATH
echo "Adding $homePath/bin to PATH..."
export PATH=$PATH:$homePath/bin
if [ -f $HOME/.bashrc ]; then
if ! grep -q "export PATH=\$PATH:$homePath/bin" $HOME/.bashrc; then
echo "" >> $HOME/.bashrc
echo "export PATH=\$PATH:$homePath/bin" >> $HOME/.bashrc
fi
fi
if [ -f $HOME/.zshrc ]; then
if ! grep -q "export PATH=\$PATH:$homePath/bin" $HOME/.zshrc; then
echo "" >> $HOME/.zshrc
echo "export PATH=\$PATH:$homePath/bin" >> $HOME/.zshrc
fi
fi
if [ -f $HOME/.bash_profile ]; then
if ! grep -q "export PATH=\$PATH:$homePath/bin" $HOME/.bash_profile; then
echo "" >> $HOME/.bash_profile
echo "export PATH=\$PATH:$homePath/bin" >> $HOME/.bash_profile
fi
fi
echo "templify successfully installed to $homePath/bin"
echo "You may need to restart your shell for the changes to take effect"
echo "Run 'tpy help' to get started or visit https://templify.philipp-bonin.com for more information"