Merge update_grub into client
This commit is contained in:
@@ -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':
|
||||
|
||||
@@ -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"
|
||||
@@ -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)
|
||||
|
||||
@@ -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" \
|
||||
|
||||
@@ -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<volume_id>.+)$', 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()
|
||||
|
||||
Reference in New Issue
Block a user