diff --git a/extra/motioneye.rc-bsd b/extra/motioneye.rc-bsd new file mode 100644 index 000000000..caf1dc3db --- /dev/null +++ b/extra/motioneye.rc-bsd @@ -0,0 +1,46 @@ +#!/bin/sh + +# $FreeBSD$ +# +# PROVIDE: motioneye +# REQUIRE: LOGIN +# KEYWORD: shutdown +# +# Add the following line(s) to /etc/rc.conf to enable motioneye: +# +# motioneye_enable="YES" +# # optional +# motioneye_flags="-l startserver -c $motioneye_config" +# motioneye_user="root" +# motioneye_config="/usr/local/etc/motioneye/motioneye.conf" + +. /etc/rc.subr + +name=motioneye +rcvar=motioneye_enable +load_rc_config $name + +# Set defaults +motioneye_enable=${motioneye_enable:-"NO"} +motioneye_config=${motioneye_config:-"/usr/local/etc/motioneye/motioneye.conf"} +motioneye_flags=${motioneye_flags:-"startserver -l -c $motioneye_config"} +motioneye_user=${motioneye_user:-"root"} + +pidfile=/var/run/motioneye.pid +command_interpreter=/usr/local/bin/python2.7 +command=/usr/local/bin/meyectl + +start_cmd=motioneye_start +stop_postcmd=motioneye_cleanup + +motioneye_start() { + echo "Starting motioneye." + /usr/sbin/daemon -cf -p ${pidfile} -u ${motioneye_user} ${command} ${motioneye_flags} +} + +motioneye_cleanup() { + [ -f ${pidfile} ] && rm ${pidfile} +} + +run_rc_command "$1" + diff --git a/motioneye/diskctl.py b/motioneye/diskctl.py index 52c7a34f6..8f3bc94e4 100644 --- a/motioneye/diskctl.py +++ b/motioneye/diskctl.py @@ -21,8 +21,48 @@ import subprocess import utils - def _list_mounts(): + if os.path.exists('/proc/mounts'): + return _list_mounts_proc_mounts() + else: # Use mount command + return _list_mounts_mount() + +def _list_mounts_mount(): + try: + output = subprocess.check_output(['mount'], stderr=utils.DEV_NULL) + + except Exception as e: + logging.error('failed to list mounts using "mount": %s' % e, exc_info=True) + + return [] + + mounts = [] + # Line should be something like (on FreeBSD): + # target on mountpoint (fstype, option1, option2...) + # On Linux it would look different, but linux has /proc/mounts so we should not get here + # So regex out the target, mountpoint, fstype and whatever options + regex = re.compile('(\S+)\s+on\s+(\S+)\s+\((\w+),\s+([\S\s]+).*\)') + for line in output.splitlines(): + line = line.strip() + if not line: + continue + parts = regex.split(line) + + target = parts[1] + mount_point = parts[2] + fstype = parts[3] + opts = parts[4] + + mounts.append({ + 'target': target, + 'mount_point': mount_point, + 'fstype': fstype, + 'opts': opts + }) + return mounts + + +def _list_mounts_proc_mounts(): logging.debug('listing mounts...') seen_targets = set() @@ -68,10 +108,20 @@ def _list_mounts(): def _list_disks(): if os.path.exists('/dev/disk/by-id/'): return _list_disks_dev_by_id() - - else: # fall back to fdisk -l + if os.path.exists('/proc/mounts'): return _list_disks_fdisk() + else: # fall back to gpart command - Linux should never get here + return _list_disks_gpart() + +def _list_disks_gpart(): + try: + output = subprocess.check_output(['gpart', 'status'], stderr=utils.DEV_NULL) + except Exception as e: + logging.error('failed to list disks using "gpart status": %s' % e, exc_info=True) + disks = [] + + return disks def _list_disks_dev_by_id(): logging.debug('listing disks using /dev/disk/by-id/') diff --git a/motioneye/scripts/relayevent.sh b/motioneye/scripts/relayevent.sh index 408daa3e9..06294be4c 100755 --- a/motioneye/scripts/relayevent.sh +++ b/motioneye/scripts/relayevent.sh @@ -29,7 +29,9 @@ filename="$4" uri="/_relay_event/?_username=$username&event=$event&motion_camera_id=$motion_camera_id" data="{\"filename\": \"$filename\"}" -signature=$(echo -n "POST:$uri:$data:$password" | sha1sum | cut -d ' ' -f 1) +# allow for sha1 usage as well as sha1sum +sha1=$(which sha1sum sha1) +signature=$(echo -n "POST:$uri:$data:$password" | $sha1 | cut -d ' ' -f 1) curl -s -S -m $timeout -H "Content-Type: application/json" -X POST "http://127.0.0.1:$port$uri&_signature=$signature" -d "$data" >/dev/null diff --git a/motioneye/update.py b/motioneye/update.py index ff8e68838..dcb66bba4 100644 --- a/motioneye/update.py +++ b/motioneye/update.py @@ -34,17 +34,23 @@ def get_os_version(): def _get_os_version_lsb_release(): - try: - output = subprocess.check_output('lsb_release -sri', shell=True) - lines = output.strip().split() - name, version = lines - if version.lower() == 'rolling': - version = '' + # check if it exists before calling to avoid log spam + rc = subprocess.call(['which', 'lsb_release']) + + if rc == 0: + try: + output = subprocess.check_output('lsb_release -sri', shell=True) + lines = output.strip().split() + name, version = lines + if version.lower() == 'rolling': + version = '' - return name, version + return name, version - except: - return _get_os_version_uname() + except: + return _get_os_version_uname() + else: + return _get_os_version_uname() def _get_os_version_uname():