From 02b7f46dd2cbfab36b8343b49ecbf997dc759979 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 10 May 2016 00:23:04 +0000 Subject: [PATCH] Merge update_grub into client --- client/client.py | 11 +++++++++++ client/fetch_and_update.sh | 30 ------------------------------ client/fetcher.py | 6 +++--- client/run | 1 + client/update_grub.py | 24 ------------------------ 5 files changed, 15 insertions(+), 57 deletions(-) delete mode 100755 client/fetch_and_update.sh diff --git a/client/client.py b/client/client.py index b2d7d84..2a4cd72 100755 --- a/client/client.py +++ b/client/client.py @@ -6,10 +6,16 @@ import json import os import socket import time +import update_grub from ws4py.client import threadedclient parser = argparse.ArgumentParser(description='iconograph fetcher') +parser.add_argument( + '--boot-dir', + dest='boot_dir', + action='store', + required=True) parser.add_argument( '--config', dest='config', @@ -95,6 +101,11 @@ class Client(threadedclient.WebSocketClient): fetch.Fetch() fetch.DeleteOldImages() + update = update_grub.GrubUpdater( + FLAGS.image_dir, + FLAGS.boot_dir) + update.Update() + def received_message(self, msg): parsed = json.loads(msg.data.decode('utf8')) if parsed['type'] == 'image_types': diff --git a/client/fetch_and_update.sh b/client/fetch_and_update.sh deleted file mode 100755 index 0c11f92..0000000 --- a/client/fetch_and_update.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -set -ex - -BASE=$(dirname $0) - -IMAGES="/isodevice/iconograph" -mkdir -p "${IMAGES}" - -BOOT="/isodevice" - -FETCHER_FLAGS="$(cat /icon/config/fetcher.flags)" -if test -f /icon/config/update_grub.flags; then - UPDATE_GRUB_FLAGS="$(cat /icon/config/update_grub.flags)" -fi -CA_CERT="/icon/config/ca.image.cert.pem" - -HTTPS_CLIENT_KEY="/systemid/$(hostname).www.key.pem" -HTTPS_CLIENT_CERT="/systemid/$(hostname).www.cert.pem" -HTTPS_CA_CERT="/icon/config/ca.www.cert.pem" - -if test -e "${HTTPS_CLIENT_KEY}" -a -e "${HTTPS_CLIENT_CERT}"; then - HTTPS_CLIENT_FLAGS="--https-client-cert=${HTTPS_CLIENT_CERT} --https-client-key=${HTTPS_CLIENT_KEY}" -fi -if test -e "${HTTPS_CA_CERT}"; then - HTTPS_CA_FLAGS="--https-ca-cert=${HTTPS_CA_CERT}" -fi - -"${BASE}/fetcher.py" --image-dir="${IMAGES}" --ca-cert="${CA_CERT}" ${FETCHER_FLAGS} ${HTTPS_CLIENT_FLAGS} ${HTTPS_CA_FLAGS} -"${BASE}/update_grub.py" --image-dir="${IMAGES}" --boot-dir="${BOOT}" ${UPDATE_GRUB_FLAGS} > "${BOOT}/grub/grub.cfg.tmp" && mv "${BOOT}/grub/grub.cfg.tmp" "${BOOT}/grub/grub.cfg" diff --git a/client/fetcher.py b/client/fetcher.py index 50f194d..02033b6 100755 --- a/client/fetcher.py +++ b/client/fetcher.py @@ -126,7 +126,7 @@ class Fetcher(object): return url = '%s/%s' % (self._base_url, filename) - print('Fetching:', url) + print('Fetching:', url, flush=True) resp = self._session.get(url, stream=True) hash_obj = hashlib.sha256() @@ -155,7 +155,7 @@ class Fetcher(object): except FileNotFoundError: pass - print('Changing current link to:', filename) + print('Changing current link to:', filename, flush=True) temp_path = tempfile.mktemp(dir=self._image_dir) os.symlink(filename, temp_path) os.rename(temp_path, current_path) @@ -177,6 +177,6 @@ class Fetcher(object): images.append((int(match.group('timestamp')), filename)) images.sort(reverse=True) for timestamp, filename in images[max_images:]: - print('Deleting old image:', filename) + print('Deleting old image:', filename, flush=True) path = os.path.join(self._image_dir, filename) os.unlink(path) diff --git a/client/run b/client/run index 322e3c1..e6afc7f 100755 --- a/client/run +++ b/client/run @@ -7,6 +7,7 @@ exec 2>&1 BASE=$(dirname $0) exec "${BASE}/client.py" \ + --boot-dir="/isodevice" \ --image-dir="/isodevice/iconograph" \ --ca-cert="/icon/config/ca.image.cert.pem" \ --https-ca-cert="/icon/config/ca.www.cert.pem" \ diff --git a/client/update_grub.py b/client/update_grub.py index 28501e9..b2ffa81 100755 --- a/client/update_grub.py +++ b/client/update_grub.py @@ -1,6 +1,5 @@ #!/usr/bin/python3 -import argparse import os import re import string @@ -8,20 +7,6 @@ import subprocess import sys -parser = argparse.ArgumentParser(description='iconograph update_grub') -parser.add_argument( - '--boot-dir', - dest='boot_dir', - action='store', - required=True) -parser.add_argument( - '--image-dir', - dest='image_dir', - action='store', - required=True) -FLAGS = parser.parse_args() - - class GrubUpdater(object): _VOLUME_ID_REGEX = re.compile(b'^Volume id: (?P.+)$', re.MULTILINE) @@ -76,12 +61,3 @@ menuentry "%(image_filename)s (%(volume_id)s)" --hotkey=%(hotkey)s { 'hotkey': self._HOTKEYS[i], 'volume_id': self._GetVolumeID(os.path.join(self._image_dir, filename)), }) - - -def main(): - updater = GrubUpdater(FLAGS.image_dir, FLAGS.boot_dir) - updater.Update() - - -if __name__ == '__main__': - main()