Lintian cleanups and package modernization

- Remove pre/post scripts, use dh-systemd to handle installing service
- Instead of trying to dpkg-divert /etc/dnsmasq.conf, install our config
to /etc/dnsmasq.d

Change-Id: I0053c49a7d666f397d55d0b6fbd43c0f2afef279
diff --git a/debian/control b/debian/control
index 112ca3c..2f99d12 100644
--- a/debian/control
+++ b/debian/control
@@ -1,13 +1,15 @@
 Source: usb-gadget
 Section: devel
 Priority: optional
-Maintainer: AIY Team <coral-support@google.com>
-Build-Depends: debhelper (>= 9)
+Maintainer: Coral <coral-support@google.com>
+Build-Depends: debhelper (>= 10), dh-systemd
 Standards-Version: 3.9.8
-Homepage: https://aiyprojects.withgoogle.com/
+Homepage: https://coral.withgoogle.com/
 
 Package: usb-gadget
-Version: 0.0.1
 Architecture: all
 Depends: ${shlibs:Depends}, ${misc:Depends}, dnsmasq, openssh-server, network-manager
 Description: Sets up USB gadget ethernet and TTY for a given USB port
+ Using sysfs, configures USB gadget to expose a
+ serial console using ACM, and an Ethernet
+ device using ECM.
diff --git a/debian/copyright b/debian/copyright
index 1b82c7a..5514d2f 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,6 +1,6 @@
 Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
 Upstream-Name: usb-gadget
-Source: <https://aiyprojects.googlesource.com/>
+Source: https://coral.googlesource.com/
 
 Files: *
 Copyright: Copyright 2018 Google, LLC <coral-support@google.com>
diff --git a/debian/postinst b/debian/postinst
deleted file mode 100644
index b1502ba..0000000
--- a/debian/postinst
+++ /dev/null
@@ -1,40 +0,0 @@
-#!/bin/sh
-# postinst script for usb-gadget
-#
-# see: dh_installdeb(1)
-
-set -e
-
-# summary of how this script can be called:
-#        * <postinst> `configure' <most-recently-configured-version>
-#        * <old-postinst> `abort-upgrade' <new version>
-#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
-#          <new-version>
-#        * <postinst> `abort-remove'
-#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
-#          <failed-install-package> <version> `removing'
-#          <conflicting-package> <version>
-# for details, see https://www.debian.org/doc/debian-policy/ or
-# the debian-policy package
-
-case "$1" in
-    configure)
-      systemctl daemon-reload || true
-      systemctl enable usb-gadget || true
-    ;;
-
-    abort-upgrade|abort-remove|abort-deconfigure)
-    ;;
-
-    *)
-        echo "postinst called with unknown argument \`$1'" >&2
-        exit 1
-    ;;
-esac
-
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/preinst b/debian/preinst
deleted file mode 100644
index 27d176a..0000000
--- a/debian/preinst
+++ /dev/null
@@ -1,41 +0,0 @@
-#!/bin/sh
-# preinst script for test
-#
-# see: dh_installdeb(1)
-
-set -e
-
-# summary of how this script can be called:
-#        * <new-preinst> `install'
-#        * <new-preinst> `install' <old-version>
-#        * <new-preinst> `upgrade' <old-version>
-#        * <old-preinst> `abort-upgrade' <new-version>
-# for details, see https://www.debian.org/doc/debian-policy/ or
-# the debian-policy package
-
-divert_dnsmaq_conf() {
-  dpkg-divert --package usb-gadget --add --rename \
-      --divert /etc/dnsmasq.conf.orig /etc/dnsmasq.conf
-}
-
-
-case "$1" in
-    install|upgrade)
-    	divert_dnsmaq_conf
-    ;;
-
-    abort-upgrade)
-    ;;
-
-    *)
-        echo "preinst called with unknown argument \`$1'" >&2
-        exit 1
-    ;;
-esac
-
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/prerm b/debian/prerm
deleted file mode 100644
index c0d9355..0000000
--- a/debian/prerm
+++ /dev/null
@@ -1,47 +0,0 @@
-#!/bin/sh
-# prerm script for usb-gadget
-#
-# see: dh_installdeb(1)
-
-set -e
-
-# summary of how this script can be called:
-#        * <prerm> `remove'
-#        * <old-prerm> `upgrade' <new-version>
-#        * <new-prerm> `failed-upgrade' <old-version>
-#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
-#        * <deconfigured's-prerm> `deconfigure' `in-favour'
-#          <package-being-installed> <version> `removing'
-#          <conflicting-package> <version>
-# for details, see https://www.debian.org/doc/debian-policy/ or
-# the debian-policy package
-
-revert_dnsmasq_conf () {
-  rm /etc/dnsmasq.conf
-  dpkg-divert --package usb-gadget --remove --rename \
-    --divert /etc/dnsmasq.conf.orig /etc/dnsmasq.conf
-}
-
-case "$1" in
-    remove|upgrade|deconfigure)
-      revert_dnsmasq_conf
-      systemctl disable usb-gadget || true
-      systemctl stop usb-gadget || true
-      systemctl restart dnsmasq || true
-    ;;
-
-    failed-upgrade)
-    ;;
-
-    *)
-        echo "prerm called with unknown argument \`$1'" >&2
-        exit 1
-    ;;
-esac
-
-# dh_installdeb will replace this with shell code automatically
-# generated by other debhelper scripts.
-
-#DEBHELPER#
-
-exit 0
diff --git a/debian/rules b/debian/rules
index 747699d..15979e6 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,27 +1,18 @@
 #!/usr/bin/make -f
 # See debhelper(7) (uncomment to enable)
 # output every command that modifies files on the build system.
