-
Notifications
You must be signed in to change notification settings - Fork 1
/
install
executable file
·133 lines (119 loc) · 4.63 KB
/
install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
set -eu -o pipefail
function help () {
echo "$(basename ${0}): Install forklift pallet manager, or a pallet"
echo
echo "Usage: $(basename ${0})"
echo -e "\tcommands:"
echo -e "\t\t--help: Display this command line help"
echo -e "\t\t--dev: Install forklift from this directory for testing forklift"
echo -e "\t\tfor any other set of arguments this script will install forklift and then run it with the specified command line arguments"
echo
}
SELF_DIR=$(cd $(dirname ${0}) && pwd -P)
SELF=${SELF_DIR}/$(basename ${0})
DEVINSTALL=0
if [[ $# -ge 1 ]]; then
COMMAND="${1}"
case ${COMMAND} in
-h|--help|help)
help
exit 0
;;
-d|--dev|dev|--development|development)
if [ -x ${SELF_DIR}/forklift ]; then
DEVINSTALL=1
shift
else
echo "Cannot do a development install without a development copy of forklift!"
exit 1
fi
;;
esac
fi
if [ ${DEVINSTALL} -ne 0 ]; then
echo "Performing a development install of forklift from current directory"
FORKLIFT=${SELF_DIR}/forklift
${FORKLIFT} run builtin ../ current .forklift/post-import
else
TEMPDIR=$(mktemp -d)
STATUS_STEP=""
STATUS_OUTPUT=""
trap 'rm -rf ${TEMPDIR}; echo "Failed to install forklift: ${STATUS_STEP}"; echo "${STATUS_OUTPUT}" >&2;' EXIT
pushd ${TEMPDIR} 2>&1 >/dev/null
set +u
if [ -z "${RELEASE_URL}" ]; then
set -u
# Get release information from github using github API
echo "Getting information about latest release"
RELEASE_ORG="g2forge"
RELEASE_REPO="forklift"
RELEASE_DIRPREFIX="${RELEASE_ORG}-${RELEASE_REPO}"
STATUS_STEP="Downloading GitHub release metadata"
RELEASE_JSON="release.json"
curl https://api.github.com/repos/${RELEASE_ORG}/${RELEASE_REPO}/releases/latest 2> /dev/null > ${RELEASE_JSON}
STATUS_STEP="Parsing GitHub release metadata"
RELEASE_TAG_NAME=$(grep -F "tag_name" ${RELEASE_JSON} | sed -e 's/[^"]*"tag_name":[^"]*"\([^"]*\)",/\1/')
RELEASE_TARBALL_URL=$(grep -F "tarball_url" ${RELEASE_JSON} | sed -e 's/[^"]*"tarball_url":[^"]*"\([^"]*\)",/\1/')
else
set -u
# Install a specific version
echo "Installing the version from ${RELEASE_URL}"
# RELEASE_URL: The zip or tarball download URL for a specific branch
if [ ${RELEASE_URL: -4} == ".zip" ]; then
STATUS_STEP="Converting zip to tar.gz URL"
RELEASE_URL="$(dirname ${RELEASE_URL})/$(basename ${RELEASE_URL} .zip).tar.gz"
fi
STATUS_STEP="Parsing release URL"
RELEASE_TAG_NAME=$(basename ${RELEASE_URL} .tar.gz)
RELEASE_TARBALL_URL="${RELEASE_URL}"
STRIPPED=$(dirname $(dirname ${RELEASE_URL}))
RELEASE_ORG=$(basename $(dirname ${STRIPPED}))
RELEASE_REPO=$(basename ${STRIPPED})
RELEASE_DIRPREFIX="${RELEASE_REPO}"
fi
if which forklift > /dev/null 2>&1; then
# Forklift is already installed, so we can use that
FORKLIFT=forklift
STATUS_STEP="Checking installed forklift version"
INSTALLED_VERSION=$(${FORKLIFT} version)
echo "Found previous install of ${INSTALLED_VERSION}"
if [ "${INSTALLED_VERSION}" == "${RELEASE_TAG_NAME}" ] && [ "${INSTALLED_VERSION}" == "development" ]; then
echo "Already up to date, skipping download and install"
else
STATUS_STEP="Installing forklift ${RELEASE_TAG_NAME}"
echo "${STATUS_STEP}"
${FORKLIFT} import com.github ${RELEASE_ORG}/${RELEASE_REPO} ${RELEASE_TAG_NAME}
if [ "${INSTALLED_VERSION}" != "${RELEASE_TAG_NAME}" ]; then
STATUS_STEP="Removing forklift ${INSTALLED_VERSION}"
echo "${STATUS_STEP}"
${FORKLIFT} delete com.github ${RELEASE_ORG}/${RELEASE_REPO} ${INSTALLED_VERSION}
fi
fi
else
# Forklift wasn't already installed, so use curl to download a release from github for temporary usage
STATUS_STEP="Downloading forklift ${RELEASE_TAG_NAME}"
echo "${STATUS_STEP}"
RELEASE_TGZ="release.tar.gz"
curl -L ${RELEASE_TARBALL_URL} > ${RELEASE_TGZ}
STATUS_STEP="Unpacking tarball"
tar -xf ${RELEASE_TGZ}
STATUS_STEP="Parsing tarball contents"
STATUS_OUTPUT=$(find . -maxdepth 1 -mindepth 1 -type d)
RELEASE_DIR=$(find . -maxdepth 1 -mindepth 1 -type d | grep -F "./${RELEASE_DIRPREFIX}-" | head -n 1)
STATUS_STEP="Running install for ${RELEASE_TAG_NAME}"
echo "${STATUS_STEP}"
# Note that this will download, import and then run the setup script
${RELEASE_DIR}/forklift import com.github ${RELEASE_ORG}/${RELEASE_REPO} ${RELEASE_TAG_NAME}
STATUS_STEP="Getting path to new install"
FORKLIFT="$(${RELEASE_DIR}/forklift path com.github ${RELEASE_ORG}/${RELEASE_REPO} ${RELEASE_TAG_NAME})/forklift"
fi
popd 2>&1 >/dev/null
rm -rf ${TEMPDIR}
trap '' EXIT
echo "Successfully installed forklift!"
fi
if [[ $# -gt 0 ]]; then
echo "Running forklift $@"
${FORKLIFT} $@
fi