install 4.46 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
releaseChannel=$1
34

35
# Release is the default release type (others are alpha and beta).
36
37
if [[ "$releaseChannel" == "" ]]; then
  releaseChannel='release'
38
39
40
fi

alphaBinaryVersion=00000000000000
41
42
alphaPackageVersion=00.00.00
alphaSourceVersion=bedface
43
44

betaBinaryVersion=00000000000000
45
betaPackageVersion=00.00.00
46
betaSourceVersion=bedface
47

Aral Balkan's avatar
Aral Balkan committed
48
49
50
releaseBinaryVersion=20200618155325
releasePackageVersion=13.0.0
releaseSourceVersion=76a9bd2
51

52
53
54
binaryVersionVariableName="${releaseChannel}BinaryVersion"
packageVersionVariableName="${releaseChannel}PackageVersion"
sourceVersionVariableName="${releaseChannel}SourceVersion"
55
56

binaryVersion=${!binaryVersionVariableName}
57
packageVersion=${!packageVersionVariableName}
58
59
60
sourceVersion=${!sourceVersionVariableName}

if [[ "$binaryVersion" == "00000000000000" ]]; then
61
  echo " ❌ Sorry, no Site.js ${releaseChannel} binaries have been released yet."
62
63
64
65
66
  cleanUp
  exit 1
fi

echo
67
echo " 📡 Downloading Site.js version ${binaryVersion} (${packageversion}/${sourceVersion})…"
68
69

# Mark alpha and beta releases prominently.
70
if [[ "$releaseChannel" == "alpha" ]]; then
71

72
73
74
75
76
77
78
79
  # Writes ALPHA in large red block letters.
  echo -e '\033[31m'
  echo '     █████  ██      ██████  ██   ██  █████'
  echo '    ██   ██ ██      ██   ██ ██   ██ ██   ██ '
  echo '    ███████ ██      ██████  ███████ ███████ '
  echo '    ██   ██ ██      ██      ██   ██ ██   ██ '
  echo '    ██   ██ ███████ ██      ██   ██ ██   ██'
  echo -e '\033[0m'
80

81
elif [[ "$releaseChannel" == "beta" ]]; then
82

83
84
85
86
87
88
89
90
  # Writes BETA in large yellow block letters.
  echo -e '\033[33m'
  echo '    ██████  ███████ ████████  █████ '
  echo '    ██   ██ ██         ██    ██   ██ '
  echo '    ██████  █████      ██    ███████ '
  echo '    ██   ██ ██         ██    ██   ██ '
  echo '    ██████  ███████    ██    ██   ██'
  echo -e '\033[0m'
91

92
93
fi

94
# Setup.
95
96
97
98
rm -rf /tmp/sitejs.org
mkdir -p /tmp/sitejs.org
pushd /tmp/sitejs.org > /dev/null

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

128
# Install.
129
echo " 📦 Installing…"
130
131
gzip -d "${binaryVersion}.tar.gz"
tar -xf "${binaryVersion}.tar"
132

133
# Ensure /usr/local/bin directory exists (it does not by default on macOS)
134
135
sudo mkdir -p /usr/local/bin/

136
# Install the Site.js binary.
137
138
139
140
141
142
sudo mv site /usr/local/bin/

cleanUp

echo " 🎉 Done!"
echo