walnut.js/install.sh

121 lines
3.1 KiB
Bash
Raw Permalink Normal View History

2017-07-28 23:03:55 +00:00
#!/bin/bash
# Not every platform has or needs sudo, gotta save them O(1)s...
sudo_cmd=""
((EUID)) && [[ -z "$ANDROID_ROOT" ]] && sudo_cmd="sudo"
2017-07-28 23:03:55 +00:00
set -e
set -u
###############################
# #
# boilerplate for curl / wget #
# #
###############################
http_get=""
http_opts=""
http_out=""
detect_http_get()
{
if type -p curl >/dev/null 2>&1; then
http_get="curl"
http_opts="-fsSL"
http_out="-o"
#curl -fsSL "$caddy_url" -o "$PREFIX/tmp/$caddy_pkg"
elif type -p wget >/dev/null 2>&1; then
http_get="wget"
http_opts="--quiet"
http_out="-O"
#wget --quiet "$caddy_url" -O "$PREFIX/tmp/$caddy_pkg"
else
echo "Aborted, could not find curl or wget"
return 7
fi
}
dap_dl()
{
$http_get $http_opts $http_out "$2" "$1"
}
dap_dl_bash()
{
dap_url=$1
#dap_args=$2
rm -rf dap-tmp-runner.sh
$http_get $http_opts $http_out dap-tmp-runner.sh "$dap_url"; bash dap-tmp-runner.sh; rm dap-tmp-runner.sh
}
detect_http_get
###############################
# #
# actual script continues... #
# #
###############################
install_walnut()
{
$sudo_cmd mkdir -p /srv/walnut/{var,etc,packages,node_modules}
2017-07-28 23:03:55 +00:00
# www-data exists on linux, _www exists on mac OS
$sudo_cmd chown -R $(whoami):www-data /srv/walnut || $sudo_cmd chown -R $(whoami):_www /srv/walnut
2017-07-28 23:03:55 +00:00
if [ ! -d "/srv/walnut/core/" ]; then
git clone https://git.daplie.com/Daplie/walnut.js.git /srv/walnut/core
fi
pushd /srv/walnut/core
if [ ! -d "./.git/" ]; then
echo "'/srv/walnut/core' exists but is not a git repository... not sure what to do here..."
fi
git checkout master
2017-07-28 23:03:55 +00:00
git pull
popd
rm -rf /srv/walnut/core/node_modules
ln -sf ../node_modules /srv/walnut/core/node_modules
/srv/walnut/core/install-helper.sh /srv/walnut
# Now that the install is finished we need to set the owner to the user that will actually
# be running the walnut server.
$sudo_cmd chown -R www-data:www-data /srv/walnut || $sudo_cmd chown -R _www:_www /srv/walnut
}
2017-07-28 23:03:55 +00:00
# Install node
echo "----Installing Nodejs and NPM----"
2017-07-28 23:03:55 +00:00
echo "v8.2.1" > /tmp/NODEJS_VER
daplie-install-node-dev
npm install -g npm@4
# Install goldilocks
echo "----Installing goldilocks.js----"
2017-07-28 23:03:55 +00:00
daplie-install-goldilocks
echo "----Installing walnut.js----"
#$sudo_cmd mkdir -p /opt/goldilocks/{lib,bin,etc}
#export NODE_PATH=/opt/walnut/lib/node_modules
#export NPM_CONFIG_PREFIX=/opt/walnut
old_PATH=$PATH
export PATH=/opt/walnut/bin:$PATH
2017-07-28 23:03:55 +00:00
# Install walnut
install_walnut
# Install bower, some systems may be missing it, and it is a dependency
/opt/walnut/bin/npm install -g bower
touch /.bowerrc
echo '{ "allow_root": true }' > /.bowerrc
# Restore PATH to original value
export PATH=$old_PATH
2017-07-28 23:03:55 +00:00
echo ""
echo "You must have some set of domain set up to properly use goldilocks+walnut:"
echo ""
echo " example.com"
echo " www.example.com"
echo " api.example.com"
echo " assets.example.com"
echo " cloud.example.com"
echo " api.cloud.example.com"
echo ""
echo "Check the WALNUT README.md for more info and how to set up /etc/goldilocks/goldilocks.yml"
echo ""