From 563ce47520a4b96d7838d378b2f5153d2d5b608c Mon Sep 17 00:00:00 2001 From: Michael Cohen Date: Sat, 19 May 2018 21:45:14 +1000 Subject: [PATCH] Build debian package templates. --- Makefile | 5 ++ debian/changelog | 5 ++ debian/compat | 1 + debian/control | 13 +++ debian/copyright | 27 ++++++ debian/rules | 30 +++++++ debian/velociraptor.init | 164 ++++++++++++++++++++++++++++++++++ debian/velociraptor.postinst | 39 ++++++++ debian/velociraptor.preinst | 36 ++++++++ debian/velociraptor.service | 14 +++ debian/velociraptor.substvars | 3 + debian/velociraptor.upstart | 23 +++++ templates/.gitignore | 1 + 13 files changed, 361 insertions(+) create mode 100644 debian/changelog create mode 100644 debian/compat create mode 100644 debian/control create mode 100644 debian/copyright create mode 100755 debian/rules create mode 100644 debian/velociraptor.init create mode 100644 debian/velociraptor.postinst create mode 100644 debian/velociraptor.preinst create mode 100644 debian/velociraptor.service create mode 100644 debian/velociraptor.substvars create mode 100644 debian/velociraptor.upstart create mode 100644 templates/.gitignore diff --git a/Makefile b/Makefile index 7a1f90fd4b1..274761f3edb 100644 --- a/Makefile +++ b/Makefile @@ -1,2 +1,7 @@ test: go test ./... + +# Build templates for all supported operating systems. +build: + GOOS=linux GOARCH=amd64 go build -o debian/velociraptor/usr/lib/velociraptor/velociraptor ./bin/ + zip -r templates/velociraptor_linux_amd64.zip debian/ diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 00000000000..c37050ce043 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +velociraptor (0.1.0-1) unstable; urgency=low + + * Initial release + + -- velociraptor Sat, 19 May 2018 09:51:10 +0000 diff --git a/debian/compat b/debian/compat new file mode 100644 index 00000000000..7f8f011eb73 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 00000000000..fcc7a996768 --- /dev/null +++ b/debian/control @@ -0,0 +1,13 @@ +Source: velociraptor +Section: misc +Priority: extra +Maintainer: Velocidex Innovations +Build-Depends: debhelper (>= 7.0.0) +Standards-Version: 3.9.2 +Homepage: https://gitlab.com/velocidex/velociraptor + +Package: velociraptor +Architecture: any +Depends: lsb-base (>= 3.2-14) +Description: Velociraptor Response Client + The Velociraptor Response Client diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 00000000000..1e9afde2ace --- /dev/null +++ b/debian/copyright @@ -0,0 +1,27 @@ +Format: http://dep.debian.net/deps/dep5 +Upstream-Name: velociraptor +Source: https://gitlab.com/velocidex/velociraptor + +Files: * +Copyright: 2018 Velocidex Innovations +License: Apache-2.0 + +Files: debian/* +Copyright: 2018 Velocidex Innovations +License: Apache-2.0 + +License: Apache-2.0 + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + . + http://www.apache.org/licenses/LICENSE-2.0 + . + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + . + On Debian systems, the complete text of the Apache version 2.0 license + can be found in "/usr/share/common-licenses/Apache-2.0". diff --git a/debian/rules b/debian/rules new file mode 100755 index 00000000000..78655777a9e --- /dev/null +++ b/debian/rules @@ -0,0 +1,30 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +# export DH_VERBOSE=1 + +%: + dh $@ + +override_dh_clean: + # Nothing to do here, directory is already wiped and set up. + +override_dh_build: + # Nothing to do here, directory is already wiped and set up. + +override_dh_prep: + # Nothing to do here, directory is already wiped and set up. + +override_dh_link: + dh_link "/usr/lib/velociraptor/velociraptor" "/usr/sbin/velociraptor" + dh_link "/usr/lib/velociraptor/nanny.sh" "/usr/sbin/velociraptor.nanny" + +override_dh_builddeb: + # Older distros don't support xz so we use gzip instead. + dh_builddeb -- -Zgzip diff --git a/debian/velociraptor.init b/debian/velociraptor.init new file mode 100644 index 00000000000..05f2ec95a21 --- /dev/null +++ b/debian/velociraptor.init @@ -0,0 +1,164 @@ +#! /bin/sh +### BEGIN INIT INFO +# Provides: velociraptor_client +# Required-Start: $network $named $local_fs $syslog +# Required-Stop: $network $named $local_fs $syslog +# Should-Start: +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: velociraptor linux amd64 +### END INIT INFO + +PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" +DESC="velociraptor linux amd64" +NAME="velociraptor-client" +DAEMON="/usr/sbin/velociraptor" +DAEMON_ARGS="client" +PIDFILE="/var/run/${NAME}.pid" +SCRIPTNAME="/etc/init.d/${NAME}" + +[ -x "${DAEMON}" ] || exit 0 + +. /lib/init/vars.sh + +# Define various helper functions, needs lsb-base >= 3.2-14 +. /lib/lsb/init-functions + +# If upstart or systemd is here, exit and let it handle everything. +# The init_is_upstart requires lsb-base >= 4.1+Debian3, but we want to be able +# to run on older systems, so if it isn't present we do the check ourselves. +if type init_is_upstart >/dev/null 2>&1; then + log_daemon_msg "Upstart is present and should be used instead, doing nothing." + init_is_upstart && exit 0 +elif [ -x /sbin/initctl ] && /sbin/initctl version | /bin/grep -q upstart; then + log_daemon_msg "Upstart is present and should be used instead, doing nothing." + exit 0 +elif [ -x /bin/systemctl ]; then + log_daemon_msg "Systemd is present and should be used instead, doing nothing." + exit 0 +fi + +# Parentheses are escaped since they confuse config_lib.InterpolateValue + +do_start() { + start-stop-daemon --start \ + --quiet \ + --test \ + --make-pidfile \ + --pidfile ${PIDFILE} \ + --startas ${DAEMON} -- ${DAEMON_ARGS} || return 1 + + start-stop-daemon --start \ + --quiet \ + --background \ + --make-pidfile \ + --pidfile ${PIDFILE} \ + --startas ${DAEMON} -- ${DAEMON_ARGS} || return 2 +} + +do_stop() { + start-stop-daemon --stop \ + --quiet \ + --oknodo \ + --retry=TERM/30/KILL/5 \ + --pidfile ${PIDFILE} + + RETVAL="$?" + + [ "${RETVAL}" = 2 ] && return 2 + + rm -f ${PIDFILE} + + return "${RETVAL}" +} + +do_reload() { + start-stop-daemon --stop \ + --quiet \ + --pidfile ${PIDFILE} \ + --signal HUP + + return 0 +} + +case "$1" in + start) + [ "${VERBOSE}" != no ] && log_daemon_msg "Starting ${DESC}" "${NAME}" + + do_start + + case "$?" in + 0|1) + [ "${VERBOSE}" != no ] && log_end_msg 0 + ;; + + 2) + [ "${VERBOSE}" != no ] && log_end_msg 1 + ;; + esac + ;; + + stop) + [ "${VERBOSE}" != no ] && log_daemon_msg "Stopping ${DESC}" "${NAME}" + + do_stop + + case "$?" in + 0|1) + [ "${VERBOSE}" != no ] && log_end_msg 0 + ;; + + 2) + [ "${VERBOSE}" != no ] && log_end_msg 1 + ;; + esac + ;; + + status) + status_of_proc -p "${PIDFILE}" "${DAEMON}" "${NAME}" && exit 0 || exit $? + ;; + + reload|force-reload) + log_daemon_msg "Reloading ${DESC}" "${NAME}" + + do_reload + + log_end_msg $? + ;; + + restart) + log_daemon_msg "Restarting ${DESC}" "${NAME}" + + do_stop + + case "$?" in + 0|1) + sleep 1 + + do_start + + case "$?" in + 0) + log_end_msg 0 + ;; + + 1|2) + log_end_msg 1 + ;; + esac + ;; + + 2) + log_end_msg 1 + ;; + esac + ;; + + *) + echo "Usage: ${SCRIPTNAME} {start|stop|status|restart|force-reload|reload}" >&2 + + exit 3 + ;; +esac + +: diff --git a/debian/velociraptor.postinst b/debian/velociraptor.postinst new file mode 100644 index 00000000000..50fa4f9ffd1 --- /dev/null +++ b/debian/velociraptor.postinst @@ -0,0 +1,39 @@ +#!/bin/sh + +set -e + +NANNY="/usr/lib/velociraptor/nanny.sh" +DAEMON="/usr/lib/velociraptor/velociraptor" +DAEMON_ARGS="" + +# This package is designed to work on systems with init.d, upstart, and systemd. +case "$1" in + configure) + /bin/chmod +x "${NANNY}" + + if [ -x /sbin/initctl ] && /sbin/initctl version | /bin/grep -q upstart; then + # Early versions of upstart didn't support restarting a service that + # wasn't already running: + # https://bugs.launchpad.net/ubuntu/+source/upstart/+bug/430883 + /usr/sbin/service velociraptor stop 2>/dev/null || true + /usr/sbin/service velociraptor start 2>/dev/null + elif [ -x /bin/systemctl ]; then + # Systemd + /bin/systemctl enable velociraptor + /bin/systemctl restart velociraptor + elif [ -x "/etc/init.d/velociraptor" ]; then + update-rc.d velociraptor defaults >/dev/null + invoke-rc.d velociraptor start || exit $? + fi + ;; + + abort-upgrade|abort-remove|abort-deconfigure) + ;; + + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/debian/velociraptor.preinst b/debian/velociraptor.preinst new file mode 100644 index 00000000000..3bca831e34f --- /dev/null +++ b/debian/velociraptor.preinst @@ -0,0 +1,36 @@ +#!/bin/sh + +# Remove broken upstart init script links if this is an upgrade and they link to +# upstart-job. This fixes a problem where init scripts were wrongly linked to +# upstart-job, like this: +# +# /etc/init.d/[clientname] -> /lib/init/upstart-job + +# If this fires, it will trigger a dpkg 'config changed' prompt. This prompt can +# be avoided by using one of the dpkg --force-conf* options, --force-confnew is +# ideal but --force-confold will just leave the /etc/init.d/[clientname] script +# missing, which is OK on upstart systems. + +set -e + +case "$1" in + upgrade) + if [ "$(readlink /etc/init.d/velociraptor)" = "/lib/init/upstart-job" ]; then + # On precise+ we have dpkg-maintscript-helper, so use it. + if which dpkg-maintscript-helper >/dev/null 2>&1 && dpkg-maintscript-helper supports rm_conffile; then + dpkg-maintscript-helper rm_conffile /etc/init.d/velociraptor 3081~ velociraptor -- "$@" + update-rc.d velociraptor remove + else + rm -f /etc/init.d/velociraptor + update-rc.d velociraptor remove + fi + fi + ;; + + *) + ;; +esac + +#DEBHELPER# + +exit 0 diff --git a/debian/velociraptor.service b/debian/velociraptor.service new file mode 100644 index 00000000000..6ffcb6306cf --- /dev/null +++ b/debian/velociraptor.service @@ -0,0 +1,14 @@ +[Unit] +Description=Velociraptor linux amd64 +After=syslog.target network.target + +[Service] +Type=simple +Restart=always +RestartSec=120 +LimitNOFILE=20000 +Environment=LANG=en_US.UTF-8 +ExecStart=/usr/sbin/velociraptor client + +[Install] +WantedBy=multi-user.target diff --git a/debian/velociraptor.substvars b/debian/velociraptor.substvars new file mode 100644 index 00000000000..886ddcd3569 --- /dev/null +++ b/debian/velociraptor.substvars @@ -0,0 +1,3 @@ +misc:Depends=lsb-base (>= 4.1+Debian11ubuntu7) +misc:Pre-Depends= +shlibs:Depends=libc6 (>= 2.3.2) diff --git a/debian/velociraptor.upstart b/debian/velociraptor.upstart new file mode 100644 index 00000000000..38cc277d787 --- /dev/null +++ b/debian/velociraptor.upstart @@ -0,0 +1,23 @@ +# velociraptor linux amd64 client upstart file + +limit nofile 20000 20000 + +kill timeout 300 + +start on startup +start on runlevel [2345] +stop on runlevel [016] + +respawn + +env LANG=en_US.UTF-8 + +script + DAEMON="/usr/sbin/velociraptor.nanny" + DAEMON_ARGS="/usr/sbin/velociraptor client" + + [ -x "${DAEMON}" ] || exit 0 + + exec ${DAEMON} ${DAEMON_ARGS} + +end script diff --git a/templates/.gitignore b/templates/.gitignore new file mode 100644 index 00000000000..f59ec20aabf --- /dev/null +++ b/templates/.gitignore @@ -0,0 +1 @@ +* \ No newline at end of file