Skip to content

Commit 227f83f

Browse files
committed
feat: move occurances of appwrite in install scripts to params
1 parent f87d608 commit 227f83f

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

templates/cli/install.ps1.twig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ $version = $this->getParam('version', '');
1717
# You can use "View source" of this page to see the full script.
1818

1919
# {{ spec.title | caseUcfirst }} CLI location
20-
$APPWRITE_INSTALL_DIR = Join-Path -Path $env:LOCALAPPDATA -ChildPath "{{ spec.title | caseUcfirst }}"
20+
${{ spec.title | upper }}_INSTALL_DIR = Join-Path -Path $env:LOCALAPPDATA -ChildPath "{{ spec.title | caseUcfirst }}"
2121

2222
# {{ spec.title | caseUcfirst }} CLI Executable name
23-
$APPWRITE_EXECUTABLE_NAME = "{{ language.params.executableName }}.ps1"
23+
${{ spec.title | upper }}_EXECUTABLE_NAME = "{{ language.params.executableName }}.ps1"
2424

2525
# {{ spec.title | caseUcfirst }} executable file path
26-
$APPWRITE_EXECUTABLE_FILEPATH = Join-Path -Path $APPWRITE_INSTALL_DIR -ChildPath $APPWRITE_EXECUTABLE_NAME
26+
${{ spec.title | upper }}_EXECUTABLE_FILEPATH = Join-Path -Path ${{ spec.title | upper }}_INSTALL_DIR -ChildPath ${{ spec.title | upper }}_EXECUTABLE_NAME
2727

2828
# {{ spec.title | caseUcfirst }} CLI image name
29-
$APPWRITE_CLI_IMAGE_NAME = "{{ spec.title | lower }}/cli"
29+
${{ spec.title | upper }}_CLI_IMAGE_NAME = "{{ spec.title | lower }}/cli"
3030

3131
# {{ spec.title | caseUcfirst }} CLI image version
32-
$APPWRITE_CLI_IMAGE_VERSION = "$version"
32+
${{ spec.title | upper }}_CLI_IMAGE_VERSION = "$version"
3333

34-
$APPWRITE_EXECUTABLE_CONTENT = @"
34+
${{ spec.title | upper }}_EXECUTABLE_CONTENT = @"
3535
$allowList = 'help', 'init', 'client' {% for service in spec.services %}, '{{ service.name }}'{% endfor %}
3636

3737
if ( $args.count -eq 0 ) {
@@ -43,7 +43,7 @@ if ( -not ($allowList -contains $args[0])) {
4343
exit 1
4444
}
4545

46-
docker run -i --rm --volume {{ spec.title | lower }}-cli:/usr/local/code/app/.preferences/ --volume `$pwd``:/usr/local/code/files:rw $APPWRITE_CLI_IMAGE_NAME`:$APPWRITE_CLI_IMAGE_VERSION (`$args | % {[uri]::EscapeUriString(`$_)})"@
46+
docker run -i --rm --volume {{ spec.title | lower }}-cli:/usr/local/code/app/.preferences/ --volume `$pwd``:/usr/local/code/files:rw ${{ spec.title | upper }}_CLI_IMAGE_NAME`:${{ spec.title | upper }}_CLI_IMAGE_VERSION (`$args | % {[uri]::EscapeUriString(`$_)})"@
4747

4848
$USER_PATH_ENV_VAR = [Environment]::GetEnvironmentVariable("PATH", "User")
4949

@@ -80,19 +80,19 @@ function PerformChecks {
8080
function Install {
8181
Write-Host "[3/4] Starting installation ..."
8282

83-
$out = (Invoke-Expression "docker pull $APPWRITE_CLI_IMAGE_NAME`:$APPWRITE_CLI_IMAGE_VERSION") | Out-String
83+
$out = (Invoke-Expression "docker pull ${{ spec.title | upper }}_CLI_IMAGE_NAME`:${{ spec.title | upper }}_CLI_IMAGE_VERSION") | Out-String
8484

8585
if ($out -NotMatch "Image is up to date|Downloaded newer image") {
8686
throw "Failed to fetch docker image. Exiting ..."
8787
}
8888

89-
[void](New-Item -Path $APPWRITE_EXECUTABLE_FILEPATH -Value $APPWRITE_EXECUTABLE_CONTENT -ItemType File -Force)
89+
[void](New-Item -Path ${{ spec.title | upper }}_EXECUTABLE_FILEPATH -Value ${{ spec.title | upper }}_EXECUTABLE_CONTENT -ItemType File -Force)
9090

9191
if ($USER_PATH_ENV_VAR -like '*{{ spec.title | caseUcfirst }}*') {
9292
Write-Host "Skipping to add {{ spec.title | caseUcfirst }} to User Path."
9393
}
9494
else {
95-
[System.Environment]::SetEnvironmentVariable("PATH", $USER_PATH_ENV_VAR + ";$APPWRITE_INSTALL_DIR", "User")
95+
[System.Environment]::SetEnvironmentVariable("PATH", $USER_PATH_ENV_VAR + ";${{ spec.title | upper }}_INSTALL_DIR", "User")
9696
}
9797
}
9898

templates/cli/install.sh.twig

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ $version = $this->getParam('version', '');
1818
# You can use "View source" of this page to see the full script.
1919

2020
# {{ spec.title | caseUcfirst }} CLI location
21-
: ${APPWRITE_INSTALL_DIR:="/usr/local/bin"}
21+
{{ spec.title | upper }}_INSTALL_DIR="/usr/local/bin"
2222

2323
# {{ spec.title | caseUcfirst }} CLI Executable name
24-
APPWRITE_EXECUTABLE_NAME={{ language.params.executableName }}
24+
{{ spec.title | upper }}_EXECUTABLE_NAME={{ language.params.executableName }}
2525

2626
# {{ spec.title | caseUcfirst }} executable file path
27-
APPWRITE_EXECUTABLE_FILEPATH="${APPWRITE_INSTALL_DIR}/${APPWRITE_EXECUTABLE_NAME}"
27+
{{ spec.title | upper }}_EXECUTABLE_FILEPATH="${{ spec.title | upper }}_INSTALL_DIR/${{ spec.title | upper }}_EXECUTABLE_NAME"
2828

2929
# {{ spec.title | caseUcfirst }} CLI image name
30-
APPWRITE_CLI_IMAGE_NAME={{ spec.title | lower }}/cli
30+
{{ spec.title | upper }}_CLI_IMAGE_NAME={{ spec.title | lower }}/cli
3131

3232
# {{ spec.title | caseUcfirst }} CLI image version
33-
APPWRITE_CLI_IMAGE_VERSION=$version
34-
# sudo is required to copy executable to APPWRITE_INSTALL_DIR for linux
35-
: ${USE_SUDO:="false"}]
33+
{{ spec.title | upper }}_CLI_IMAGE_VERSION=$version
34+
35+
# sudo is required to copy executable to {{ spec.title | upper }}_INSTALL_DIR for linux
36+
USE_SUDO="false"
3637

