2016-06-26 11:53:19 +00:00
|
|
|
#!/bin/bash -e
|
|
|
|
|
|
|
|
set -e
|
|
|
|
has() {
|
|
|
|
type "$1" > /dev/null 2>&1
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
|
|
|
if has "curl"; then
|
|
|
|
DOWNLOAD="curl -L "
|
|
|
|
elif has "wget"; then
|
|
|
|
DOWNLOAD="wget -O - "
|
|
|
|
else
|
|
|
|
echo "Error: you need curl or wget to proceed" >&2;
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-08-28 03:11:57 +00:00
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
SOURCE=$(pwd)
|
2016-06-26 11:53:19 +00:00
|
|
|
|
|
|
|
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 ;;
|
|
|
|
MSYS_NT*) os=windows ;;
|
|
|
|
esac
|
|
|
|
case "$uname" in
|
|
|
|
*x86_64*) arch=x64 ;;
|
|
|
|
*i*86*) arch=x86 ;;
|
|
|
|
*armv6l*) arch=arm-pi ;;
|
|
|
|
*armv7l*) arch=arm-pi ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
red=$'\e[01;31m'
|
|
|
|
green=$'\e[01;32m'
|
|
|
|
yellow=$'\e[01;33m'
|
|
|
|
blue=$'\e[01;34m'
|
|
|
|
magenta=$'\e[01;35m'
|
|
|
|
resetColor=$'\e[0m'
|
|
|
|
|
2016-08-28 03:11:57 +00:00
|
|
|
# NO_PULL=
|
|
|
|
# NO_GLOBAL_INSTALL=
|
|
|
|
# FORCE=
|
2016-06-26 11:53:19 +00:00
|
|
|
|
|
|
|
updatePackage() {
|
|
|
|
name=$1
|
2016-08-28 03:11:57 +00:00
|
|
|
cd "$SOURCE"
|
2016-06-26 11:53:19 +00:00
|
|
|
|
|
|
|
REPO=https://github.com/c9/$name
|
|
|
|
echo "${green}checking out ${resetColor}$REPO"
|
|
|
|
|
2016-08-28 03:11:57 +00:00
|
|
|
if ! [[ -d ./plugins/"$name" ]]; then
|
|
|
|
mkdir -p ./plugins/"$name"
|
2016-06-26 11:53:19 +00:00
|
|
|
fi
|
|
|
|
|
2016-08-28 03:11:57 +00:00
|
|
|
pushd ./plugins/"$name"
|
2016-06-26 11:53:19 +00:00
|
|
|
if ! [[ -d .git ]]; then
|
|
|
|
git init
|
|
|
|
# git remote rm origin || true
|
2016-08-28 03:11:57 +00:00
|
|
|
git remote add origin "$REPO"
|
2016-06-26 11:53:19 +00:00
|
|
|
fi
|
|
|
|
|
2016-08-28 03:11:57 +00:00
|
|
|
version=$("$NODE" -e 'console.log((require("../../package.json").c9plugins["'"$name"'"].substr(1) || "origin/master"))');
|
|
|
|
rev=$(git rev-parse --revs-only "$version")
|
2016-06-26 11:53:19 +00:00
|
|
|
|
|
|
|
if [ "$rev" == "" ]; then
|
|
|
|
git fetch origin
|
|
|
|
fi
|
|
|
|
|
2016-08-28 03:11:57 +00:00
|
|
|
status=$(git status --porcelain --untracked-files=no)
|
|
|
|
if [ "$status" == "" ] || [ "$FORCE" == "1" ]; then
|
|
|
|
git reset "$version" --hard
|
2016-06-26 11:53:19 +00:00
|
|
|
else
|
|
|
|
echo "${yellow}$name ${red}contains uncommited changes.${yellow} Skipping...${resetColor}"
|
|
|
|
fi
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
updateAllPackages() {
|
2016-08-30 15:18:25 +00:00
|
|
|
c9packages=$("$NODE" -p 'Object.keys(require("./package.json").c9plugins).join(" ")');
|
|
|
|
count=$("$NODE" -p 'Object.keys(require("./package.json").c9plugins).length')
|
2016-06-26 11:53:19 +00:00
|
|
|
i=0
|
2016-08-30 15:18:25 +00:00
|
|
|
for m in ${c9packages[@]}; do
|
2016-08-28 03:11:57 +00:00
|
|
|
echo "$m"
|
|
|
|
i=$((i + 1))
|
2016-06-26 11:53:19 +00:00
|
|
|
echo "updating plugin ${blue}$i${resetColor} of ${blue}$count${resetColor}"
|
2016-08-28 03:11:57 +00:00
|
|
|
updatePackage "$m" || updatePackage "$m"
|
2016-06-26 11:53:19 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
updateNodeModules() {
|
|
|
|
echo "${magenta}--- Running npm install --------------------------------------------${resetColor}"
|
|
|
|
safeInstall(){
|
2016-08-28 03:11:57 +00:00
|
|
|
deps=$("$NODE" -e 'console.log(Object.keys(require("./package.json").dependencies).join(" "))');
|
2016-08-30 15:18:25 +00:00
|
|
|
for m in ${deps[@]}; do echo "$m";
|
2016-08-28 03:11:57 +00:00
|
|
|
"$NPM" install --loglevel warn "$m"
|
2016-06-26 11:53:19 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
"$NPM" install || safeInstall
|
|
|
|
echo "${magenta}--------------------------------------------------------------------${resetColor}"
|
|
|
|
}
|
|
|
|
|
|
|
|
updateCore() {
|
|
|
|
if [ "$NO_PULL" ]; then
|
|
|
|
return 0;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# without this git merge fails on windows
|
|
|
|
mv ./scripts/install-sdk.sh './scripts/.#install-sdk-tmp.sh'
|
2016-08-30 15:18:25 +00:00
|
|
|
rm -f ./scripts/.install-sdk-tmp.sh
|
2016-06-26 11:53:19 +00:00
|
|
|
cp './scripts/.#install-sdk-tmp.sh' ./scripts/install-sdk.sh
|
|
|
|
git checkout -- ./scripts/install-sdk.sh
|
|
|
|
|
|
|
|
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}"
|
|
|
|
|
|
|
|
## 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
installGlobalDeps() {
|
|
|
|
if ! [[ -f ~/.c9/installed ]]; then
|
|
|
|
if [[ $os == "windows" ]]; then
|
|
|
|
URL=https://raw.githubusercontent.com/cloud9ide/sdk-deps-win32
|
|
|
|
else
|
|
|
|
URL=https://raw.githubusercontent.com/c9/install
|
|
|
|
fi
|
|
|
|
$DOWNLOAD $URL/master/install.sh | bash
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
############################################################################
|
|
|
|
export C9_DIR="$HOME"/.c9
|
2016-08-28 03:11:57 +00:00
|
|
|
if ! [[ $(which npm) ]]; then
|
2016-06-26 11:53:19 +00:00
|
|
|
if [[ $os == "windows" ]]; then
|
|
|
|
export PATH="$C9_DIR:$C9_DIR/node_modules/.bin:$PATH"
|
|
|
|
else
|
|
|
|
export PATH="$C9_DIR/node/bin:$C9_DIR/node_modules/.bin:$PATH"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
NPM=npm
|
|
|
|
NODE=node
|
|
|
|
|
|
|
|
# cleanup build cache since c9.static doesn't do this automatically yet
|
|
|
|
rm -rf ./build/standalone
|
|
|
|
|
|
|
|
# pull the latest version
|
|
|
|
updateCore || true
|
|
|
|
|
|
|
|
installGlobalDeps
|
|
|
|
updateAllPackages
|
|
|
|
updateNodeModules
|
|
|
|
|
|
|
|
echo -e "c9.*\n.gitignore" > plugins/.gitignore
|
|
|
|
echo -e "nak\n.gitignore" > node_modules/.gitignore
|
|
|
|
|
|
|
|
echo "Success!"
|
|
|
|
|
|
|
|
echo "run '${yellow}node server.js -p 8080 -a :${resetColor}' to launch Cloud9"
|