-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·141 lines (123 loc) · 4.3 KB
/
install
File metadata and controls
executable file
·141 lines (123 loc) · 4.3 KB
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
134
135
136
137
138
139
140
141
#!/bin/sh -e
: ${STACKER_HOME:=~/.stacker}
: ${STACKER_BIN:=/usr/local/bin/stacker}
NODE_VERSION=v1.3.0
NODE_BASE_URL=https://iojs.org/dist/${NODE_VERSION}/
NODE_DIR=${STACKER_HOME}/package/iojs/
NODE_CHECKSUM_darwin_x64=00c45575b8ce578434038655daf09903361edf5c96858e2581647f349e14a8cd
NODE_CHECKSUM_linux_x64=3fa309fce40a9ad94a612c91443034456d6e109e4e63a039f72e3ea5fc31e592
NODE_CHECKSUM_linux_x86=3c747f9af20824a085967042055032838acf100e35d4a90a68e67bb478aff2e7
STACKER_HOME_BIN=${STACKER_HOME}/package/stacker/stacker/bin/stacker
ask_permission() {
printf "\nThis script will install stacker CLI and a self contained version of NodeJS.\n"
printf "No path, ENV vars, or profile scripts will be modified. All files will be\n"
printf "contained in the install directory execpt for a link to the stacker bin.\n"
printf "\nInstall directory: \e[0;36m%s\e[0m\n" "${STACKER_HOME}"
printf "Stacker bin: \e[0;36m%s\e[0m\n" "${STACKER_BIN}"
if [ -f "${STACKER_HOME_BIN}" ]; then
printf "\n\e[0;31m[WARNING]\e[0m %s already exists.\n" "${STACKER_BIN}"
printf "Installing stacker will result in overwriting this file.\n"
fi
while true; do
printf "\n\e[0;35mInstall stacker?\e[0m [Y/n] "
read yn
case $yn in
[Yy]* ) return;;
[Nn]* ) exit 0;;
* ) return;;
esac
done
}
unsupported() {
echo 'Sorry, your OS is not currently supported by the stacker install script.'
echo 'Please add an issue https://github.com/getstacker/stacker/issues'
exit 1
}
get_platform(){
PLATFORM=$(uname | tr '[:upper:]' '[:lower:]')
ARCH=$(uname -m)
if [ "$(echo "${ARCH}" | cut -c5-6)" = "64" ]; then
ARCH=x64
elif [ "$(echo "${ARCH}" | cut -c1-3)" = "x86" ]; then
ARCH=x86
else
unsupported
fi
}
install_stacker() {
local pkg_name; pkg_name=stacker
local pkg_url; pkg_url="https://github.com/getstacker/${pkg_name}.git"
local pkg_dir; pkg_dir="${STACKER_HOME}/package/stacker"
printf "\n\e[0;36m[INSTALLING]\e[0m %s\n%s\n-> %s\n" "${pkg_name}" "${pkg_url}" "${pkg_dir}"
mkdir -vp "${pkg_dir}"
cd "${STACKER_HOME}/package/stacker"
if test -d $pkg_name/.git; then
printf "Git pull... "
git -C ./$pkg_name pull
else
printf "Git clone... "
git clone "${pkg_url}"
fi
}
install_stacker_packages() {
local pkg_dir; pkg_dir="${STACKER_HOME}/package/stacker/stacker"
printf "\n\e[0;36m[INSTALLING]\e[0m stacker npm modules\n-> %s\n" "${pkg_dir}"
cd "${pkg_dir}"
"${NODE_DIR}"/node/bin/npm install
}
install_node() {
local pkg_name; pkg_name="iojs-${NODE_VERSION}-${PLATFORM}-${ARCH}.tar.gz"
local dir_name; dir_name=$(basename -s .tar.gz "${pkg_name}")
local node_url; node_url=${NODE_BASE_URL}${pkg_name}
local checksum;
printf "\n\e[0;36m[INSTALLING]\e[0m Node io.js %s\n%s\n-> %s\n" "${NODE_VERSION}" "${node_url}" "${NODE_DIR}"
remove_dir "${NODE_DIR}"
mkdir -vp "${NODE_DIR}"
cd "${NODE_DIR}"
test -d "${dir_name}" && rm -rf "${dir_name}"
test -e "${pkg_name}" && rm -f "${pkg_name}"
printf "Downloading...\n"
curl -SLo "${pkg_name}" "${node_url}"
printf "\nVerifying node io.js\n"
checksum=NODE_CHECKSUM_${PLATFORM}_${ARCH}
echo "${!checksum}"
if [ "$(shasum -b -a 256 "${pkg_name}" | cut -c1-64)" = "${!checksum}" ]; then
printf "Verified!\n"
else
printf "\e[01;31m[ERROR]\e[0m Failed checksum\n\n"
printf "Try again. Node io.js was not successfully downloaded.\n"
exit 1
fi
tar -xzf "${pkg_name}"
ln -sfn "${dir_name}" node
rm "${pkg_name}"
}
link_stacker() {
printf "\n\e[0;36m[LINKING]\e[0m stacker bin\n%s\n-> %s\n" "${STACKER_HOME_BIN}" "${STACKER_BIN}"
ln -sf "${STACKER_HOME_BIN}" "${STACKER_BIN}"
if [ "$(which stacker)" != "${STACKER_BIN}" ]; then
printf "\n\e[0;31m[WARNING]\e[0m another program named stacker appears earlier in the path\n"
printf "%s\n" "$(which stacker)"
fi
}
remove_dir() {
local dir; dir="$1"
# Only allow removing dir if nested in $STACKER_HOME
if [ "${dir#*$STACKER_HOME}" = "${dir}" ]; then
printf "\e[01;31m[ERROR]\e[0m Refusing to remove dir: %s\n" "${dir}"
exit 1
fi
printf "Removing dir: %s\n" "${dir}"
rm -rf "${dir}"
}
main() {
ask_permission
get_platform
install_stacker
install_node
install_stacker_packages
link_stacker
printf "\n\e[0;32m[SUCCESS]\e[0m installed stacker\n"
printf "\n\e[0;36mUsage:\e[0m\n stacker help\n\n"
}
main