From e38422c8a0ba60efb21935327bde0f2d5d36a4c9 Mon Sep 17 00:00:00 2001 From: boltgolt Date: Wed, 2 Jan 2019 22:57:00 +0100 Subject: [PATCH] Installer fixes --- debian/control | 2 +- debian/postinst | 45 +++++++++++++++++++++++++++------------- src/dlib-data/install.sh | 10 +++++++++ 3 files changed, 42 insertions(+), 15 deletions(-) create mode 100755 src/dlib-data/install.sh diff --git a/debian/control b/debian/control index 457d11d..128a891 100644 --- a/debian/control +++ b/debian/control @@ -9,7 +9,7 @@ Vcs-Git: https://github.com/boltgolt/howdy Package: howdy Homepage: https://github.com/boltgolt/howdy Architecture: all -Depends: ${misc:Depends}, curl|wget, python3-pip, python3-dev, python3-setuptools, libpam-python, fswebcam, libopencv-dev, python3-opencv, cmake, streamer +Depends: ${misc:Depends}, curl|wget, python3-pip, python3-dev, python3-setuptools, libpam-python, fswebcam, libopencv-dev, cmake, streamer Recommends: libatlas-base-dev | libopenblas-dev | liblapack-dev Suggests: nvidia-cuda-dev (>= 7.5) Description: Howdy: Windows Hello style authentication for Linux. diff --git a/debian/postinst b/debian/postinst index 86b524a..91afe47 100755 --- a/debian/postinst +++ b/debian/postinst @@ -72,7 +72,7 @@ if not os.path.exists("/tmp/howdy_picked_device"): try: newConf.set(section, key, value) # Add a new section where needed - except configparser.NoSectionError as e: + except configparser.NoSectionError: newConf.add_section(section) newConf.set(section, key, value) @@ -94,21 +94,25 @@ os.unlink("/tmp/howdy_picked_device") log("Upgrading pip to the latest version") # Update pip -handleStatus(sc(["pip3", "install", "--upgrade", "pip"])) +handleStatus(sc(["pip3", "install", "--no-cache-dir", "--upgrade", "pip"])) -dlib_archive = '/tmp/dlib_latest.tar.gz' +log("Downloading and unpacking data files") + +handleStatus(subprocess.call(["./install.sh"], shell=True, cwd="/lib/security/howdy/dlib-data")) log('Downloading dlib') +dlib_archive = '/tmp/v19.16.tar.gz' + loader = which('curl') LOADER_CMD = None if loader: - LOADER_CMD = [loader, '--silent', '--retry', '5', '--location', '--output'] + LOADER_CMD = [loader, '--retry', '5', '--location', '--output'] else: loader = which('wget') - LOADER_CMD = [loader, '--quiet', '--tries', '5', '--output-document'] + LOADER_CMD = [loader, '--tries', '5', '--output-document'] -cmd = LOADER_CMD + [dlib_archive, 'https://api.github.com/repos/davisking/dlib/tarball/latest'] +cmd = LOADER_CMD + [dlib_archive, 'https://github.com/davisking/dlib/archive/v19.16.tar.gz'] handleStatus(sc(cmd)) @@ -119,13 +123,14 @@ excludes = re.compile( '(docs|examples|python_examples)|' 'tools/(archive|convert_dlib_nets_to_caffe|htmlify|imglab|python/test|visual_studio_natvis))' ) + with tarfile.open(dlib_archive) as tf: for item in tf: # tarball contains directory davisking-dlib-, so peek into archive for the name if not DLIB_DIR: - DLIB_DIR = item.name + DLIB_DIR = "/tmp/" + item.name - # extract only files sufficent for building + # extract only files sufficient for building if not excludes.match(item.name): tf.extract(item, '/tmp') @@ -134,7 +139,8 @@ os.unlink(dlib_archive) log("Building dlib") # Start the build -cmd = ["python3", "setup.py", "install"] +cmd = ["sudo", "python3", "setup.py", "install"] +cuda_used = False flags = '' with open('/proc/cpuinfo') as info: @@ -152,11 +158,19 @@ elif 'sse3' in flags: elif 'sse2' in flags: cmd += ["--yes", "USE_SSE2_INSTRUCTIONS"] -sp = subprocess.run(cmd, cwd=DLIB_DIR, stderr=subprocess.STDOUT) -handleStatus(sp.returncode) +try: + sp = subprocess.Popen(cmd, cwd=DLIB_DIR, stdout=subprocess.PIPE) +except subprocess.CalledProcessError: + print("Error while building dlib") + raise -# simple check for CUDA -cuda_used = 'DLIB WILL USE CUDA' in sp.stdout +while sp.poll() is None: + line = sp.stdout.readline().decode("utf-8") + + if 'DLIB WILL USE CUDA' in line: + cuda_used = True + + print(line, end='') log("Cleaning up dlib") @@ -164,8 +178,11 @@ log("Cleaning up dlib") del sp rmtree(DLIB_DIR) -log("Temporary dlib files removed") +print("Temporary dlib files removed") +log("Installing OpenCV") + +handleStatus(subprocess.call(["pip3", "install", "--no-cache-dir", "opencv-python"])) log("Configuring howdy") diff --git a/src/dlib-data/install.sh b/src/dlib-data/install.sh new file mode 100755 index 0000000..b966d9f --- /dev/null +++ b/src/dlib-data/install.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +# Download the archives +wget https://github.com/davisking/dlib-models/raw/master/dlib_face_recognition_resnet_model_v1.dat.bz2 +wget https://github.com/davisking/dlib-models/raw/master/mmod_human_face_detector.dat.bz2 +wget https://github.com/davisking/dlib-models/raw/master/shape_predictor_5_face_landmarks.dat.bz2 + +# Uncompress the data files and delete the original archive +echo "Unpacking..." +bzip2 -d *.bz2