summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/check-qemu-install59
-rwxr-xr-xscripts/list-build-dependencies120
-rwxr-xr-xscripts/list-required-firmware75
-rwxr-xr-xscripts/live-build-config1
4 files changed, 227 insertions, 28 deletions
diff --git a/scripts/check-qemu-install b/scripts/check-qemu-install
index 88477afd..0c443f18 100755
--- a/scripts/check-qemu-install
+++ b/scripts/check-qemu-install
@@ -94,6 +94,34 @@ class StreamToLogger(object):
def flush(self):
pass
+def get_qemu_cmd(name, enable_kvm, disk_img, iso_img=None):
+ kvm = ""
+ cpu = "-cpu host"
+ if not enable_kvm:
+ kvm = "--no-kvm"
+ cpu = ""
+
+ cdrom = ""
+ if iso_img:
+ cdrom = "-boot d -cdrom {}".format(iso_img)
+
+ cmd = 'qemu-system-x86_64 \
+ -name "{NAME}" \
+ -m 1G \
+ -nic user,model=virtio,mac=52:54:99:12:34:56 \
+ -nic user,model=virtio,mac=52:54:99:12:34:57 \
+ -nic user,model=virtio,mac=52:54:99:12:34:58 \
+ -nic user,model=virtio,mac=52:54:99:12:34:59 \
+ -machine accel=kvm \
+ {CPU} \
+ -smp 2 \
+ -nographic \
+ {CD} \
+ {KVM} \
+ -drive format=raw,file={DISK}'.format(NAME=name, CD=cdrom, DISK=disk_img, KVM=kvm, CPU=cpu)
+
+ return cmd
+
# Setting up logger
log = logging.getLogger()
@@ -150,20 +178,7 @@ try:
# Installing image to disk
#################################################
log.info("Installing system")
-
- cmd = """qemu-system-x86_64 \
- -name "TESTVM" \
- -m 1G \
- -nic user,model=virtio,mac=52:54:99:12:34:56,hostfwd=tcp::2299-:22 \
- -machine accel=kvm \
- {CPU} \
- -smp 2 \
- -vnc 0.0.0.0:99 \
- -nographic \
- -boot d -cdrom {CD} \
- {KVM} \
- -drive format=raw,file={DISK}
- """.format(CD=args.iso, DISK=args.disk, KVM="" if kvm else "--no-kvm", CPU="-cpu host" if kvm else "")
+ cmd = get_qemu_cmd("TESTVM", kvm, args.disk, args.iso)
log.debug("Executing command: {}".format(cmd))
c = pexpect.spawn(cmd, logfile=stl)
@@ -237,19 +252,7 @@ try:
# Booting installed system
#################################################
log.info("Booting installed system")
-
- cmd = """qemu-system-x86_64 \
- -name "TESTVM" \
- -m 1G \
- -nic user,model=virtio,mac=52:54:99:12:34:56,hostfwd=tcp::2299-:22
- -machine accel=kvm \
- {CPU} \
- -smp 2 \
- -nographic \
- {KVM} \
- -drive format=raw,file={DISK}
- """.format(DISK=args.disk, KVM="" if kvm else "--no-kvm", CPU="-cpu host" if kvm else "")
-
+ cmd = get_qemu_cmd("TESTVM", kvm, args.disk)
log.debug('Executing command: {}'.format(cmd))
c = pexpect.spawn(cmd, logfile=stl)
@@ -290,7 +293,7 @@ try:
i = child.expect(['\n +Invalid command:',
'\n +Set failed',
'No such file or directory',
- r'\n\S+@\S+[$#]'])
+ r'\n\S+@\S+[$#]'], timeout=1800)
if i==0:
raise Exception('Invalid command detected')
diff --git a/scripts/list-build-dependencies b/scripts/list-build-dependencies
new file mode 100755
index 00000000..e13651f3
--- /dev/null
+++ b/scripts/list-build-dependencies
@@ -0,0 +1,120 @@
+#!/bin/bash
+#
+# Copyright (C) 2020 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# in order to easy exprort images built to "external" world
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+# Parse debian/control like content and extract packages required by the
+# Build-Depends statement. Return a string with all required packages.
+#
+# Code below copied from https://stackoverflow.com/a/47707412 - Thank You!
+get_build_depends () {
+ echo $(awk '
+ /^Build-Depends:/ || /^ / && deps {
+ sub(/^[^ ]+: /, "")
+ deps = 1
+ dep_str = dep_str ", " $0
+ next
+ }
+ { deps=0 }
+ END {
+ split(dep_str, dep_array, /, */)
+ for (d in dep_array) {
+ dep = dep_array[d]
+ gsub(/[^a-z0-9_.-].*$/, "", dep)
+ if (dep && !seen[dep]++) print dep
+ }
+ }' $1)
+}
+
+get_runtime_depends () {
+ echo $(awk '
+ /^Depends:/ || /^ / && deps {
+ sub(/^[^ ]+: /, "")
+ deps = 1
+ dep_str = dep_str ", " $0
+ next
+ }
+ { deps=0 }
+ END {
+ split(dep_str, dep_array, /, */)
+ for (d in dep_array) {
+ dep = dep_array[d]
+ gsub(/[^a-z0-9_.-].*$/, "", dep)
+ if (dep && !seen[dep]++) print dep
+ }
+ }' $1)
+}
+
+# Some packages are required prior to running this script
+BOOTSTRAP_PACKAGES="devscripts curl equivs"
+for pkg in $BOOTSTRAP_PACKAGES
+do
+ dpkg -s $pkg >/dev/null 2>&1
+ if [ $? -ne 0 ]; then
+ echo "Required package \"$pkg\" not installed"
+ exit 1
+ fi
+done
+
+echo ""
+echo "Below you can find a list of packages that are required as build time"
+echo "dependency for the individual package"
+echo ""
+echo "The generated content can be used to populate a file to provision"
+echo "e.g. a native build host or a Docker container"
+echo ""
+echo ""
+
+GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
+
+# First we need to get vyos-world so we know all individual packages for VyOS
+curl -L https://github.com/vyos/vyos-world/raw/$GIT_BRANCH/debian/control \
+ --output /tmp/vyos-world.control --retry 100 --retry-delay 1 --silent
+
+VYOS_PACKAGES=$(get_runtime_depends /tmp/vyos-world.control)
+rm -f /tmp/vyos-world.control
+for pkg in $VYOS_PACKAGES
+do
+ # Check if repo exists
+ res=$(curl -o /dev/null --silent -Iw '%{http_code}' https://github.com/vyos/$pkg)
+ if [[ $res -ne 200 ]]; then
+ continue
+ fi
+
+ CTRLFILE=/tmp/$pkg.control
+ curl -L https://github.com/vyos/$pkg/raw/$GIT_BRANCH/debian/control \
+ --output $CTRLFILE --retry 100 --retry-delay 1 --silent
+
+ declare -a array
+ declare -i length cnt
+
+ array=($(get_build_depends $CTRLFILE))
+ length=${#array[@]}
+ cnt=0
+
+ echo "# Packages needed to build '$pkg' from https://github.com/vyos/$pkg"
+ echo "apt-get install -y \\"
+ for name in "${array[@]}"; do
+ cnt=$((cnt + 1))
+ if [[ "$cnt" -eq "$length" ]]; then
+ echo " $name"
+ else
+ echo " $name \\"
+ fi
+ done
+ rm -f $CTRLFILE
+ echo ""
+done
+
diff --git a/scripts/list-required-firmware b/scripts/list-required-firmware
new file mode 100755
index 00000000..64280e03
--- /dev/null
+++ b/scripts/list-required-firmware
@@ -0,0 +1,75 @@
+#!/usr/bin/env python3
+# Copyright (C) 2020 VyOS maintainers and contributors
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 or later as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+import re
+import os
+import sys
+import glob
+
+
+SRC_DIR = sys.argv[1]
+KERNEL_CONFIG = sys.argv[2]
+
+def load_config(path):
+ with open(KERNEL_CONFIG, 'r') as f:
+ config = f.read()
+ targets = re.findall(r'(.*)=(?:y|m)', config)
+ return targets
+
+def find_subdirs(config, path):
+ try:
+ with open(os.path.join(path, 'Makefile'), 'r') as f:
+ makefile = f.read()
+ except OSError:
+ # No Makefile
+ return []
+
+ dir_stmts = re.findall(r'obj-\$\((.*)\)\s+\+=\s+(.*)(?:\n|$)', makefile)
+ subdirs = []
+ for ds in dir_stmts:
+ print("Processing make targets from {0} ({1})".format(ds[1], ds[0]), file=sys.stderr)
+ if ds[0] in config:
+ dirname = os.path.dirname(ds[1])
+ if dirname:
+ subdirs.append(dirname)
+ else:
+ print("{0} is disabled in the config, ignoring {1}".format(ds[0], ds[1]), file=sys.stderr)
+
+ return subdirs
+
+def find_firmware(file):
+ with open(file, 'r') as f:
+ source = f.read()
+ fws = re.findall(r'MODULE_FIRMWARE\((.*)\)', source)
+ return fws
+
+def walk_dir(config, path):
+ subdirs = find_subdirs(config, path)
+
+ print("Looking for C files in {0}".format(path), file=sys.stderr)
+ c_files = glob.glob("{0}/*.c".format(path))
+ for cf in c_files:
+ fws = find_firmware(cf)
+ if fws:
+ print("Referenced firmware: {0}".format(fws))
+
+ for d in subdirs:
+ d = os.path.join(path, d)
+ walk_dir(config, d)
+
+if __name__ == '__main__':
+ config = load_config(KERNEL_CONFIG)
+ walk_dir(config, SRC_DIR)
diff --git a/scripts/live-build-config b/scripts/live-build-config
index 61e71c0d..1b31e4fd 100755
--- a/scripts/live-build-config
+++ b/scripts/live-build-config
@@ -57,6 +57,7 @@ lb config noauto \
--firmware-binary false \
--updates true \
--security true \
+ --apt-recommends false \
--apt-options "--yes -oAPT::Default-Release="current" -oAPT::Get::allow-downgrades=true" \
--apt-indices false
"${@}"