2011-07-31 16:37:50 +00:00
#!/bin/sh
2018-07-28 21:23:39 +00:00
# minimum required node version
REQUIRED_NODE_MAJOR = 6
REQUIRED_NODE_MINOR = 9
# minimum required npm version
REQUIRED_NPM_MAJOR = 3
REQUIRED_NPM_MINOR = 10
require_minimal_version( ) {
PROGRAM_LABEL = " $1 "
VERSION_STRING = " $2 "
REQUIRED_MAJOR = " $3 "
REQUIRED_MINOR = " $4 "
2018-07-31 10:44:17 +00:00
# Flag -s (--only-delimited on GNU cut) ensures no string is returned
# when there is no match
DETECTED_MAJOR = $( echo $VERSION_STRING | cut -s -d "." -f 1)
DETECTED_MINOR = $( echo $VERSION_STRING | cut -s -d "." -f 2)
2018-07-28 21:23:39 +00:00
if [ -z " $DETECTED_MAJOR " ] ; then
printf 'Cannot extract %s major version from version string "%s"\n' " $PROGRAM_LABEL " " $VERSION_STRING " >& 2
exit 1
fi
if [ -z " $DETECTED_MINOR " ] ; then
printf 'Cannot extract %s minor version from version string "%s"\n' " $PROGRAM_LABEL " " $VERSION_STRING " >& 2
exit 1
fi
case " $DETECTED_MAJOR " in
'' | *[ !0-9] *)
printf '%s major version from "%s" is not a number. Detected: "%s"\n' " $PROGRAM_LABEL " " $VERSION_STRING " " $DETECTED_MAJOR " >& 2
exit 1
; ;
esac
case " $DETECTED_MINOR " in
'' | *[ !0-9] *)
printf '%s minor version from "%s" is not a number. Detected: "%s"\n' " $PROGRAM_LABEL " " $VERSION_STRING " " $DETECTED_MINOR " >& 2
exit 1
esac
if [ " $DETECTED_MAJOR " -lt " $REQUIRED_MAJOR " ] || ( [ " $DETECTED_MAJOR " -eq " $REQUIRED_MAJOR " ] && [ " $DETECTED_MINOR " -lt " $REQUIRED_MINOR " ] ) ; then
printf 'Your %s version "%s" is too old. %s %d.%d.x or higher is required.\n' " $PROGRAM_LABEL " " $VERSION_STRING " " $PROGRAM_LABEL " " $REQUIRED_MAJOR " " $REQUIRED_MINOR " >& 2
exit 1
fi
}
2011-07-27 13:37:12 +00:00
#Move to the folder where ep-lite is installed
2011-08-03 21:08:27 +00:00
cd ` dirname $0 `
2011-07-27 13:37:12 +00:00
#Was this script started in the bin folder? if yes move out
if [ -d "../bin" ] ; then
cd "../"
fi
2012-11-07 11:51:51 +00:00
#Is gnu-grep (ggrep) installed on SunOS (Solaris)
if [ $( uname) = "SunOS" ] ; then
2015-01-21 12:18:38 +00:00
hash ggrep > /dev/null 2>& 1 || {
2012-11-07 11:51:51 +00:00
echo "Please install ggrep (pkg install gnu-grep)" >& 2
2015-01-21 12:18:38 +00:00
exit 1
2012-11-07 11:51:51 +00:00
}
fi
2013-11-12 09:58:22 +00:00
#Is curl installed?
2015-01-21 12:18:38 +00:00
hash curl > /dev/null 2>& 1 || {
2011-08-09 09:54:55 +00:00
echo "Please install curl" >& 2
2015-01-21 12:18:38 +00:00
exit 1
2011-07-27 13:37:12 +00:00
}
#Is node installed?
2017-09-14 11:33:27 +00:00
#Not checking io.js, default installation creates a symbolic link to node
2015-01-21 12:18:38 +00:00
hash node > /dev/null 2>& 1 || {
2017-09-14 11:33:27 +00:00
echo "Please install node.js ( https://nodejs.org )" >& 2
2015-01-21 12:18:38 +00:00
exit 1
2011-07-27 13:37:12 +00:00
}
#Is npm installed?
2015-01-21 12:18:38 +00:00
hash npm > /dev/null 2>& 1 || {
2017-09-14 11:33:27 +00:00
echo "Please install npm ( https://npmjs.org )" >& 2
2015-01-21 12:18:38 +00:00
exit 1
2011-07-27 13:37:12 +00:00
}
2017-09-14 11:33:27 +00:00
#Check npm version
2018-07-28 21:23:39 +00:00
NPM_VERSION_STRING = $( npm --version)
require_minimal_version "npm" " $NPM_VERSION_STRING " " $REQUIRED_NPM_MAJOR " " $REQUIRED_NPM_MINOR "
2011-08-11 14:09:05 +00:00
2017-09-14 11:33:27 +00:00
#Check node version
2018-07-28 21:23:39 +00:00
NODE_VERSION_STRING = $( node --version)
NODE_VERSION_STRING = ${ NODE_VERSION_STRING # "v" }
require_minimal_version "nodejs" " $NODE_VERSION_STRING " " $REQUIRED_NODE_MAJOR " " $REQUIRED_NODE_MINOR "
2012-01-26 11:55:54 +00:00
2012-02-21 19:20:45 +00:00
#Get the name of the settings file
settings = "settings.json"
a = '' ;
for arg in $* ; do
if [ " $a " = "--settings" ] || [ " $a " = "-s" ] ; then settings = $arg ; fi
a = $arg
done
2017-09-14 11:33:27 +00:00
#Does a $settings exist? if not copy the template
2012-02-21 19:20:45 +00:00
if [ ! -f $settings ] ; then
echo " Copy the settings template to $settings ... "
2012-11-07 11:51:51 +00:00
cp settings.json.template $settings || exit 1
2011-07-27 13:37:12 +00:00
fi
2013-02-10 03:17:04 +00:00
echo "Ensure that all dependencies are up to date... If this is the first time you have run Etherpad please be patient."
2012-02-26 12:31:47 +00:00
(
mkdir -p node_modules
cd node_modules
2012-02-26 12:54:32 +00:00
[ -e ep_etherpad-lite ] || ln -s ../src ep_etherpad-lite
cd ep_etherpad-lite
2018-07-14 15:54:26 +00:00
npm install --no-save --loglevel warn
2015-01-21 12:18:38 +00:00
) || {
2011-08-09 10:14:09 +00:00
rm -rf node_modules
2015-01-21 12:18:38 +00:00
exit 1
2011-08-09 10:14:09 +00:00
}
2011-07-27 13:37:12 +00:00
echo "Ensure jQuery is downloaded and up to date..."
DOWNLOAD_JQUERY = "true"
2013-02-10 01:55:50 +00:00
NEEDED_VERSION = "1.9.1"
2012-02-26 12:31:47 +00:00
if [ -f "src/static/js/jquery.js" ] ; then
2012-11-16 21:12:04 +00:00
if [ $( uname) = "SunOS" ] ; then
2015-01-08 11:54:08 +00:00
VERSION = $( head -n 3 src/static/js/jquery.js | ggrep -o "v[0-9]\.[0-9]\(\.[0-9]\)\?" )
2012-11-07 11:51:51 +00:00
else
2015-01-08 11:54:08 +00:00
VERSION = $( head -n 3 src/static/js/jquery.js | grep -o "v[0-9]\.[0-9]\(\.[0-9]\)\?" )
2012-11-07 11:51:51 +00:00
fi
2011-07-27 13:37:12 +00:00
if [ ${ VERSION #v } = $NEEDED_VERSION ] ; then
DOWNLOAD_JQUERY = "false"
fi
fi
if [ $DOWNLOAD_JQUERY = "true" ] ; then
2016-07-23 14:59:47 +00:00
curl -lo src/static/js/jquery.js https://code.jquery.com/jquery-$NEEDED_VERSION .js || exit 1
2011-07-27 13:37:12 +00:00
fi
#Remove all minified data to force node creating it new
2015-04-04 15:30:41 +00:00
echo "Clearing minified cache..."
2011-07-27 13:37:12 +00:00
rm -f var/minified*
exit 0