Commit b75484de authored by Aral Balkan's avatar Aral Balkan

Merge branch 'installation-fix' into 'master'

Updates the installation script to implement forking and installing from forks



See merge request !1
parents af949bf0 9b0b0b24
......@@ -13,6 +13,10 @@ set -e
# The installation script is non-destructive and will not replace existing
# directories from a previous installation.
#
# Developers have the option of automatically forking the repositories
# during installation so that they can easily hack on Better and submit
# merge requests to the upstream (canonical) repositories.
#
# This is Independent Technology.
#
# ▲❤ We practice Ethical Design (https://ind.ie/ethical-design)
......@@ -23,15 +27,80 @@ set -e
#
################################################################################
#
# Properties
#
optionInstallEverything=false
optionFork=false
optionAccountName=better
humanNameOfThingToInstall=null
ask() {
# Modified slightly from https://gist.github.com/davejamesmiller/1965569
while true; do
if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi
# Ask the question (not using "read -p" as it uses stderr not stdout)
echo "$1 ($prompt) \n"
# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
# read REPLY </dev/tty
read -e -p "▶ " REPLY
# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi
# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac
done
}
#
# Prints out a link to the Better app on the App Store on premature exits.
#
exitPS(){
echo "PS. You can purchase and install Better from the App Store at:\nhttps://itunes.apple.com/us/app/better-by-ind.ie/id1080964978?mt=8\n"
echo "Laura, Osky, and I (Aral) appreciate your support! :)\nhttps://ind.ie/team\n"
}
#
# Returns the account name for the account associated with the private token.
#
accountName(){
accountName=$(curl --silent --header "PRIVATE-TOKEN: ${privateToken}" -X GET https://source.ind.ie/api/v3/user/ | ./jq --raw-output .username)
echo $accountName
}
menu(){
echo ""
echo " ____ _ _ ";
echo " | _ \ | | | | ";
echo " | |_) | ___| |_| |_ ___ _ __ ";
echo " | _ < / _ \ __| __/ _ \ '__|";
echo " _ _"
echo " ( \/ )"
echo " ____ _ _ \ /";
echo " | _ \ | | | | \/";
echo " | |_) | ___| |_| |_ ___ _ __ |";
echo " | _ < / _ \ __| __/ _ \ '__| /";
echo " | |_) | __/ |_| || __/ | ";
echo " |____/ \___|\__|\__\___|_| ";
# Question 1
title="\n\nHej hej! What would you like to install?\n"
prompt="▶ "
options=("Everything (iOS App, Safari Extension, Inspector)" "Just the Inspector")
......@@ -41,28 +110,124 @@ PS3="
$prompt "
select opt in "${options[@]}" "Nothing, get me out of here!"; do
case "$REPLY" in
case "$REPLY" in
1 ) optionInstallEverything=true; humanNameOfThingToInstall="iOS App, etc.,"; break;;
2 ) optionInstallEverything=false; humanNameOfThingToInstall="Inspector"; break;;
$(( ${#options[@]}+1 )) ) echo "\nSee you later! :)\n"; exitPS; exit;;
*) echo "\nOops, I only understand numbers between 1 and 3.";continue;;
esac
done
# Question 2
title="\nShould I install from your forks or the canonical repositories?\n\n• Choose ‘use my forks’ if you want to hack on the code and submit\n merge requests easily. (This will automatically fork the projects\n if you haven’t done so already yourself, so don’t worry.)\n\n• Select ‘use canonical repositories’ if you just want to run the\n ${humanNameOfThingToInstall} or if you have commit access to the canonical repositories.\n\n• If you have no idea what any of this means, pick option 2\n (or purchase & install Better from the App Store with a tap) ;)\n"
prompt="▶ "
options=("Use my forks." "Use canonical repositories.")
echo "$title"
PS3="
$prompt "
select opt in "${options[@]}" "I have second thoughts about all this, get me out of here!"; do
case "$REPLY" in
1 ) installEverything; break;;
2 ) installInspector; break;;
1 ) optionFork=true; break;;
2 ) optionFork=false; break;;
$(( ${#options[@]}+1 )) ) echo "\nSee you later! :)\n"; break;;
*) echo "\nOops, I only understand numbers between 1 and 3.";continue;;
$(( ${#options[@]}+1 )) ) echo "\nNo worries, we all get cold feet sometimes. Bye! :)\n"; exitPS; exit;;
*) echo "\nOops, I only understand numbers between 1 and 3.";continue;;
esac
esac
done
#
# If person wants to fork, we need their private token so we can
# automatically fork the repositories via the GitLab API.
#
if [ $optionFork = true ]; then
echo """
Sure, I’ll use your forks (and create them if necessary) :)
To continue:
1. Sign up for an account at:
https://source.ind.ie
2. Generate and add an SSH key to your account at:
https://source.ind.ie/profile/keys
3. Visit:
https://source.ind.ie/profile/account
4. Copy your Private Token
"""
read -e -p "5. Paste it here: " privateToken
fi
#
# Summarise.
#
echo "\nThank you! :)\n\nI’m going to: \n"
if [ $optionInstallEverything = true ]; then
echo "• Install everything (iOS App, Safari Extension, Inspector).\n"
else
echo "• Install only Better Inspector (and its dependencies).\n"
fi
if [ $optionFork = true ]; then
# Get the account name.
optionAccountName=$(accountName)
echo "• Use (and create, if necessary) your own forks on your\n ${optionAccountName} GitLab account on source.ind.ie."
else
echo "• Using the canonical repositories (read-only unless you have commit access)."
fi
#
# Persist the account name in a hidden file so that the other
# installers can use it also.
#
echo $optionAccountName > .accountname
#
# Confirm.
#
if ask "\nMay I proceed?" Y; then
echo "\nThank you, proceeding with the installation."
if [ $optionInstallEverything = true ]; then
installEverything
else
installInspector
fi
else
echo "\nSure, no problem, maybe some other time. Bye! :)\n"
exit
fi
}
#
# 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
}
#
# Runs the passed command, formatting the output with the passed indentation (default: 4 spaces)
#
indentOutput(){
commandToRun=$1
indentation=${2:-' '}
......@@ -75,7 +240,12 @@ indentOutput(){
#
installEverything(){
echo "\nInstalling everything."
if [ $optionFork = true ]; then
echo "\nEnsuring forks exist:\n"
ensureForksExistForEverything
fi
echo "\nInstalling everything:"
# 1. Install the Better iOS App (which will, in turn, install its dependencies, the Inspector and Builder)
install "app" "Better iOS App"
......@@ -84,7 +254,13 @@ installEverything(){
install "safari" "Better Safari Extension"
}
installInspector(){
if [ $optionFork = true ]; then
echo "\nForking inspector (and builder)…"
ensureForksExistForInspector
fi
echo "\nInstalling inspector."
install "inspector" "Better Inspector"
}
......@@ -99,14 +275,14 @@ install(){
# Check if a Better Builder installation exists.
if [ -d componentToInstall ]; then
echo " · Existing ${humanName} found. Skipping installation."
echo " Existing ${humanName} found. Skipping installation."
return 0
fi
echo "\n · Cloning ${humanName}…"
git clone --quiet git@source.ind.ie:better/${componentToInstall}.git
echo "\n Cloning ${humanName}…"
git clone --quiet git@source.ind.ie:${optionAccountName}/${componentToInstall}.git
echo "\n · Running installation script for ${humanName}…"
echo "\n Running installation script for ${humanName}…"
cd $componentToInstall
indentOutput "./install" ' '
cd ..
......@@ -114,12 +290,53 @@ install(){
# Check that the installation completed successfully
if [ -f "/tmp/better.fyi.${componentToInstall}.installation.is.incomplete" ]; then
# Error
echo " · Error: ${humanName} installation was interrupted. Exiting."
echo " Error: ${humanName} installation was interrupted. Exiting."
exit 1
fi
# OK
echo "\n · ${humanName} installed."
echo "\n${humanName} installed."
}
#
# Forks (if necessary) and installs a component. e.g., ensureForkExists "app" "Better iOS App" "<ID of project on source.ind.ie>"
#
ensureForkExists(){
componentToInstall=$1
humanName=$2
projectID=$3
# Check if a Better Builder installation exists.
if [ -d componentToInstall ]; then
echo " • Existing ${humanName} found locally. Skipping fork."
return 0
fi
printf " • For ${humanName}…"
forkResult=$(curl --silent --header "PRIVATE-TOKEN: ${privateToken}" -X POST https://source.ind.ie/api/v3/projects/fork/${projectID})
printf " OK.\n"
}
#
# Fork the Inspector (which depends on the Builder)
#
ensureForksExistForInspector(){
ensureForkExists "inspector" "Better Inspector" "151"
ensureForkExists "builder" "Better Builder" "105"
ensureForkExists "themes" "Better Themes" "136"
ensureForkExists "content" "Better Content" "106"
}
#
# Forks all repositories.
#
ensureForksExistForEverything(){
ensureForkExists "app" "Better iOS App" "107"
ensureForksExistForInspector
ensureForkExists "safari" "Better Safari Extension" "152"
}
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