3738
# Add some color to life
3839
RED='\033[0;31m'
@@ -60,7 +61,7 @@ getSystemInfo() {
6061
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
6162

6263
# Need root access if its a linux system
63-
if [ "$OS" == "linux" ] && [ "$APPWRITE_INSTALL_DIR" == "/usr/local/bin" ]; then
64+
if [ "$OS" == "linux" ] && [ "${{ spec.title | upper }}_INSTALL_DIR" == "/usr/local/bin" ]; then
6465
USE_SUDO="true"
6566
fi
6667

@@ -108,7 +109,7 @@ install() {
108109

109110
# Fetch the {{ spec.title | caseUcfirst }} CLI Image.
110111
printf "${GREEN}🐳 Pulling docker image ... ${NC}\n"
111-
out=$(docker pull "${APPWRITE_CLI_IMAGE_NAME}:${APPWRITE_CLI_IMAGE_VERSION}")
112+
out=$(docker pull "${{ spec.title | upper }}_CLI_IMAGE_NAME:${{ spec.title | upper }}_CLI_IMAGE_VERSION")
112113
if [[ $out != *"Image is up to date"* ]] && [[ $out != *"Downloaded newer image"* ]]; then
113114
printf "${RED}❌ Failed to fetch docker image. Exiting ... ${NC}\n"
114115
exit 1
@@ -140,30 +141,30 @@ for x in "${@}" ; do
140141
_args=$_args" "$x
141142
done
142143

143-
bash -c "docker run -i --rm --volume {{ spec.title | lower }}-cli:/usr/local/code/app/.preferences/ --volume $(pwd):/usr/local/code/files:rw --network host '$APPWRITE_CLI_IMAGE_NAME:$APPWRITE_CLI_IMAGE_VERSION' $_args" ' > $APPWRITE_EXECUTABLE_NAME
144+
bash -c "docker run -i --rm --volume {{ spec.title | lower }}-cli:/usr/local/code/app/.preferences/ --volume $(pwd):/usr/local/code/files:rw --network host '${{ spec.title | upper }}_CLI_IMAGE_NAME:${{ spec.title | upper }}_CLI_IMAGE_VERSION' $_args" ' > ${{ spec.title | upper }}_EXECUTABLE_NAME
144145

145146
printf "${GREEN}🚧 Setting Permissions ${NC}\n"
146-
chmod +x $APPWRITE_EXECUTABLE_NAME
147+
chmod +x ${{ spec.title | upper }}_EXECUTABLE_NAME
147148
if [ $? -ne 0 ]; then
148149
printf "${RED}❌ Failed to set permissions ... ${NC}\n"
149150
exit 1
150151
fi
151152
printSuccess
152153

153-
printf "${GREEN}📝 Copying file to $APPWRITE_EXECUTABLE_FILEPATH ... ${NC}\n"
154-
runAsRoot cp $APPWRITE_EXECUTABLE_NAME $APPWRITE_EXECUTABLE_FILEPATH
154+
printf "${GREEN}📝 Copying file to ${{ spec.title | upper }}_EXECUTABLE_FILEPATH ... ${NC}\n"
155+
runAsRoot cp ${{ spec.title | upper }}_EXECUTABLE_NAME ${{ spec.title | upper }}_EXECUTABLE_FILEPATH
155156
if [ $? -ne 0 ]; then
156-
printf "${RED}❌ Failed to copy file to $APPWRITE_EXECUTABLE_FILEPATH ... ${NC}\n"
157+
printf "${RED}❌ Failed to copy file to ${{ spec.title | upper }}_EXECUTABLE_FILEPATH ... ${NC}\n"
157158
exit 1
158159
fi
159160
printSuccess
160161
}
161162

162163
cleanup() {
163164
echo "🧹 Cleaning up mess ... "
164-
rm $APPWRITE_EXECUTABLE_NAME
165+
rm ${{ spec.title | upper }}_EXECUTABLE_NAME
165166
if [ $? -ne 0 ]; then
166-
printf "${RED}❌ Failed to remove $APPWRITE_EXECUTABLE_NAME ... ${NC}\n"
167+
printf "${RED}❌ Failed to remove ${{ spec.title | upper }}_EXECUTABLE_NAME ... ${NC}\n"
167168
exit 1
168169
fi
169170
printSuccess

0 commit comments

Comments
 (0)