#!/bin/bash if [ ! -d "packages" ]; then echo "This script needs to be executed inside the top root of vyos-build" exit 1 fi print_help() { echo "Script for building all subpackages to vyos" echo "Execute this sctipt from the root of the vyos-build directory" echo "" echo "This script could be executed from a Debian Jessie installation with all dependencies" echo "or from the vyos-builder docker container." echo "" echo "Build the container:" echo " docker build -t vyos-builder ." echo "Compile packages:" echo " docker run --rm -it -v $(pwd):/vyos -w /vyos --sysctl net.ipv6.conf.lo.disable_ipv6=0 vyos-builder scripts/build-submodules" echo "" echo "Parameters:" echo " --init-packages - Initiate all subpackages before building" echo " --verbose|-v - Enable verbose output" } while test $# -gt 0 do case "$1" in -h|-?|--help) print_help exit 0 ;; --init-packages) INIT_PACKAGES=1 ;; --verbose|-v) VERBOSE=1 ;; *) (>&2 echo "Error: Argument $1 is not valid") echo "" print_help exit 1 ;; esac shift done status_start() { echo -ne "[ ] $1" } status_ok() { echo -ne "\r[\e[32m OK \e[39m]\n" } status_fail() { echo -ne "\r[\e[31mFAIL\e[39m]\n" } status_skip() { echo -ne "\r[SKIP] $1\n" } error_msg() { echo -ne " $1\n" } ROOTDIR="$(pwd)" PKGDIR="$ROOTDIR/packages" SCRIPTDIR="$ROOTDIR/scripts" build_package() { PKG=$1 status_start "Building package: $PKG" if [ ! -d "$PKGDIR/$PKG/debian" ]; then status_skip "No source for: $PKG" return 1 fi ( set -e; set -x cd $PKGDIR/$PKG dpkg-buildpackage -uc -us -tc -b ) >>$PKGDIR/$PKG.buildlog 2>&1 if [ $? -ne 0 ]; then status_fail error_msg "Failed to build package $PKG, look in $PKG.buildlog to examine the fault\n" return 2 fi status_ok } echo "Cleaning up buildfiles..." rm -rf $PKGDIR/*.deb rm -rf $PKGDIR/*.changes rm -rf $PKGDIR/*.buildlog echo "-----------------------------------------------------" echo "Starting build process for all packages" echo "" initialize_packages() { status_start "Initializing packages" ( set -x git submodule update --init --recursive git submodule update --remote ) >>$PKGDIR/init-packages.buildlog 2>&1 if [ $? -ne 0 ]; then status_fail if [ $VERBOSE ]; then cat $PKGDIR/init-packages.buildlog fi error_msg "Failed to update all package, look in init-packages.buildlog to examine the fault\n" return 1 fi status_ok } if [ $INIT_PACKAGES ]; then initialize_packages fi for PKG in mdns-repeater \ pmacct \ udp-broadcast-relay \ vyatta-bash \ vyatta-cfg \ vyatta-cfg-firewall \ vyatta-cfg-op-pppoe \ vyatta-cfg-qos \ vyatta-cfg-quagga \ vyatta-cfg-system \ vyatta-cfg-vpn \ vyatta-cluster \ vyatta-config-mgmt \ vyatta-config-migrate \ vyatta-conntrack \ vyatta-conntrack-sync \ vyatta-eventwatch \ vyatta-iproute \ vyatta-ipv6-rtradv \ vyatta-lldp \ vyatta-nat \ vyatta-netflow \ vyatta-op \ vyatta-op-dhcp-server \ vyatta-op-firewall \ vyatta-op-qos \ vyatta-op-quagga \ vyatta-op-vpn \ vyatta-openvpn \ vyatta-ravpn \ vyatta-vrrp \ vyatta-wanloadbalance \ vyatta-webgui \ vyatta-webproxy \ vyatta-wireless \ vyatta-wirelessmodem \ vyatta-zone \ vyos-keepalived \ vyos-nhrp \ vyos-pppoe-server \ vyos-strongswan \ vyos-world \ ; do build_package "$PKG" ERRCODE=$? if [ "$ERRCODE" -ne "0" ]; then exit $ERRCODE fi done # KERNEL build_kernel() { status_start "Building-package: vyos-kernel" if [ ! -f "$PKGDIR/vyos-kernel/Makefile" ]; then status_skip "No source for: vyos-kernel" return 0 fi ( set -e; set -x cd $PKGDIR/vyos-kernel > /dev/null bash -c "$SCRIPTDIR/build-kernel" ) >>$PKGDIR/vyos-kernel.buildlog 2>&1 if [ $? -ne 0 ]; then status_fail if [ $VERBOSE ]; then cat $PKGDIR/vyos-kernel.buildlog fi error_msg "Failed to build package vyos-kernel, look in vyos-kernel.buildlog to examine the fault\n" return 1 fi VERSION=$(grep "^VERSION" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') PATCHLEVEL=$(grep "^PATCHLEVEL" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') SUBLEVEL=$(grep "^SUBLEVEL" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') ARCH=$(dpkg --print-architecture) echo "$VERSION.$PATCHLEVEL.$SUBLEVEL" > $ROOTDIR/data/kernel_version status_ok } build_kernel ERRCODE=$? if [ "$ERRCODE" -ne "0" ]; then exit $ERRCODE fi # WIREGUARD build_wireguard() { status_start "Building package: vyos-wireguard" if [ ! -d "$PKGDIR/vyos-wireguard/debian" ]; then status_skip "No source for: vyos-wireguard" return 0 fi if [ ! -f "$PKGDIR/vyos-kernel/Makefile" ]; then status_fail error_msg "No Makefile found in kernel package" return 1 fi if ! grep -q "KBUILD_OUTPUT" $PKGDIR/vyos-kernel/Makefile; then status_fail error_msg "Failed to build package vyos-wireguard, no kernel source found\n" return 1 fi VERSION=$(grep "^VERSION" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') PATCHLEVEL=$(grep "^PATCHLEVEL" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') SUBLEVEL=$(grep "^SUBLEVEL" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') ARCH=$(dpkg --print-architecture) # Collect kernel information ( set -e; set -x cd $PKGDIR/vyos-wireguard echo "src/wireguard.ko /lib/modules/$VERSION.$PATCHLEVEL.$SUBLEVEL-$ARCH-vyos/extra" | tee debian/wireguard-modules.install KERNELDIR=$PKGDIR/vyos-kernel dpkg-buildpackage -uc -us -tc -b ) >>$PKGDIR/vyos-wireguard.buildlog 2>&1 if [ $? -ne 0 ]; then status_fail if [ $VERBOSE ]; then cat $PKGDIR/vyos-wireguard.buildlog fi error_msg "Failed to build package vyos-wireguard, look in vyos-wireguard.buildlog to examine the fault\n" return 2 fi status_ok } build_wireguard ERRCODE=$? if [ "$ERRCODE" -ne "0" ]; then exit $ERRCODE fi # ACCEL-PPP build_accel-ppp() { status_start "Building package: vyos-accel-ppp" if [ ! -d "$PKGDIR/vyos-accel-ppp/debian" ]; then status_skip "No source for: vyos-accel-ppp" return 0 fi if [ ! -f "$PKGDIR/vyos-kernel/Makefile" ]; then status_fail error_msg "No Makefile found in kernel package" return 1 fi if ! grep -q "KBUILD_OUTPUT" $PKGDIR/vyos-kernel/Makefile; then status_fail error_msg "Failed to build package vyos-accel-ppp, no kernel source found\n" fi # Collect kernel information VERSION=$(grep "^VERSION" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') PATCHLEVEL=$(grep "^PATCHLEVEL" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') SUBLEVEL=$(grep "^SUBLEVEL" $PKGDIR/vyos-kernel/Makefile | grep -Eo '[0-9]{1,4}') ARCH=$(dpkg --print-architecture) ( set -e; set -x cd $PKGDIR/vyos-accel-ppp echo "lib/modules/$VERSION.$PATCHLEVEL.$SUBLEVEL-$ARCH-vyos/extra/*.ko" | tee debian/vyos-accel-ppp-ipoe-kmod.install sed -i "s#[0-9].[0-9][0-9].[0-9]-amd64-vyos#$VERSION.$PATCHLEVEL.$SUBLEVEL-$ARCH-vyos#g" debian/rules KERNELDIR=$PKGDIR/vyos-kernel dpkg-buildpackage -uc -us -tc -b ) >>$PKGDIR/vyos-accel-ppp.buildlog 2>&1 if [ $? -ne 0 ]; then status_fail if [ $VERBOSE ]; then cat $PKGDIR/vyos-accel-ppp.buildlog fi error_msg "Failed to build package vyos-accel-ppp, look in vyos-accel-ppp.buildlog to examine the fault\n" return 1 fi status_ok } build_accel-ppp ERRCODE=$? if [ "$ERRCODE" -ne "0" ]; then exit $ERRCODE fi