-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
84 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,91 @@ | ||
#!/bin/bash | ||
distro=$1 | ||
if [ -z ${distro+x} ]; then | ||
distro='master' | ||
#!/usr/bin/env bash | ||
|
||
progname=$(basename $0) | ||
|
||
tmpd=$(mktemp -d) | ||
trap "rm -rf $tmpd" EXIT | ||
|
||
set -e | ||
|
||
err() { | ||
echo "$progname: ""$@" >&2 | ||
} | ||
|
||
usage() { | ||
echo "usage: $progname: -b <git branch> -d </full/path/to/shinobi>" | ||
echo "" | ||
echo "-b dev|master the branch of Shinobi you want to use" | ||
echo "-d /opt/Shinobi the full path to your Shinobi checkout" | ||
echo "-h show help" | ||
} | ||
|
||
if [[ $# -eq 0 ]]; then | ||
usage >&2 | ||
exit 99 | ||
fi | ||
rm -rf $distro master_temp | ||
wget https://github.com/ShinobiCCTV/Shinobi/tarball/$distro | ||
mkdir master_temp | ||
tar -xzf $distro -C master_temp --strip-components=1 | ||
|
||
while getopts hd:b: opt; do | ||
case $opt in | ||
b) | ||
case $OPTARG in | ||
dev|master) | ||
distro=$OPTARG | ||
;; | ||
*) | ||
err "branch must be dev or master" | ||
exit 1 | ||
;; | ||
esac | ||
;; | ||
d) | ||
if [[ ! -w $OPTARG ]]; then | ||
err "$OPTARG is not writable" | ||
exit 2 | ||
fi | ||
shinobi=$OPTARG | ||
;; | ||
h) | ||
usage | ||
exit 0 | ||
;; | ||
*) | ||
usage | ||
exit 10 | ||
;; | ||
esac | ||
done | ||
shift $((OPTIND-1)) | ||
|
||
if [[ -z $distro ]]; then | ||
err "-b <branch> is required" | ||
usage >&2 | ||
exit 99 | ||
fi | ||
|
||
if [[ -z $shinobi ]]; then | ||
err "-d </full/path/to/shinobi/checkout> is required" | ||
usage >&2 | ||
exit 99 | ||
fi | ||
|
||
# download source | ||
wget -O $tmpd/$distro https://github.com/ShinobiCCTV/Shinobi/tarball/$distro | ||
|
||
# stop existing processes | ||
cd $shinobi | ||
pm2 stop camera.js | ||
pm2 stop cron.js | ||
pm2 kill | ||
mv master_temp/UPDATE.sh UPDATE.sh | ||
chmod +x UPDATE.sh | ||
sed -i 's/\r//' UPDATE.sh | ||
mv master_temp/languages languages | ||
mv master_temp/definitions definitions | ||
mv master_temp/web web | ||
mv master_temp/LICENSE LICENSE | ||
mv master_temp/COPYING COPYING | ||
mv master_temp/package.json package.json | ||
mv master_temp/camera.js camera.js | ||
mv master_temp/cron.js cron.js | ||
mv master_temp/plugins/motion/shinobi-motion.js plugins/motion/shinobi-motion.js | ||
mv master_temp/plugins/opencv/shinobi-opencv.js plugins/motion/shinobi-opencv.js | ||
|
||
# unpack new files to shinobi directory | ||
tar -xzf $tmpd/$distro --strip-components=1 | ||
|
||
# update nodejs modules and start shinobi processes | ||
npm install | ||
rm -rf $distro master_temp | ||
pm2 start camera.js | ||
pm2 start cron.js | ||
if [ ! -f plugins/motion/conf.json ]; then | ||
pm2 start plugins/motion/shinobi-motion.js | ||
fi | ||
if [[ ! -f plugins/motion/conf.json ]]; then | ||
pm2 start plugins/motion/shinobi-motion.js | ||
fi | ||
|
||
exit 0 |