install 4.22 KB
Newer Older
1
2
#!/bin/bash

3
######################################################################
4
#
5
# Site.js installer for Linux (x86 and ARM) and macOS.
6
#
7
# Usage:
8
9
10
#
# wget -qO- https://sitejs.org/install | bash
#
11
12
13
14
15
16
17
# Or:
#
# curl -s https://sitejs.org/install | bash
#
# For alpha, replace bash with bash -s -- alpha
# For beta, replace bash with bash -s -- beta
#
18
# Copyright (c) 2019-2020 Aral Balkan.
Aral Balkan's avatar
Aral Balkan committed
19
20
# Released under the AGPL version 3.0 or later license.
# Made with ♥ by Small Technology Foundation (https://small-tech.org)
21
#
Aral Balkan's avatar
Aral Balkan committed
22
# Like this? Fund us! (https://small-tech.org/fund-us)
23
#
24
######################################################################
25
26
27
28
29
30
31
32

set -e

function cleanUp {
  popd > /dev/null
  rm -rf /tmp/sitejs.org
}

33
34
releaseType=$1

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
# Release is the default release type (others are alpha and beta).
if [[ "$releaseType" == "" ]]; then
  releaseType='release'
fi

alphaBinaryVersion=00000000000000
alphaSourceVersion=00.00.00

betaBinaryVersion=00000000000000
betaSourceVersion=00.00.00

releaseBinaryVersion=00000000000000
releaseSourceVersion=00.00.00

binaryVersionVariableName="${releaseType}BinaryVersion"
sourceVersionVariableName="${releaseType}SourceVersion"

binaryVersion=${!binaryVersionVariableName}
sourceVersion=${!sourceVersionVariableName}

if [[ "$binaryVersion" == "00000000000000" ]]; then
  echo " ❌ Sorry, no Site.js ${releaseType} binaries have been released yet."
  cleanUp
  exit 1
fi

echo
echo " 📡 Downloading Site.js version ${binaryVersion}/${sourceVersion}…"

# Mark alpha and beta releases prominently.
65
if [[ "$releaseType" == "alpha" ]]; then
66

67
68
69
70
71
72
73
74
  # Writes ALPHA in large red block letters.
  echo -e '\033[31m'
  echo '     █████  ██      ██████  ██   ██  █████'
  echo '    ██   ██ ██      ██   ██ ██   ██ ██   ██ '
  echo '    ███████ ██      ██████  ███████ ███████ '
  echo '    ██   ██ ██      ██      ██   ██ ██   ██ '
  echo '    ██   ██ ███████ ██      ██   ██ ██   ██'
  echo -e '\033[0m'
75

76
elif [[ "$releaseType" == "beta" ]]; then
77

78
79
80
81
82
83
84
85
  # Writes BETA in large yellow block letters.
  echo -e '\033[33m'
  echo '    ██████  ███████ ████████  █████ '
  echo '    ██   ██ ██         ██    ██   ██ '
  echo '    ██████  █████      ██    ███████ '
  echo '    ██   ██ ██         ██    ██   ██ '
  echo '    ██████  ███████    ██    ██   ██'
  echo -e '\033[0m'
86

87
88
fi

89
# Setup.
90
91
92
93
rm -rf /tmp/sitejs.org
mkdir -p /tmp/sitejs.org
pushd /tmp/sitejs.org > /dev/null

94
# Download the release.
95
if [[ "$OSTYPE" == "linux-gnu" || "$OSTYPE" == "linux-gnueabihf" ]]; then
96
  cpuArchitecture=`uname -m`
97
  if [[ "$cpuArchitecture" == "x86_64" ]]; then
98
    # Linux on x64.
99
    wget -q "https://sitejs.org/binaries/${releaseType}/linux/${binaryVersion}.tar.gz"
100
101
  elif [[ "$cpuArchitecture" == "armv7l" || "$cpuArchitecture" == "armv6l" ]]; then
    # Linux on ARM. Tested on Raspberry Pi Zero W (armv6l), 3B+ and 4B (both reporting armv7l).
102
    wget -q "https://sitejs.org/binaries/${releaseType}/linux-arm/${binaryVersion}.tar.gz"
103
  else
104
    # Error: unsupported architecture.
105
106
107
    echo
    echo " ❌ Error: this architecture is not supported on Linux (only x86_64, armv6l, and armv7l are)."
    echo
108
109
110
    cleanUp
    exit 1
  fi
111
112
elif [[ "$OSTYPE" == "darwin"* ]]; then
  # macOS
113
  curl -Os "https://sitejs.org/binaries/${releaseType}/macos/${binaryVersion}.tar.gz"
114
else
115
  # Error: Unsupported operating system.
116
117
118
  echo
  echo " ❌ Error: this operating system is not supported."
  echo
119
120
121
122
  cleanUp
  exit 1
fi

123
# Install.
124
echo " 📦 Installing…"
125
126
gzip -d "${binaryVersion}.tar.gz"
tar -xf "${binaryVersion}.tar"
127

128
# Ensure /usr/local/bin directory exists (it does not by default on macOS)
129
130
sudo mkdir -p /usr/local/bin/

131
# Install the Site.js binary.
132
133
134
135
136
137
sudo mv site /usr/local/bin/

cleanUp

echo " 🎉 Done!"
echo