Skip to content

Commit

Permalink
refactor upgrade script
Browse files Browse the repository at this point in the history
  • Loading branch information
sethlyons committed Mar 2, 2018
1 parent ad04e9e commit 147310e
Showing 1 changed file with 84 additions and 25 deletions.
109 changes: 84 additions & 25 deletions UPDATE.sh
100644 → 100755
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

0 comments on commit 147310e

Please sign in to comment.