Merge update_grub into client
This commit is contained in:
@@ -6,10 +6,16 @@ import json
|
|||||||
import os
|
import os
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
import update_grub
|
||||||
from ws4py.client import threadedclient
|
from ws4py.client import threadedclient
|
||||||
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='iconograph fetcher')
|
parser = argparse.ArgumentParser(description='iconograph fetcher')
|
||||||
|
parser.add_argument(
|
||||||
|
'--boot-dir',
|
||||||
|
dest='boot_dir',
|
||||||
|
action='store',
|
||||||
|
required=True)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--config',
|
'--config',
|
||||||
dest='config',
|
dest='config',
|
||||||
@@ -95,6 +101,11 @@ class Client(threadedclient.WebSocketClient):
|
|||||||
fetch.Fetch()
|
fetch.Fetch()
|
||||||
fetch.DeleteOldImages()
|
fetch.DeleteOldImages()
|
||||||
|
|
||||||
|
update = update_grub.GrubUpdater(
|
||||||
|
FLAGS.image_dir,
|
||||||
|
FLAGS.boot_dir)
|
||||||
|
update.Update()
|
||||||
|
|
||||||
def received_message(self, msg):
|
def received_message(self, msg):
|
||||||
parsed = json.loads(msg.data.decode('utf8'))
|
parsed = json.loads(msg.data.decode('utf8'))
|
||||||
if parsed['type'] == 'image_types':
|
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
|
return
|
||||||
|
|
||||||
url = '%s/%s' % (self._base_url, filename)
|
url = '%s/%s' % (self._base_url, filename)
|
||||||
print('Fetching:', url)
|
print('Fetching:', url, flush=True)
|
||||||
resp = self._session.get(url, stream=True)
|
resp = self._session.get(url, stream=True)
|
||||||
|
|
||||||
hash_obj = hashlib.sha256()
|
hash_obj = hashlib.sha256()
|
||||||
@@ -155,7 +155,7 @@ class Fetcher(object):
|
|||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
print('Changing current link to:', filename)
|
print('Changing current link to:', filename, flush=True)
|
||||||
temp_path = tempfile.mktemp(dir=self._image_dir)
|
temp_path = tempfile.mktemp(dir=self._image_dir)
|
||||||
os.symlink(filename, temp_path)
|
os.symlink(filename, temp_path)
|
||||||
os.rename(temp_path, current_path)
|
os.rename(temp_path, current_path)
|
||||||
@@ -177,6 +177,6 @@ class Fetcher(object):
|
|||||||
images.append((int(match.group('timestamp')), filename))
|
images.append((int(match.group('timestamp')), filename))
|
||||||
images.sort(reverse=True)
|
images.sort(reverse=True)
|
||||||
for timestamp, filename in images[max_images:]:
|
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)
|
path = os.path.join(self._image_dir, filename)
|
||||||
os.unlink(path)
|
os.unlink(path)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ exec 2>&1
|
|||||||
BASE=$(dirname $0)
|
BASE=$(dirname $0)
|
||||||
|
|
||||||
exec "${BASE}/client.py" \
|
exec "${BASE}/client.py" \
|
||||||
|
--boot-dir="/isodevice" \
|
||||||
--image-dir="/isodevice/iconograph" \
|
--image-dir="/isodevice/iconograph" \
|
||||||
--ca-cert="/icon/config/ca.image.cert.pem" \
|
--ca-cert="/icon/config/ca.image.cert.pem" \
|
||||||
--https-ca-cert="/icon/config/ca.www.cert.pem" \
|
--https-ca-cert="/icon/config/ca.www.cert.pem" \
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import argparse
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import string
|
import string
|
||||||
@@ -8,20 +7,6 @@ import subprocess
|
|||||||
import sys
|
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):
|
class GrubUpdater(object):
|
||||||
|
|
||||||
_VOLUME_ID_REGEX = re.compile(b'^Volume id: (?P<volume_id>.+)$', re.MULTILINE)
|
_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],
|
'hotkey': self._HOTKEYS[i],
|
||||||
'volume_id': self._GetVolumeID(os.path.join(self._image_dir, filename)),
|
'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