-export DH_VERBOSE = 1
-
-
-# see FEATURE AREAS in dpkg-buildflags(1)
-#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
-
-# see ENVIRONMENT in dpkg-buildflags(1)
-# package maintainers to append CFLAGS
-#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
-# package maintainers to append LDFLAGS
-#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
-
+# export DH_VERBOSE = 1
 
 %:
-	dh $@
+	dh $@ --with systemd
 
 override_dh_systemd_enable:
 	dh_systemd_enable --name=usb-gadget
 
-# dh_make generated override targets
-# This is example for Cmake (See https://bugs.debian.org/641051 )
-#override_dh_auto_configure:
-#	dh_auto_configure -- #	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
-
+# From man dh_installinit:
+# In compat 10 or earlier: If a package only ships a systemd service file and no sysvinit script
+# is provided, you may want to exclude the call to dh_installinit for that package (e.g. via -N).
+# Otherwise, you may get warnings from lintian about init.d scripts not being included in the
+# package.
+override_dh_installinit:
+	true
diff --git a/debian/usb-gadget.service b/debian/usb-gadget.service
index df3e375..50e82f1 100644
--- a/debian/usb-gadget.service
+++ b/debian/usb-gadget.service
@@ -1,5 +1,6 @@
 [Unit]
 Description=USB Gadget
+Before=network.target
 
 [Service]
 Type=oneshot
diff --git a/etc/dnsmasq.d/02-usb-gadget b/etc/dnsmasq.d/02-usb-gadget
new file mode 100644
index 0000000..b4dc38f
--- /dev/null
+++ b/etc/dnsmasq.d/02-usb-gadget
@@ -0,0 +1,7 @@
+# Configuration file for dnsmasq.
+port=0
+interface=usb0
+domain=local
+dhcp-range=192.168.100.50,192.168.100.99,255.255.255.0,12h
+dhcp-lease-max=150
+log-dhcp
diff --git a/usr/bin/usb-gadget-start.sh b/usr/bin/usb-gadget-start.sh
index 5ec05a9..c788e45 100755
--- a/usr/bin/usb-gadget-start.sh
+++ b/usr/bin/usb-gadget-start.sh
@@ -50,18 +50,3 @@
 fi
 
 nmcli con up id usb0
-
-# Setup the dhcp server and ssh
-
-cat << EOF > /etc/dnsmasq.conf
-# Configuration file for dnsmasq.
-port=0
-interface=usb0
-domain=local
-dhcp-range=192.168.100.50,192.168.100.99,255.255.255.0,12h
-dhcp-lease-max=150
-log-dhcp
-EOF
-
-systemctl restart dnsmasq
-systemctl restart sshd