2015-02-20 21:25:49 +00:00
|
|
|
#!/bin/bash -e
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
cd `dirname $0`/..
|
|
|
|
SOURCE=`pwd`
|
|
|
|
|
|
|
|
uname="$(uname -a)"
|
|
|
|
os=
|
|
|
|
arch="$(uname -m)"
|
|
|
|
case "$uname" in
|
|
|
|
Linux\ *) os=linux ;;
|
|
|
|
Darwin\ *) os=darwin ;;
|
|
|
|
SunOS\ *) os=sunos ;;
|
|
|
|
FreeBSD\ *) os=freebsd ;;
|
|
|
|
CYGWIN*) os=windows ;;
|
|
|
|
MINGW*) os=windows ;;
|
|
|
|
esac
|
|
|
|
case "$uname" in
|
|
|
|
*x86_64*) arch=x64 ;;
|
|
|
|
*i*86*) arch=x86 ;;
|
|
|
|
*armv6l*) arch=arm-pi ;;
|
2015-02-15 22:15:57 +00:00
|
|
|
*armv7l*) arch=arm-pi ;;
|
2015-02-10 19:41:24 +00:00
|
|
|
esac
|
|
|
|
|
2015-02-20 21:25:49 +00:00
|
|
|
red=$'\e[01;31m'
|
|
|
|
green=$'\e[01;32m'
|
|
|
|
yellow=$'\e[01;33m'
|
|
|
|
blue=$'\e[01;34m'
|
|
|
|
magenta=$'\e[01;35m'
|
|
|
|
resetColor=$'\e[0m'
|
2015-02-10 19:41:24 +00:00
|
|
|
|
2015-04-13 18:34:01 +00:00
|
|
|
NO_PULL=
|
|
|
|
NO_GLOBAL_INSTALL=
|
|
|
|
FORCE=
|
2015-02-10 19:41:24 +00:00
|
|
|
|
2015-02-20 21:25:49 +00:00
|
|
|
updatePackage() {
|
2015-02-10 19:41:24 +00:00
|
|
|
name=$1
|
|
|
|
|
|
|
|
REPO=https://github.com/c9/$name
|
2015-02-20 21:25:49 +00:00
|
|
|
echo "${green}checking out ${resetColor}$REPO"
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
if ! [[ -d ./plugins/$name ]]; then
|
|
|
|
mkdir -p ./plugins/$name
|
|
|
|
fi
|
|
|
|
|
|
|
|
pushd ./plugins/$name
|
|
|
|
if ! [[ -d .git ]]; then
|
|
|
|
git init
|
|
|
|
# git remote rm origin || true
|
|
|
|
git remote add origin $REPO
|
|
|
|
fi
|
|
|
|
|
2015-02-20 21:25:49 +00:00
|
|
|
version=`"$NODE" -e 'console.log((require("../../package.json").c9plugins["'$name'"].substr(1) || "origin/master"))'`;
|
2015-02-10 19:41:24 +00:00
|
|
|
rev=`git rev-parse --revs-only $version`
|
|
|
|
|
|
|
|
if [ "$rev" == "" ]; then
|
|
|
|
git fetch origin
|
|
|
|
fi
|
|
|
|
|
|
|
|
status=`git status --porcelain --untracked-files=no`
|
|
|
|
if [ "$status" == "" ]; then
|
|
|
|
git reset $version --hard
|
|
|
|
else
|
2015-02-20 21:25:49 +00:00
|
|
|
echo "${yellow}$name ${red}contains uncommited changes.${yellow} Skipping...${resetColor}"
|
2015-02-10 19:41:24 +00:00
|
|
|
fi
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
2015-02-20 21:25:49 +00:00
|
|
|
updateAllPackages() {
|
2015-04-13 18:34:01 +00:00
|
|
|
c9packages=`"$NODE" -e 'console.log(Object.keys(require("./package.json").c9plugins).join(" "))'`;
|
2015-02-20 21:25:49 +00:00
|
|
|
count=${#c9packages[@]}
|
|
|
|
i=0
|
|
|
|
for m in ${c9packages[@]}; do echo $m;
|
|
|
|
i=$(($i + 1))
|
|
|
|
echo "updating plugin ${blue}$i${resetColor} of ${blue}$count${resetColor}"
|
2015-03-11 12:07:16 +00:00
|
|
|
updatePackage $m
|
2015-02-20 21:25:49 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
updateNodeModules() {
|
|
|
|
echo "${magenta}--- Running npm install --------------------------------------------${resetColor}"
|
|
|
|
safeInstall(){
|
2015-04-13 18:34:01 +00:00
|
|
|
deps=`"$NODE" -e 'console.log(Object.keys(require("./package.json").dependencies).join(" "))'`;
|
2015-02-20 21:25:49 +00:00
|
|
|
for m in $deps; do echo $m;
|
|
|
|
"$NPM" install --loglevel warn $m || true
|
|
|
|
done
|
|
|
|
}
|
|
|
|
"$NPM" install || safeInstall
|
|
|
|
echo "${magenta}--------------------------------------------------------------------${resetColor}"
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCore() {
|
2015-04-13 18:34:01 +00:00
|
|
|
if [ "$NO_PULL" ]; then
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# without this git merge fails on windows
|
|
|
|
mv ./scripts/install-sdk.sh ./scripts/.install-sdk-tmp.sh
|
|
|
|
cp ./scripts/.install-sdk-tmp.sh ./scripts/install-sdk.sh
|
|
|
|
git checkout -- ./scripts/install-sdk.sh
|
|
|
|
|
2015-02-20 21:25:49 +00:00
|
|
|
git remote add c9 https://github.com/c9/core 2> /dev/null || true
|
|
|
|
git fetch c9
|
|
|
|
git merge c9/master --ff-only || \
|
|
|
|
echo "${yellow}Couldn't automatically update sdk core ${resetColor}"
|
2015-04-13 18:34:01 +00:00
|
|
|
|
|
|
|
## TODO use fetched script?
|
|
|
|
# oldScript="$(cat ./scripts/install-sdk.sh)"
|
|
|
|
# newScript="$(cat ./scripts/install-sdk.sh)"
|
|
|
|
# if ! [ "$oldScript" == "$newScript" ]; then
|
|
|
|
# ./scripts/install-sdk.sh --no-pull
|
|
|
|
# exit
|
|
|
|
# fi
|
2015-02-20 21:25:49 +00:00
|
|
|
}
|
|
|
|
|
2015-04-13 18:34:01 +00:00
|
|
|
|
|
|
|
|
2015-02-20 21:25:49 +00:00
|
|
|
installGlobalDeps() {
|
2015-04-09 16:19:58 +00:00
|
|
|
if ! [[ -f ~/.c9/installed ]] && ! [[ $os == "windows" ]]; then
|
2015-02-20 21:25:49 +00:00
|
|
|
curl https://raw.githubusercontent.com/c9/install/master/install.sh | bash
|
|
|
|
fi
|
|
|
|
}
|
2015-02-10 19:41:24 +00:00
|
|
|
|
2015-02-20 21:25:49 +00:00
|
|
|
############################################################################
|
|
|
|
NPM=npm
|
|
|
|
NODE=node
|
2015-02-10 19:41:24 +00:00
|
|
|
|
2015-02-20 21:25:49 +00:00
|
|
|
updateCore || true
|
2015-02-10 19:41:24 +00:00
|
|
|
|
2015-02-20 21:25:49 +00:00
|
|
|
installGlobalDeps
|
|
|
|
updateAllPackages
|
|
|
|
updateNodeModules
|
2015-02-10 19:41:24 +00:00
|
|
|
|
|
|
|
echo "Success!"
|
2015-02-20 21:25:49 +00:00
|
|
|
echo "run '${yellow}node server.js -p 8181 -l 0.0.0.0 -a :${resetColor}' to launch Cloud9"
|