summaryrefslogtreecommitdiff
path: root/scripts/list-build-dependencies
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-01-22 18:45:34 +0100
committerChristian Poessinger <christian@poessinger.com>2020-01-22 18:45:34 +0100
commitb7536e4b3699c1fd9f4338981111583e85cef662 (patch)
treefe165b6af1ba8a3355f105b06e850132cc70b197 /scripts/list-build-dependencies
parent0b67e14b62fee0d4ab3d2d621828000701758767 (diff)
downloadvyos-build-b7536e4b3699c1fd9f4338981111583e85cef662.tar.gz
vyos-build-b7536e4b3699c1fd9f4338981111583e85cef662.zip
scripts: add helper to list all build dependencies
This script will download vyos-world debian/control file and build a denpendency list which in the end outputs the commands required to setup a build host (either native or via Docker) with all required packages.
Diffstat (limited to 'scripts/list-build-dependencies')
-rwxr-xr-xscripts/list-build-dependencies115
1 files changed, 115 insertions, 0 deletions
diff --git a/scripts/list-build-dependencies b/scripts/list-build-dependencies
new file mode 100755
index 0000000..e7fc330
--- /dev/null
+++ b/scripts/list-build-dependencies
@@ -0,0 +1,115 @@
+#!/bin/bash
+#
+# Copyright (C) 2018 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.
+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 ""
+
+# First we need to get vyos-world so we know all individual packages for VyOS
+curl -L https://github.com/vyos/vyos-world/raw/current/debian/control \
+ --output /tmp/vyos-world.control --retry 100 --retry-delay 1 --silent
+
+VYOS_PACKAGES=$(get_runtime_depends /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/current/debian/control \
+ --output $CTRLFILE --retry 100 --retry-delay 1 --silent
+
+ declare -a array
+ declare -i length current
+
+ array=($(get_build_depends $CTRLFILE))
+ length=${#array[@]}
+ current=0
+
+ echo "# Packages needed to build '$pkg' from https://github.com/vyos/$pkg"
+ echo "apt-get install -y \\"
+ for name in "${array[@]}"; do
+ current=$((current + 1))
+ if [[ "$current" -eq "$length" ]]; then
+ echo " $name"
+ else
+ echo " $name \\"
+ fi
+ done
+ rm -f $CTRLFILE
+ echo ""
+done
+