-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.sh
180 lines (137 loc) · 5.49 KB
/
installer.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#! /usr/bin/env sh
installMantine() {
if grep -e "@mantine/core" package.json > /dev/null 2>&1; then
return
fi
echo -e "\x1b[1m[ ℹ️ ] Matador needs the \x1b[36m@mantine/core\x1b[39m package, the script is gonna install it\x1b[0m"
local remixRootDir=$1
local currentDir=$(pwd)
cd $remixRootDir
local hasMantineBeenInstalled=0
if [[ -f "package.json" ]]; then
if ! npm --version > /dev/null 2>&1; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] I can't run \x1b[36mnpm\x1b[39m\x1b[0m"
exit 1
else
echo -e "\x1b[1m[ ℹ️ ] installing \x1b[36m@mantine/core\x1b[39m package with npm\x1b[0m"
npm install @mantine/core
if [[ $? -ne 0 ]]; then
echo -e -n "\x1b[1m[ ❌ ] something went wrong while installing the package, aborting\x1b[0m "
exit 1
fi
hasMantineBeenInstalled=1
fi
if [[ $hasMantineBeenInstalled -eq 0 ]]; then
if ! yarn --version > /dev/null 2>&1; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] I can't run \x1b[36myarn\x1b[39m\x1b[0m"
exit 1
else
echo -e "\x1b[1m[ ℹ️ ] installing \x1b[36m@mantine/core\x1b[39m package with yarn\x1b[0m"
yarn add @mantine/core
if [[ $? -ne 0 ]]; then
echo -e -n "\x1b[1m[ ❌ ] something went wrong while installing the package, aborting\x1b[0m "
exit 1
fi
hasMantineBeenInstalled=1
fi
fi
if [[ $hasMantineBeenInstalled -eq 0 ]]; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] I can't install \x1b[36mMantine\x1b[39m package\x1b[0m"
echo -e -n "\x1b[1m[ ❌ ] aborting \x1b[36mMatador\x1b[39m installation for the above reasons\x1b[0m "
exit 1
fi
else
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] I can't found \x1b[36mpackage.json\x1b[39m file\x1b[0m"
echo -e -n "\x1b[1m[ ❌ ] aborting \x1b[36mMatador\x1b[39m installation for the above reasons\x1b[0m "
exit 1
fi
cd $currentDir
echo
echo -e "\x1b[1m[ ℹ️ ] I successfully installed the \x1b[36m@mantine/core\x1b[39m package\x1b[0m"
}
checkRemixDir() {
local remixRootDir=$(realpath $1)
if ! [[ -f "${remixRootDir}/remix.config.js" ]]; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] the \x1b[36m$remixRootDir\x1b[39m directory does not look like a Remix project, aborting\x1b[0k"
echo -e -n "\x1b[1m[ ❌ ] aborting \x1b[36mMatador\x1b[39m installation for the above reasons\x1b[0m "
exit 1
fi
echo $remixRootDir
}
checkAppDir() {
local isError=0
local remixAppDir=$1
if [[ ! -d "$remixAppDir" ]]; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] directory \x1b[36m$remixAppDir\x1b[39m not found\x1b[0m"
isError=1
fi
if [[ -f "$remixAppDir/routes/matador.tsx" ]]; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] file \x1b[36m$remixAppDir/routes/matador.tsx\x1b[39m already exists\x1b[0m"
isError=1
fi
if [[ -d "$remixAppDir/routes/matador" ]]; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] directory \x1b[36m$remixAppDir/routes/matador\x1b[39m already exists\x1b[0m"
isError=1
fi
if [[ -d "$remixAppDir/lib/matador" ]]; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] directory \x1b[36m$remixAppDir/lib/matador\x1b[39m already exists\x1b[0m"
isError=1
fi
if [[ isError -eq 1 ]]; then
echo -e -n "\x1b[1m[ ❌ ] aborting \x1b[36mMatador\x1b[39m installation for the above reasons\x1b[0m "
exit 1
fi
}
checkEnvFile() {
local remixRootDir=$1
# if there is no .env file, create one and add env variables
if ! [[ -f "${remixRootDir}/.env" ]]; then
echo -e "\x1b[1m[ ℹ️ ] Creating .env file with REDIS_URL variable\x1b[0m"
echo 'REDIS_URL=""' >> "${remixRootDir}/.env"
return
fi
# if there is a .env file, check if it has REDIS_URL env variables
if ! grep -q -E "REDIS_URL=*" "${remixRootDir}/.env"; then
echo -e "\x1b[1m[ ℹ️ ] Adding REDIS_URL variable to .env file\x1b[0m"
echo 'REDIS_URL=""' >> "${remixRootDir}/.env"
fi
}
main() {
if [[ $# -gt 2 ]]; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] invalid arguments, aborting\x1b[0m"
exit 1
fi
local remixRootDir=$(checkRemixDir $1)
local remixAppDir=$(realpath "$1/$([[ $2 != "" ]] && echo $2 || echo "app")")
checkAppDir $remixAppDir
installMantine $remixRootDir
local tempDir="/tmp/matador-$(uuidgen -t)"
mkdir $tempDir
echo -e "\x1b[1m[ ℹ️ ] Downloading \x1b[36mMatador\x1b[39m from repo\x1b[0m"
wget -q https://github.com/nullndr/Matador/archive/refs/heads/main.zip -O "$tempDir/main.zip" 2>&1 > /dev/null
if [[ $? -ne 0 ]]; then
echo -e "\x1b[1m[ \x1b[31mError\x1b[39m ] wget failed to download the repo\x1b[0m"
[[ -f main.zip ]] && rm "$tempDir/main.zip" && rm -rf $tempDir
exit 1
fi
echo -e "\x1b[1m[ ℹ️ ] Extracting \x1b[36mMatador\x1b[39m from repo\x1b[0m"
local libDir="$remixAppDir/lib"
if ! [[ -d $libDir ]]; then
mkdir $libDir
fi
unzip -q "$tempDir/main.zip" "Matador-main/*" -d "$tempDir"
cp -r "$tempDir/Matador-main/app/lib/matador" $libDir
cp -r "$tempDir/Matador-main/app/routes/matador" "$remixAppDir/routes"
cp "$tempDir/Matador-main/app/routes/matador.tsx" "$remixAppDir/routes"
if ! [[ -d "$remixRootDir/public/assets" ]]; then
mkdir "$remixRootDir/public/assets"
fi
cp "$tempDir/Matador-main/public/assets/matador.png" "$remixRootDir/public/assets"
rm -rf "$tempDir/Matador-main"
rm "$tempDir/main.zip"
rm -rf $tempDir
checkEnvFile $remixRootDir
echo -e "\x1b[1m[ ✅ ] All done! Enjoy \x1b[36mMatador\x1b[39m!\x1b[0m"
}
echo
main $@