summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJannik Schönartz2020-07-28 18:24:11 +0200
committerJannik Schönartz2020-07-28 18:24:11 +0200
commitb5180b31b72e8038f901630c814cfa137b031320 (patch)
treec06e4f79336b74a8fe0293cb40b6128a67ba211e
parent[slx-splash] reactivate systemd messages if fbsplash fails (diff)
downloadsystemd-init-b5180b31b72e8038f901630c814cfa137b031320.tar.gz
systemd-init-b5180b31b72e8038f901630c814cfa137b031320.tar.xz
systemd-init-b5180b31b72e8038f901630c814cfa137b031320.zip
Create bas branch
Add bas registration hook module Add bas python module Upgrade busybox version Add README with stuff
-rw-r--r--README.md59
-rwxr-xr-xmodules.d/bas-python/module-setup.sh40
-rwxr-xr-xmodules.d/bas-python/scripts/00collect_hw_info_json.py63
-rwxr-xr-xmodules.d/bas-python/scripts/00reboot_script.sh6
-rwxr-xr-xmodules.d/bas-registration-hooks/module-setup.sh20
-rw-r--r--modules.d/bas-registration-hooks/scripts/00_execute_hooks32
-rw-r--r--modules.d/busybox/module-setup.sh2
7 files changed, 220 insertions, 2 deletions
diff --git a/README.md b/README.md
index 1333ed77..5af8fea3 100644
--- a/README.md
+++ b/README.md
@@ -1 +1,58 @@
-TODO
+# Dracut-BAS
+
+* Builded on `Ubuntu 20.04 LTS`
+* Used kernel `vmlinuz-5.4.0-42-generic`
+* Dracut Version `050`\
+https://github.com/dracutdevs/dracut
+
+
+Dracut build command
+```bash
+./dracut.sh --no-hostonly --force --local --modules "dracut-systemd systemd-initrd systemd busybox terminfo base bash kernel-modules slx-network shutdown bas-registration-hooks bas-python" initramfs-bas
+```
+
+---
+
+#### Default Dracut modules
+* systemd-initrd
+* systemd
+* terminfo
+* base
+* bash
+* kernel-modules
+* kernel-network-modules (dependency from slx-network)
+* shutdown
+
+---
+
+### SLX-Modules
+Needs to be linked in `dracut/modules.d/` e.g. `90<modulename>`\
+The smaller numbers overrides the bigger ones
+
+#### slx-network
+* unchanged
+
+#### busybox
+* Updated busybox to version `v1.32.0`\
+https://git.busybox.net/busybox/\
+`v1.33.0.git` was working as well
+* link to `00busybox` to override dracut's default busybox
+
+---
+
+### BAS-Modules
+Needs to be linked in `dracut/modules.d/` e.g. `90<modulename>`
+
+#### bas-registration-hooks
+Script for execution the registration hooks\
+Loops and pulls all bash scripts from the BAS until all scripts are finished or the next hook is an ipxe script
+* curl
+* dmidecode
+
+
+#### bas-python
+Better to be linked as `95bas-python`, so that `/opt`, `/usr/lib` and `/usr/local/lib/` already exists\
+Python script that collects hardware information and sends it to different backends (BAS, openslx, ...)
+* Python 3.8
+* Pip 3
+* dmiparser
diff --git a/modules.d/bas-python/module-setup.sh b/modules.d/bas-python/module-setup.sh
new file mode 100755
index 00000000..2cec109f
--- /dev/null
+++ b/modules.d/bas-python/module-setup.sh
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+
+check() {
+ for bin in python3 pip3; do
+ if ! hash "$bin" 2>&1 /dev/null; then
+ echo "Missing '$bin' please install it..."
+ return 1
+ fi
+ done
+ return 255
+}
+depends() {
+ :
+}
+install() {
+ # Not needed but for testing the scripts manual
+ mkdir -p "$initdir/opt/bas"
+ cp -r "$moddir/scripts" "$initdir/opt/bas/"
+
+ mkdir -p "$initdir/usr/lib"
+ cp -r "/usr/lib/python3" "$initdir/usr/lib/"
+ cp -r "/usr/lib/python3.8" "$initdir/usr/lib/"
+
+ mkdir -p "$initdir/usr/local/lib"
+ cp -r "/usr/local/lib/python3.8" "$initdir/usr/local/lib/"
+
+ mkdir -p "$initdir/usr/share"
+ cp -r "/usr/share/python-wheels" "$initdir/usr/share/python-wheels/"
+
+ mkdir -p "$initdir/etc/ssl/certs/"
+ cp "/etc/ssl/certs/ca-certificates.crt" "$initdir/etc/ssl/certs/"
+
+ inst_multiple python3 pip3
+
+ inst_hook pre-mount 00 "$moddir/scripts/00collect_hw_info_json.py"
+ # Call finish script instead of Switch Root
+ inst_hook cleanup 00 "$moddir/scripts/00reboot_script.sh"
+
+ return 0
+}
diff --git a/modules.d/bas-python/scripts/00collect_hw_info_json.py b/modules.d/bas-python/scripts/00collect_hw_info_json.py
new file mode 100755
index 00000000..7f57e9e2
--- /dev/null
+++ b/modules.d/bas-python/scripts/00collect_hw_info_json.py
@@ -0,0 +1,63 @@
+from dmiparser import DmiParser
+import json
+import subprocess
+import sys
+import argparse
+
+__debug = False
+
+# Run dmi command as subprocess and get the stdout
+def run_subprocess(_cmd):
+ global __debug
+
+ proc = subprocess.Popen(_cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
+ stdout, stderr = proc.communicate()
+ if __debug:
+ print(_cmd + ':')
+ print()
+ print('Errors:')
+ print(stderr.decode())
+ print()
+ if proc.returncode > 0:
+ print('Critical Error:')
+ print('Failed with error: ' + stderr.decode())
+ print()
+ return False
+ else:
+ return stdout.decode()
+
+def get_dmidecode():
+ _dmiraw = run_subprocess('dmidecode')
+ _dmiparsed = ''
+ if _dmiraw:
+ # Parse dmidecode
+ _dmiparsed = DmiParser(_dmiraw)
+ return str(_dmiparsed)
+ else:
+ return False
+
+def main():
+ global __debug
+
+ # Create and parse arguments
+ parser = argparse.ArgumentParser(description='Collects hardware data from different tools and returns it as json.')
+ parser.add_argument('-d', '--debug', action='store_true', help='Prints all STDERR messages. (Non critical included)')
+ args = parser.parse_args()
+
+ if args.debug:
+ __debug = True
+
+ # Run the tools
+ _collecthw = {}
+
+ _dmidecode = get_dmidecode()
+ if isinstance(_dmidecode, str):
+ _collecthw['dmidecode'] = json.loads(_dmidecode)
+
+ # _smartctl = run_subprocess('smartctl --json')
+
+ print(json.dumps(_collecthw))
+
+if __name__ == "__main__":
+ main()
+
diff --git a/modules.d/bas-python/scripts/00reboot_script.sh b/modules.d/bas-python/scripts/00reboot_script.sh
new file mode 100755
index 00000000..2ca40949
--- /dev/null
+++ b/modules.d/bas-python/scripts/00reboot_script.sh
@@ -0,0 +1,6 @@
+#!/bin/bash
+
+echo "°(^.^)° Everything finished (hopefully) successfull"
+read -p "Press Enter to reboot"
+reboot
+
diff --git a/modules.d/bas-registration-hooks/module-setup.sh b/modules.d/bas-registration-hooks/module-setup.sh
new file mode 100755
index 00000000..7f126441
--- /dev/null
+++ b/modules.d/bas-registration-hooks/module-setup.sh
@@ -0,0 +1,20 @@
+#!/usr/bin/env bash
+
+check() {
+ for bin in curl dmidecode; do
+ if ! hash "$bin" 2>&1 /dev/null; then
+ echo "Missing '$bin' please install it..."
+ return 1
+ fi
+ done
+ return 255
+}
+depends() {
+ :
+}
+install() {
+ # pre-mount is the first hook with guaranteed network access
+ inst_hook pre-mount 00 "$moddir/scripts/00_execute_hooks"
+ inst_multiple curl dmidecode
+ return 0
+}
diff --git a/modules.d/bas-registration-hooks/scripts/00_execute_hooks b/modules.d/bas-registration-hooks/scripts/00_execute_hooks
new file mode 100644
index 00000000..6f57545c
--- /dev/null
+++ b/modules.d/bas-registration-hooks/scripts/00_execute_hooks
@@ -0,0 +1,32 @@
+#!/bin/bash
+
+BAS=$(grep -oE 'bas=\S*' /proc/cmdline)
+BAS=${BAS#'bas='}
+export BAS
+UUID=$(dmidecode -q -s system-uuid)
+
+mkdir /tmp/nexthook
+cd /tmp/nexthook
+while true
+do
+ curl -s -D header -o script --insecure https://$BAS/api/registrations/$UUID/nexthook
+ if [ -s script ]
+ then
+ echo ""
+ if sh script
+ then
+ ID=$(grep -oE 'id:\s\S+' header)
+ ID=${ID#'id: '}
+ curl -s --data "id=$ID" --insecure https://$BAS/api/registrations/$UUID/success > /dev/null
+ echo ""
+ echo "Script with id $ID finished."
+ echo ""
+ fi
+ else
+ break
+ fi
+
+ drop_shell
+done
+
+reboot -f
diff --git a/modules.d/busybox/module-setup.sh b/modules.d/busybox/module-setup.sh
index 807022e9..cbe34c87 100644
--- a/modules.d/busybox/module-setup.sh
+++ b/modules.d/busybox/module-setup.sh
@@ -1,6 +1,6 @@
#!/bin/bash
[ -z "$BB_GIT" ] && declare -rg BB_GIT="git://git.busybox.net/busybox"
-[ -z "$BB_BRANCH" ] && declare -rg BB_BRANCH="1_25_1"
+[ -z "$BB_BRANCH" ] && declare -rg BB_BRANCH="1_32_0"
build() {
local base_url="https://git.openslx.org/openslx-ng/mltk.git/plain/core/modules/busybox/"