Unverified Commit 6e8c3128 authored by Aral Balkan's avatar Aral Balkan
Browse files

Install script no longer installs Node. Tabs → spaces

We now exit if Node doesn’t exist. We also warn if the required version of Node doesn’t exist.
parent bc5f2808
......@@ -40,9 +40,9 @@ accountName='better'
# Runs command in requested directory and restores the working directory at the end.
# Usage: run <directory> "<command>"
runIn(){
pushd $1 >/dev/null
eval $2
popd >/dev/null
pushd $1 >/dev/null
eval $2
popd >/dev/null
}
#
......@@ -54,7 +54,7 @@ indent() {
}
greetings(){
echo -e "\n❤ Installing Better Inspector."
echo -e "\n❤ Installing Better Inspector."
}
#
......@@ -62,43 +62,30 @@ greetings(){
#
ensureDependenciesExist(){
ensureNodeExists
ensureBuilderExists
ensureNodeExists
ensureBuilderExists
}
ensureBuilderExists(){
install "builder" "Better Builder"
install "builder" "Better Builder"
}
# Checks that Node.js is installed.
ensureNodeExists(){
#
# Makes sure that Node.js is installed. (OS X only at the moment)
#
# Note: we do not check for the edge case where Node.js is installed but npm
# isn’t, as npm comes bundled with recent versions of Node.
#
latestNodeLTSVersion=4.4.7
if ! hash node 2>/dev/null; then
echo -e "\n • Node.js not installed. Installing…"
# Prepare a temporary directory.
rm -rf /tmp/node.js
mkdir /tmp/node.js
echo -e " • Downloading Node.js installer (latest LTS)…"
runIn /tmp/node.js "curl -OL https://nodejs.org/dist/latest-argon/node-v${latestNodeLTSVersion}.pkg"
echo -e " • Running the Node.js package installer. Please enter your password to continue:"
sudo installer -pkg "/tmp/node.js/node-v${latestNodeLTSVersion}.pkg" -target /
# The OS X installer doesn’t automatically adjust the permissions for /usr/local
# properly. Fix it so we don’t have to use sudo when installing npm modules globally.
sudo chown -R $USER /usr/local
fi
REQUIRED_NODE_VERSION="v8.11.3"
if ! hash node 2>/dev/null; then
echo -e "\n • Node.js not installed. Exiting."
exit 1
fi
# Warn if the required version of Node is not found.
nodeVersion=$(node --version)
if [ $nodeVersion != REQUIRED_NODE_VERSION ]; then
echo -e "\n • Warning: Node $REQUIRED_NODE_VERSION required but $nodeVersion found. Things may misbehave."
fi
}
#
......@@ -110,122 +97,122 @@ ensureNodeExists(){
#
install(){
componentToInstall=$1
humanName=$2
componentToInstall=$1
humanName=$2
relativePathToComponent="../${componentToInstall}"
relativePathToComponent="../${componentToInstall}"
# Check if a Better Builder installation exists.
if [ -d $relativePathToComponent ]; then
echo -e " • Existing ${humanName} found. Skipping installation."
return 0
fi
# Check if a Better Builder installation exists.
if [ -d $relativePathToComponent ]; then
echo -e " • Existing ${humanName} found. Skipping installation."
return 0
fi
echo -e "\n • Cloning ${humanName}…"
runIn .. "git clone --quiet git@source.ind.ie:${accountName}/${componentToInstall}.git"
echo -e "\n • Cloning ${humanName}…"
runIn .. "git clone --quiet git@source.ind.ie:${accountName}/${componentToInstall}.git"
echo -e "\n • Running installation script for ${humanName}…"
cd $relativePathToComponent
./install | indent ' '
cd ../inspector
echo -e "\n • Running installation script for ${humanName}…"
cd $relativePathToComponent
./install | indent ' '
cd ../inspector
# Check that the installation completed successfully
if [ -f "/tmp/better.fyi.${componentToInstall}.installation.is.incomplete" ]; then
# Error
echo -e " • Error: ${humanName} installation was interrupted. Exiting."
exit 1
fi
# Check that the installation completed successfully
if [ -f "/tmp/better.fyi.${componentToInstall}.installation.is.incomplete" ]; then
# Error
echo -e " • Error: ${humanName} installation was interrupted. Exiting."
exit 1
fi
# OK
echo -e "\n${humanName} installed."
# OK
echo -e "\n${humanName} installed."
}
makeDirectoryIfItDoesntAlreadyExist(){
if ! [ -d $1 ]; then
echo -e " • Making the $1 directory."
mkdir -p $1
fi
if ! [ -d $1 ]; then
echo -e " • Making the $1 directory."
mkdir -p $1
fi
}
cloneDraftsRepositoryIfItDoesntExist(){
repositoryName=$1
draftsPath=~/better.fyi/drafts
workingCopyPath="${draftsPath}/${repositoryName}"
if ! [ -d workingCopyPath ]; then
echo -e " • Cloning drafts repository: ${repositoryName}"
runIn $draftsPath "git clone --quiet https://drafts.better.fyi/inspector/${repositoryName}.git"
fi
repositoryName=$1
draftsPath=~/better.fyi/drafts
workingCopyPath="${draftsPath}/${repositoryName}"
if ! [ -d workingCopyPath ]; then
echo -e " • Cloning drafts repository: ${repositoryName}"
runIn $draftsPath "git clone --quiet https://drafts.better.fyi/inspector/${repositoryName}.git"
fi
}
installSelf(){
#
# Install ourselves.
#
echo -e " • Installing node dependencies via npm."
npm install
#
# Make the drafts directory.
#
draftsDirectory=~/better.fyi/drafts
makeDirectoryIfItDoesntAlreadyExist $draftsDirectory
# Make a symbolic link from the main directory for easy access.
if ! [ -d ../drafts ]; then ln -s $draftsDirectory ../drafts; fi
#
# Clone the drafts repositories.
#
cloneDraftsRepositoryIfItDoesntExist "sites"
cloneDraftsRepositoryIfItDoesntExist "trackers"
#
# Clone the domains repository.
#
echo -e " • Cloning domains repository"
runIn ~/better.fyi "git clone --quiet https://source.ind.ie/better/domains.git"
# Make a symbolic link to the domains repository for ease of access during development.
if ! [ -d ../domains ]; then ln -s ~/better.fyi/domains ../domains; fi
#
# Download the archive.
#
echo -e " • Downloading HTTP Archive (this will take a while)."
#
# Create the archive directory.
#
archiveDirectory=~/better.fyi/archive
makeDirectoryIfItDoesntAlreadyExist $archiveDirectory
# Make a symbolic link from the main directory for easy access.
if ! [ -d ../archive ]; then ln -s $archiveDirectory ../archive; fi
# Rsync the archive directory from the archive server, while giving progress on a single line.
rsync -aPh rsync://archive.better.fyi/archive $archiveDirectory
#
# Run a local inquiry
#
echo -e " • Running a local inquiry to build the statistics and drafts. This will take a couple of minutes."
./inquiry --local
#
# Install ourselves.
#
echo -e " • Installing node dependencies via npm."
npm install
#
# Make the drafts directory.
#
draftsDirectory=~/better.fyi/drafts
makeDirectoryIfItDoesntAlreadyExist $draftsDirectory
# Make a symbolic link from the main directory for easy access.
if ! [ -d ../drafts ]; then ln -s $draftsDirectory ../drafts; fi
#
# Clone the drafts repositories.
#
cloneDraftsRepositoryIfItDoesntExist "sites"
cloneDraftsRepositoryIfItDoesntExist "trackers"
#
# Clone the domains repository.
#
echo -e " • Cloning domains repository"
runIn ~/better.fyi "git clone --quiet https://source.ind.ie/better/domains.git"
# Make a symbolic link to the domains repository for ease of access during development.
if ! [ -d ../domains ]; then ln -s ~/better.fyi/domains ../domains; fi
#
# Download the archive.
#
echo -e " • Downloading HTTP Archive (this will take a while)."
#
# Create the archive directory.
#
archiveDirectory=~/better.fyi/archive
makeDirectoryIfItDoesntAlreadyExist $archiveDirectory
# Make a symbolic link from the main directory for easy access.
if ! [ -d ../archive ]; then ln -s $archiveDirectory ../archive; fi
# Rsync the archive directory from the archive server, while giving progress on a single line.
rsync -aPh rsync://archive.better.fyi/archive $archiveDirectory
#
# Run a local inquiry
#
echo -e " • Running a local inquiry to build the statistics and drafts. This will take a couple of minutes."
./inquiry --local
}
flagStart(){
# Flag that we are not complete (in case another process needs to check)
touch /tmp/better.fyi.inspector.installation.is.incomplete
# Flag that we are not complete (in case another process needs to check)
touch /tmp/better.fyi.inspector.installation.is.incomplete
}
flagEnd(){
# Remove the flag we set at the beginning to signal that we are complete.
rm /tmp/better.fyi.inspector.installation.is.incomplete
# Remove the flag we set at the beginning to signal that we are complete.
rm /tmp/better.fyi.inspector.installation.is.incomplete
}
#
......@@ -233,17 +220,17 @@ flagEnd(){
# if we are being run from there.
#
getAccountName(){
persistedAccountName=../better/.accountname
if [ -f "${persistedAccountName}" ]; then
# Account name exists, use that
accountName=$(cat "${persistedAccountName}")
if [ $accountName = 'better' ]; then
echo -e " • Will clone from the canonical Better repository."
else
echo -e " • Will clone from your custom fork in the ${acccountName} account."
fi
fi
persistedAccountName=../better/.accountname
if [ -f "${persistedAccountName}" ]; then
# Account name exists, use that
accountName=$(cat "${persistedAccountName}")
if [ $accountName = 'better' ]; then
echo -e " • Will clone from the canonical Better repository."
else
echo -e " • Will clone from your custom fork in the ${acccountName} account."
fi
fi
}
#
......@@ -251,12 +238,12 @@ getAccountName(){
#
main(){
flagStart
getAccountName
greetings
ensureDependenciesExist
installSelf
flagEnd
flagStart
getAccountName
greetings
ensureDependenciesExist
installSelf
flagEnd
}
main
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment