Compare commits
9 commits
4069de095a
...
c1867d1ce3
Author | SHA1 | Date | |
---|---|---|---|
c1867d1ce3 | |||
8ac0da99fe | |||
Cayo Puigdefabregas | 71e06b13a4 | ||
Cayo Puigdefabregas | 82f93a9446 | ||
Cayo Puigdefabregas | b1136e3dd8 | ||
af780b1247 | |||
da7b78eae3 | |||
e8b1d62290 | |||
3e5e151bef |
4
Makefile
4
Makefile
|
@ -44,6 +44,10 @@ boot_iso_uefi_secureboot:
|
|||
-drive file=deploy/iso/workbench_debug.iso,cache=none,if=virtio,format=raw,index=0,media=disk \
|
||||
-boot menu=on
|
||||
|
||||
es_gen:
|
||||
$(MAKE) es_gen_po
|
||||
$(MAKE) es_gen_mo
|
||||
|
||||
es_gen_po:
|
||||
cp locale/es/LC_MESSAGES/messages.po locale/es/LC_MESSAGES/messages.pot.bak
|
||||
pygettext3 -p locale/es/LC_MESSAGES/ workbench-script.py
|
||||
|
|
|
@ -199,12 +199,12 @@ create_persistence_partition() {
|
|||
mkdir -p "${tmp_rw_mount}"
|
||||
${SUDO} mount "$(pwd)/${rw_img_path}" "${tmp_rw_mount}"
|
||||
${SUDO} mkdir -p "${tmp_rw_mount}"
|
||||
if [ -f "settings.ini" ]; then
|
||||
${SUDO} cp -v settings.ini "${tmp_rw_mount}/settings.ini"
|
||||
else
|
||||
echo "ERROR: settings.ini does not exist yet, cannot read config from there. You can take inspiration with file settings.ini.example"
|
||||
exit 1
|
||||
if [ ! -f "settings.ini" ]; then
|
||||
${SUDO} cp -v settings.ini.example settings.ini
|
||||
echo "WARNING: settings.ini was not there, settings.ini.example was copied, this only happens once"
|
||||
fi
|
||||
${SUDO} cp -v settings.ini "${tmp_rw_mount}/settings.ini"
|
||||
|
||||
${SUDO} umount "${tmp_rw_mount}"
|
||||
|
||||
uuid="$(blkid "${rw_img_path}" | awk '{ print $3; }')"
|
||||
|
@ -280,7 +280,7 @@ if [ "\${nfs_host}" ]; then
|
|||
mount --bind /run/live/medium /mnt
|
||||
# debian live nfs path is readonly, do a trick
|
||||
# to make snapshots subdir readwrite
|
||||
mount \${nfs_host}:/snapshots /run/live/medium/snapshots
|
||||
mount -v \${nfs_host}:/snapshots /run/live/medium/snapshots
|
||||
# reload mounts on systemd
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
|
|
Binary file not shown.
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2024-10-15 21:15+0200\n"
|
||||
"POT-Creation-Date: 2024-11-08 18:25+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -17,19 +17,19 @@ msgstr ""
|
|||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Content-Transfer-Encoding: 8bit\n"
|
||||
|
||||
#: workbench-script.py:48 workbench-script.py:53
|
||||
#: workbench-script.py:49 workbench-script.py:54
|
||||
msgid "Running command `%s`"
|
||||
msgstr "Ejecutando comando `%s`"
|
||||
|
||||
#: workbench-script.py:284
|
||||
#: workbench-script.py:279
|
||||
msgid "Created snapshots directory at '%s'"
|
||||
msgstr "Creado directorio de snapshots en '%s'"
|
||||
|
||||
#: workbench-script.py:287
|
||||
#: workbench-script.py:282
|
||||
msgid "Snapshot written in path '%s'"
|
||||
msgstr "Snapshot escrito en ruta '%s'"
|
||||
|
||||
#: workbench-script.py:290
|
||||
#: workbench-script.py:285
|
||||
msgid ""
|
||||
"Attempting to save file in actual path. Reason: Failed to write in snapshots "
|
||||
"directory:\n"
|
||||
|
@ -39,11 +39,11 @@ msgstr ""
|
|||
"escribir en el directorio de snapshots:\n"
|
||||
" %s."
|
||||
|
||||
#: workbench-script.py:297
|
||||
#: workbench-script.py:292
|
||||
msgid "Snapshot written in fallback path '%s'"
|
||||
msgstr "Snapshot escrito en ruta alternativa '%s'"
|
||||
|
||||
#: workbench-script.py:299
|
||||
#: workbench-script.py:294
|
||||
msgid ""
|
||||
"Could not save snapshot locally. Reason: Failed to write in fallback path:\n"
|
||||
" %s"
|
||||
|
@ -52,49 +52,53 @@ msgstr ""
|
|||
"alternativa:\n"
|
||||
" %s"
|
||||
|
||||
#: workbench-script.py:316
|
||||
#: workbench-script.py:317
|
||||
msgid "Snapshot successfully sent to '%s'"
|
||||
msgstr "Snapshot enviado con éxito a '%s'"
|
||||
|
||||
#: workbench-script.py:331
|
||||
#: workbench-script.py:335
|
||||
msgid "Snapshot %s could not be sent to URL '%s'"
|
||||
msgstr "Snapshot %s no se pudo enviar a la URL '%s'"
|
||||
|
||||
#: workbench-script.py:338
|
||||
msgid ""
|
||||
"Snapshot not remotely sent to URL '%s'. Do you have internet? Is your server "
|
||||
"up & running? Is the url token authorized?\n"
|
||||
"Snapshot %s not remotely sent to URL '%s'. Do you have internet? Is your "
|
||||
"server up & running? Is the url token authorized?\n"
|
||||
" %s"
|
||||
msgstr ""
|
||||
"Snapshot no enviado remotamente a la URL '%s'. Tienes internet? Está el "
|
||||
"Snapshot %s no enviado remotamente a la URL '%s'. Tienes internet? Está el "
|
||||
"servidor en marcha? Está autorizado el url token?\n"
|
||||
" %s"
|
||||
|
||||
#: workbench-script.py:342
|
||||
#: workbench-script.py:350
|
||||
msgid "Found config file in path: %s."
|
||||
msgstr "Encontrado fichero de configuración en ruta: %s."
|
||||
|
||||
#: workbench-script.py:353
|
||||
#: workbench-script.py:361
|
||||
msgid "Config file '%s' not found. Using default values."
|
||||
msgstr ""
|
||||
"Fichero de configuración '%s' no encontrado. Utilizando valores por defecto."
|
||||
|
||||
#: workbench-script.py:373
|
||||
#: workbench-script.py:379
|
||||
msgid "workbench-script.py [-h] [--config CONFIG]"
|
||||
msgstr ""
|
||||
|
||||
#: workbench-script.py:374
|
||||
#: workbench-script.py:380
|
||||
msgid "Optional config loader for workbench."
|
||||
msgstr "Cargador opcional de configuración para workbench"
|
||||
|
||||
#: workbench-script.py:377
|
||||
#: workbench-script.py:383
|
||||
msgid ""
|
||||
"path to the config file. Defaults to 'settings.ini' in the current directory."
|
||||
msgstr ""
|
||||
"ruta al fichero de configuración. Por defecto es 'settings.ini' en el "
|
||||
"directorio actual"
|
||||
|
||||
#: workbench-script.py:410
|
||||
#: workbench-script.py:416
|
||||
msgid "START"
|
||||
msgstr "INICIO"
|
||||
|
||||
#: workbench-script.py:423
|
||||
#: workbench-script.py:430
|
||||
msgid ""
|
||||
"This script must be run as root. Collected data will be incomplete or "
|
||||
"unusable"
|
||||
|
@ -102,6 +106,6 @@ msgstr ""
|
|||
"Es conveniente que este script sea ejecutado como administrador (root). Los "
|
||||
"datos recopilados serán incompletos o no usables."
|
||||
|
||||
#: workbench-script.py:441
|
||||
#: workbench-script.py:448
|
||||
msgid "END"
|
||||
msgstr "FIN"
|
||||
|
|
|
@ -37,7 +37,7 @@ backup_file() {
|
|||
|
||||
if [ -f "${target}" ]; then
|
||||
if ! grep -q 'we should do a backup' "${target}"; then
|
||||
${SUDO} cp -a "${target}" "${target}-bak_${ts}"
|
||||
${SUDO} cp -v -a "${target}" "${target}-bak_${ts}"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ END
|
|||
|
||||
if [ ! -f "${nfs_path}/settings.ini" ]; then
|
||||
if [ -f "settings.ini" ]; then
|
||||
${SUDO} cp settings.ini "${nfs_path}/settings.ini"
|
||||
${SUDO} cp -v settings.ini "${nfs_path}/settings.ini"
|
||||
else
|
||||
echo "ERROR: $(pwd)/settings.ini does not exist yet, cannot read config from there. You can take inspiration with file $(pwd)/settings.ini.example"
|
||||
exit 1
|
||||
|
@ -110,8 +110,12 @@ install_netboot() {
|
|||
${SUDO} cp -fv "${PXE_DIR}/../iso/staging/live/vmlinuz" "${tftp_path}/"
|
||||
${SUDO} cp -fv "${PXE_DIR}/../iso/staging/live/initrd" "${tftp_path}/"
|
||||
|
||||
${SUDO} cp /usr/lib/syslinux/memdisk "${tftp_path}/"
|
||||
${SUDO} cp /usr/lib/syslinux/modules/bios/* "${tftp_path}/"
|
||||
${SUDO} cp -v /usr/lib/syslinux/memdisk "${tftp_path}/"
|
||||
${SUDO} cp -v /usr/lib/syslinux/modules/bios/* "${tftp_path}/"
|
||||
if [ ! -f ./pxe-menu.cfg ]; then
|
||||
${SUDO} cp -v ./pxe-menu.cfg.example pxe-menu.cfg
|
||||
echo "WARNING: pxe-menu.cfg was not there, pxe-menu.cfg.example was copied, this only happens once"
|
||||
fi
|
||||
envsubst < ./pxe-menu.cfg | ${SUDO} tee "${tftp_path}/pxelinux.cfg/default"
|
||||
fi
|
||||
|
||||
|
@ -128,11 +132,10 @@ init_config() {
|
|||
|
||||
PXE_DIR="$(pwd)"
|
||||
|
||||
if [ -f ./.env ]; then
|
||||
. ./.env
|
||||
else
|
||||
echo "PXE: WARNING: $(pwd)/.env does not exist yet, cannot read config from there. You can take inspiration with file $(pwd)/.env.example"
|
||||
if [ ! -f ./.env ]; then
|
||||
echo "WARNING: .env was not there, .env.example was copied, this only happens once"
|
||||
fi
|
||||
. ./.env
|
||||
VERSION_CODENAME="${VERSION_CODENAME:-bookworm}"
|
||||
tftp_path="${tftp_path:-/srv/pxe-tftp}"
|
||||
# vars used in envsubst require to be exported:
|
||||
|
|
|
@ -6,6 +6,7 @@ import uuid
|
|||
import hashlib
|
||||
import argparse
|
||||
import configparser
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
import gettext
|
||||
|
@ -16,6 +17,7 @@ from datetime import datetime
|
|||
|
||||
|
||||
## Legacy Functions ##
|
||||
|
||||
def convert_to_legacy_snapshot(snapshot):
|
||||
snapshot["sid"] = str(uuid.uuid4()).split("-")[0]
|
||||
snapshot["software"] = "workbench-script"
|
||||
|
@ -25,7 +27,6 @@ def convert_to_legacy_snapshot(snapshot):
|
|||
snapshot["timestamp"] = snapshot["timestamp"].replace(" ", "T")
|
||||
snapshot["data"]["smart"] = snapshot["data"]["disks"]
|
||||
snapshot["data"].pop("disks")
|
||||
snapshot.pop("code")
|
||||
snapshot.pop("erase")
|
||||
|
||||
## End Legacy Functions ##
|
||||
|
@ -54,11 +55,6 @@ def exec_cmd_erase(cmd):
|
|||
return ''
|
||||
# return os.popen(cmd).read()
|
||||
|
||||
|
||||
def gen_code():
|
||||
uid = str(uuid.uuid4()).encode('utf-8')
|
||||
return hashlib.shake_256(uid).hexdigest(3)
|
||||
|
||||
## End Utility functions ##
|
||||
|
||||
|
||||
|
@ -66,7 +62,6 @@ SNAPSHOT_BASE = {
|
|||
'timestamp': str(datetime.now()),
|
||||
'type': 'Snapshot',
|
||||
'uuid': str(uuid.uuid4()),
|
||||
'code': gen_code(),
|
||||
'software': "workbench-script",
|
||||
'version': "0.0.1",
|
||||
'data': {},
|
||||
|
@ -300,7 +295,13 @@ def save_snapshot_in_disk(snapshot, path):
|
|||
|
||||
# TODO sanitize url, if url is like this, it fails
|
||||
# url = 'http://127.0.0.1:8000/api/snapshot/'
|
||||
def send_snapshot_to_devicehub(snapshot, token, url):
|
||||
def send_snapshot_to_devicehub(snapshot, token, url, legacy):
|
||||
url_components = urllib.parse.urlparse(url)
|
||||
ev_path = "evidence/{}".format(snapshot["uuid"])
|
||||
components = (url_components.schema, url_components.netloc, ev_path, '', '', '')
|
||||
ev_url = urllib.parse.urlunparse(components)
|
||||
# apt install qrencode
|
||||
|
||||
headers = {
|
||||
"Authorization": f"Bearer {token}",
|
||||
"Content-Type": "application/json"
|
||||
|
@ -314,21 +315,28 @@ def send_snapshot_to_devicehub(snapshot, token, url):
|
|||
|
||||
if 200 <= status_code < 300:
|
||||
logger.info(_("Snapshot successfully sent to '%s'"), url)
|
||||
|
||||
try:
|
||||
response = json.loads(response_text)
|
||||
if response.get('url'):
|
||||
# apt install qrencode
|
||||
qr = "echo {} | qrencode -t ANSI".format(response['url'])
|
||||
if legacy:
|
||||
try:
|
||||
response = json.loads(response_text)
|
||||
if response.get('url'):
|
||||
# apt install qrencode
|
||||
qr = "echo {} | qrencode -t ANSI".format(response['url'])
|
||||
print(exec_cmd(qr))
|
||||
print("url: {}".format(response['url']))
|
||||
if response.get("dhid"):
|
||||
print("dhid: {}".format(response['dhid']))
|
||||
except Exception:
|
||||
logger.error(response_text)
|
||||
else:
|
||||
qr = "echo {} | qrencode -t ANSI".format(ev_url)
|
||||
print(exec_cmd(qr))
|
||||
print("url: {}".format(response['url']))
|
||||
if response.get("dhid"):
|
||||
print("dhid: {}".format(response['dhid']))
|
||||
except Exception:
|
||||
logger.error(response_text)
|
||||
print(f"url: {ev_url}")
|
||||
else:
|
||||
logger.error(_("Snapshot %s could not be sent to URL '%s'"), snapshot["uuid"], url)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(_("Snapshot not remotely sent to URL '%s'. Do you have internet? Is your server up & running? Is the url token authorized?\n %s"), url, e)
|
||||
logger.error(_("Snapshot %s not remotely sent to URL '%s'. Do you have internet? Is your server up & running? Is the url token authorized?\n %s"), snapshot["uuid"], url, e)
|
||||
|
||||
|
||||
def load_config(config_file="settings.ini"):
|
||||
"""
|
||||
|
@ -414,6 +422,7 @@ def main():
|
|||
config_file = args.config
|
||||
|
||||
config = load_config(config_file)
|
||||
legacy = config.get("legacy")
|
||||
|
||||
# TODO show warning if non root, means data is not complete
|
||||
# if annotate as potentially invalid snapshot (pending the new API to be done)
|
||||
|
@ -428,13 +437,13 @@ def main():
|
|||
elif config['erase'] and not config.get("legacy"):
|
||||
snapshot['erase'] = gen_erase(all_disks, config['erase'])
|
||||
|
||||
if config.get("legacy"):
|
||||
if legacy:
|
||||
convert_to_legacy_snapshot(snapshot)
|
||||
|
||||
save_snapshot_in_disk(snapshot, config['path'])
|
||||
|
||||
if config['url']:
|
||||
send_snapshot_to_devicehub(snapshot, config['token'], config['url'])
|
||||
send_snapshot_to_devicehub(snapshot, config['token'], config['url'], legacy)
|
||||
|
||||
logger.info(_("END"))
|
||||
|
||||
|
|
Loading…
Reference in a new issue