├── debian ├── compat ├── docs ├── lintian ├── README ├── autogen.sh ├── control ├── changelog ├── copyright └── rules ├── ChangeLog ├── NEWS ├── sysconf └── vyos-cloudinit │ ├── vyos-cloudinit.conf │ ├── ec2.conf │ └── openstack.conf ├── AUTHORS ├── examples ├── config.change-hostname └── change-hostname.sh ├── README ├── .gitignore ├── templates-cfg └── service │ └── cloudinit │ ├── node.def │ ├── ssh-key │ └── node.def │ ├── user-data │ └── node.def │ ├── ssh-user │ └── node.def │ └── environment │ └── node.def ├── etc └── init.d │ ├── vyos-ssh-key │ └── vyos-cloudinit ├── Makefile.am ├── configure.ac ├── scripts ├── vyos-ssh-key └── vyos-cloudinit └── README.md /debian/compat: -------------------------------------------------------------------------------- 1 | 5 2 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | debian/changelog -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | None at this time 2 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | NEWS 2 | README 3 | -------------------------------------------------------------------------------- /sysconf/vyos-cloudinit/vyos-cloudinit.conf: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | VyOS contributors, including: 2 | 3 | Yuya Kusakabe 4 | -------------------------------------------------------------------------------- /debian/lintian: -------------------------------------------------------------------------------- 1 | vyos-cloudinit: file-in-unusual-dir 2 | vyos-cloudinit: dir-or-file-in-opt 3 | -------------------------------------------------------------------------------- /examples/config.change-hostname: -------------------------------------------------------------------------------- 1 | #vyos-config 2 | system { 3 | host-name hoge 4 | } 5 | -------------------------------------------------------------------------------- /examples/change-hostname.sh: -------------------------------------------------------------------------------- 1 | #!/bin/vbash 2 | source /opt/vyatta/etc/functions/script-template 3 | 4 | set system hostname hoge 5 | commit 6 | save 7 | -------------------------------------------------------------------------------- /sysconf/vyos-cloudinit/ec2.conf: -------------------------------------------------------------------------------- 1 | SSH_USER="vyos" 2 | SSH_KEY="http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key" 3 | USER_DATA="http://169.254.169.254/latest/user-data" 4 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | vyos-cloudinit enables a user to customize VyOS machines by providing either a vyos-config document or an executable script through user-data. 2 | 3 | See README.md for details. 4 | -------------------------------------------------------------------------------- /sysconf/vyos-cloudinit/openstack.conf: -------------------------------------------------------------------------------- 1 | SSH_USER="vyos" 2 | SSH_KEY="http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key" 3 | USER_DATA="http://169.254.169.254/latest/user-data" 4 | -------------------------------------------------------------------------------- /debian/README: -------------------------------------------------------------------------------- 1 | The Debian Package vyos-cloudinit 2 | --------------------------------- 3 | 4 | This package is a VyOS cloudinit. 5 | 6 | -- Yuya Kusakabe Thu, 15 Dec 2016 15:11:43 +0900 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.status 3 | *.log 4 | *.substvars 5 | 6 | COPYING 7 | INSTALL 8 | build-stamp 9 | config 10 | config.guess 11 | config.sub 12 | configure 13 | Makefile 14 | Makefile.in 15 | debian/files 16 | debian/vyos-cloudinit 17 | aclocal.m4 18 | -------------------------------------------------------------------------------- /debian/autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | 4 | rm -rf config 5 | rm -f aclocal.m4 config.guess config.statusconfig.sub configure INSTALL 6 | 7 | autoreconf --force --install 8 | 9 | rm -f config.sub config.guess 10 | ln -s /usr/share/misc/config.sub . 11 | ln -s /usr/share/misc/config.guess . 12 | -------------------------------------------------------------------------------- /templates-cfg/service/cloudinit/node.def: -------------------------------------------------------------------------------- 1 | priority: 400 2 | help: Cloud init 3 | create: sudo /usr/sbin/update-rc.d vyos-cloudinit defaults 4 | sudo /usr/sbin/update-rc.d vyos-ssh-key defaults 5 | 6 | delete: sudo /usr/sbin/update-rc.d -f vyos-cloudinit remove 7 | sudo /usr/sbin/update-rc.d -f vyos-ssh-key remove 8 | -------------------------------------------------------------------------------- /templates-cfg/service/cloudinit/ssh-key/node.def: -------------------------------------------------------------------------------- 1 | type: txt 2 | help: SSH key URL 3 | syntax:expression: pattern $VAR(@) "^[^!]+$" ; "SSH key URL must not be null and must not contain '!'" 4 | create: sudo sh -c "echo SSH_KEY=$VAR(@) >> /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 5 | update: sudo sh -c "sed -i '/^SSH_KEY=/c/SSH_KEY=$VAR(@)/' /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 6 | delete: sudo sh -c "sed -i '/SSH_KEY=/d' /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 7 | -------------------------------------------------------------------------------- /templates-cfg/service/cloudinit/user-data/node.def: -------------------------------------------------------------------------------- 1 | type: txt 2 | help: User Data URL 3 | syntax:expression: pattern $VAR(@) "^[^!]+$" ; "user-data URL must not be null and must not contain '!'" 4 | create: sudo sh -c "echo USER_DATA=$VAR(@) >> /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 5 | update: sudo sh -c "sed -i '/^USER_DATA=/c/USER_DATA=$VAR(@)/' /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 6 | delete: sudo sh -c "sed -i '/USER_DATA=/d' /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 7 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: vyos-cloudinit 2 | Section: admin 3 | Priority: extra 4 | Maintainer: VyOS Maintainers 5 | Standards-Version: 3.9.1 6 | Build-Depends: debhelper (>= 5), autotools-dev, autoconf 7 | 8 | Package: vyos-cloudinit 9 | Architecture: all 10 | Depends: vyatta-cfg-system, 11 | vyatta-cfg, 12 | vyatta-op, 13 | ${misc:Depends} 14 | Replaces: vyos-cloudinit 15 | Description: vyos-cloudinit 16 | vyos-cloudinit enables a user to customize VyOS machines by providing either a VyOS config document or an executable script through user-data. 17 | -------------------------------------------------------------------------------- /etc/init.d/vyos-ssh-key: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: vyos-ssh-key 4 | # Required-Start: vyos-cloudinit 5 | # Required-Stop: 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 8 | # Short-Description: Load user SSH key. 9 | # Description: Load user SSH key. 10 | ### END INIT INFO 11 | 12 | . /lib/lsb/init-functions 13 | 14 | : ${vyatta_env:=/etc/default/vyatta} 15 | source $vyatta_env 16 | 17 | log_action_begin_msg "Starting vyos-ssh-key" 18 | sg ${VYATTA_CFG_GROUP_NAME} ${vyatta_sbindir}/vyos-ssh-key 19 | log_action_end_msg $? 20 | -------------------------------------------------------------------------------- /templates-cfg/service/cloudinit/ssh-user/node.def: -------------------------------------------------------------------------------- 1 | type: txt 2 | help: SSH user 3 | 4 | syntax:expression: exec "cli-shell-api exists system login user $VAR(@)" 5 | ; "$VAR(@) does not exist" 6 | allowed: list=`cli-shell-api listNodes system login user` 7 | echo $list 8 | 9 | create: sudo sh -c "echo SSH_USER=$VAR(@) >> /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 10 | update: sudo sh -c "sed -i '/^SSH_USER=/c/SSH_USER=$VAR(@)/' /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 11 | delete: sudo sh -c "sed -i '/SSH_USER=/d' /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 12 | -------------------------------------------------------------------------------- /etc/init.d/vyos-cloudinit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ### BEGIN INIT INFO 3 | # Provides: vyos-cloudinit 4 | # Required-Start: vyatta-router 5 | # Required-Stop: 6 | # Default-Start: 2 3 4 5 7 | # Default-Stop: 8 | # Short-Description: Merge user VyOS config or run user script. 9 | # Description: Merge user VyOS config or run user script. 10 | ### END INIT INFO 11 | 12 | . /lib/lsb/init-functions 13 | 14 | : ${vyatta_env:=/etc/default/vyatta} 15 | source $vyatta_env 16 | 17 | log_action_begin_msg "Starting vyos-cloudinit" 18 | sg ${VYATTA_CFG_GROUP_NAME} ${vyatta_sbindir}/vyos-cloudinit 19 | log_action_end_msg $? 20 | -------------------------------------------------------------------------------- /templates-cfg/service/cloudinit/environment/node.def: -------------------------------------------------------------------------------- 1 | type: txt 2 | help: Environment 3 | syntax:expression: exec "[ -f /opt/vyatta/etc/vyos-cloudinit/$VAR(@).conf ]" 4 | ; "$VAR(@) is not supported" 5 | allowed: sudo ls -1 /opt/vyatta/etc/vyos-cloudinit/ | sed 's/.conf//' | grep -v vyos-cloudinit 6 | create: sudo sh -c "echo ENVIRONMENT=$VAR(@) >> /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 7 | update: sudo sh -c "sed -i '/^ENVIRONMENT=/c/ENVIRONMENT=$VAR(@)/' /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 8 | delete: sudo sh -c "sed -i '/ENVIRONMENT=/d' /opt/vyatta/etc/vyos-cloudinit/vyos-cloudinit.conf" 9 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | cfgdir = $(datadir)/vyatta-cfg/templates 2 | initddir = /etc/init.d 3 | sysconfdir = /opt/vyatta/etc/vyos-cloudinit 4 | 5 | initd_SCRIPTS = 6 | initd_SCRIPTS += etc/init.d/vyos-cloudinit 7 | initd_SCRIPTS += etc/init.d/vyos-ssh-key 8 | 9 | sbin_SCRIPTS = 10 | sbin_SCRIPTS += scripts/vyos-cloudinit 11 | sbin_SCRIPTS += scripts/vyos-ssh-key 12 | 13 | sysconf_DATA = 14 | sysconf_DATA += sysconf/vyos-cloudinit/vyos-cloudinit.conf 15 | sysconf_DATA += sysconf/vyos-cloudinit/ec2.conf 16 | sysconf_DATA += sysconf/vyos-cloudinit/openstack.conf 17 | 18 | cpiop = find . ! -regex '\(.*~\|.*\.bak\|.*\.swp\|.*\#.*\#\)' -print0 | \ 19 | cpio -0pd 20 | 21 | install-exec-hook: 22 | mkdir -p $(DESTDIR)$(cfgdir) 23 | cd templates-cfg; $(cpiop) $(DESTDIR)$(cfgdir) 24 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | # Process this file with autoconf to produce a configure script. 2 | AC_PREREQ(2.59) 3 | 4 | m4_define([VERSION_ID], [m4_esyscmd([ 5 | if test -f .version ; then 6 | head -n 1 .version | tr -d \\n 7 | else 8 | echo -n 2.4 9 | fi])]) 10 | AC_INIT([vyos-vxlan], VERSION_ID, [maintainers@vyos.net]) 11 | 12 | test -n "$VYATTA_VERSION" || VYATTA_VERSION=$PACKAGE_VERSION 13 | 14 | AC_CONFIG_AUX_DIR([config]) 15 | AM_INIT_AUTOMAKE([gnu no-dist-gzip dist-bzip2 subdir-objects]) 16 | AC_PREFIX_DEFAULT([/opt/vyatta]) 17 | 18 | AC_ARG_ENABLE([nostrip], 19 | AC_HELP_STRING([--enable-nostrip], 20 | [include -nostrip option during packaging]), 21 | [NOSTRIP=-nostrip], [NOSTRIP=]) 22 | 23 | AC_CONFIG_FILES([Makefile]) 24 | 25 | AC_SUBST(NOSTRIP) 26 | 27 | AC_PROG_CC 28 | AC_PROG_CXX 29 | AM_PROG_AS 30 | AM_PROG_CC_C_O 31 | AC_OUTPUT 32 | -------------------------------------------------------------------------------- /scripts/vyos-ssh-key: -------------------------------------------------------------------------------- 1 | #!/bin/vbash 2 | 3 | : ${vyatta_env:=/etc/default/vyatta} 4 | source $vyatta_env 5 | 6 | ENVIRONMENT="" 7 | SSH_KEY="" 8 | SSH_USER="vyos" 9 | 10 | CONF_DIR="${vyatta_sysconfdir}/vyos-cloudinit" 11 | . ${CONF_DIR}/vyos-cloudinit.conf 12 | 13 | if [ -n "${ENVIRONMENT}" ]; then 14 | env_conf=${CONF_DIR}/${ENVIRONMENT}.conf 15 | if [ -f ${env_conf} ]; then 16 | . ${env_conf} 17 | else 18 | echo "${ENVIRONMENT} is not supported" 19 | fi 20 | fi 21 | 22 | # override with user specified parameters 23 | . ${CONF_DIR}/vyos-cloudinit.conf 24 | 25 | if [[ -z "${SSH_KEY}" ]]; then 26 | echo "ssh-key not specified" 27 | exit 0 28 | fi 29 | 30 | LOAD_KEY="${vyatta_sbindir}/vyatta-load-user-key.pl" 31 | 32 | _exit=exit 33 | source ${vyatta_sysconfdir}/functions/script-template 34 | 35 | function load_key() { 36 | echo "loading ssh key..." 37 | ${LOAD_KEY} ${SSH_USER} ${SSH_KEY} 38 | } 39 | 40 | if [[ -n "${SSH_KEY}" && "${SSH_KEY}" == "http"* ]]; then 41 | /usr/bin/curl -m 3 -sf "${SSH_KEY}" 42 | if [ $? -ne 0 ]; then 43 | echo "could not retrieve ssh key from ${SSH_KEY}" 44 | $_exit 1 45 | else 46 | load_key 47 | $_exit $? 48 | fi 49 | elif [[ -n "${SSH_KEY}" ]]; then 50 | load_key 51 | $_exit $? 52 | fi 53 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | vyos-cloudinit (0.3.2) unstable; urgency=low 2 | 3 | [ Byron McCollum ] 4 | * Fix default user-data URL in openstack.conf 5 | 6 | -- Yuya Kusakabe Wed, 04 Oct 2017 08:47:36 +0900 7 | 8 | vyos-cloudinit (0.3.1) unstable; urgency=low 9 | 10 | [Anders Svanqvist] 11 | * Run scripts with correct group 12 | 13 | -- Yuya Kusakabe Fri, 28 Apr 2016 00:18:15 +0900 14 | 15 | vyos-cloudinit (0.3.0) unstable; urgency=low 16 | 17 | * Separate ssh key script from cloudinit script 18 | 19 | -- Yuya Kusakabe Fri, 30 Dec 2016 13:11:05 +0900 20 | 21 | vyos-cloudinit (0.2.1) unstable; urgency=low 22 | 23 | * Remove command option from scripts/vyos-cloudinit 24 | 25 | -- Yuya Kusakabe Tue, 20 Dec 2016 23:26:16 +0900 26 | 27 | vyos-cloudinit (0.2.0) unstable; urgency=low 28 | 29 | * Initial support for OpenStack . 30 | 31 | -- Yuya Kusakabe Tue, 20 Dec 2016 14:45:54 +0900 32 | 33 | vyos-cloudinit (0.1.0) unstable; urgency=low 34 | 35 | * Add command templates. 36 | * Initial support for EC2. 37 | 38 | -- Yuya Kusakabe Tue, 20 Dec 2016 12:41:22 +0900 39 | 40 | vyos-cloudinit (0.0.1) unstable; urgency=low 41 | 42 | * Initial release. 43 | 44 | -- Yuya Kusakabe Thu, 15 Dec 2016 15:11:43 +0900 45 | 46 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | This package was debianized by Yuya Kusakabe on 2 | Thu, 15 Dec 2016. 3 | 4 | It's original content from the GIT repository 5 | 6 | 7 | Upstream Author: 8 | 9 | Yuya Kusakabe 10 | 11 | Copyright: 12 | 13 | Copyright (C) 2016 VyOS Development Group, Inc. 14 | All Rights Reserved. 15 | 16 | License: 17 | 18 | This program is free software; you can redistribute it and/or modify 19 | it under the terms of the GNU General Public License as published by 20 | the Free Software Foundation; either version 2, or (at your option) 21 | any later version. 22 | 23 | This program is distributed in the hope that it will be useful, but 24 | WITHOUT ANY WARRANTY; without even the implied warranty of 25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 26 | General Public License for more details. 27 | 28 | A copy of the GNU General Public License is available as 29 | `/usr/share/common-licenses/GPL' in the Debian GNU/Linux distribution 30 | or on the World Wide Web at `http://www.gnu.org/copyleft/gpl.html'. 31 | You can also obtain it by writing to the Free Software Foundation, 32 | Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 33 | MA 02110-1301, USA. 34 | 35 | The Debian packaging is (C) 2016, Yuya Kusakabe and 36 | is licensed under the GPL, see above. 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vyos-cloudinit 2 | 3 | vyos-cloudinit enables a user to customize VyOS machines by providing either a VyOS config document or an executable script through user-data. 4 | 5 | ## Configuration 6 | 7 | ``` 8 | set service cloudinit environment ec2 9 | ``` 10 | 11 | or 12 | 13 | ``` 14 | set service cloudinit ssh-user 15 | set service cloudinit ssh-key 16 | set service cloudinit user-data 17 | ``` 18 | 19 | ## User data 20 | 21 | ### Configuration with vyos-config 22 | 23 | vyos-cloudinit doesn't support cloud-init spec, but supports VyOS config spec. 24 | 25 | The following is an example VyOS config document: 26 | 27 | ``` 28 | #vyos-config 29 | system { 30 | host-name hoge 31 | } 32 | ``` 33 | 34 | It will be merged into existing config. 35 | 36 | ### Executing a Script 37 | 38 | vyos-cloudinit supports executing user-data as a script instead of parsing it as a VyOS config document. 39 | 40 | The following is an example script: 41 | 42 | ``` 43 | #!/bin/vbash 44 | source /opt/vyatta/etc/functions/script-template 45 | 46 | set system hostname hoge 47 | commit 48 | save 49 | ``` 50 | 51 | ## AMI 52 | 53 | AMI name is "VyOS 1.1.7" and it is owned by AWS account ID 971835646178. 54 | 55 | ### Notes 56 | 57 | * vyos-cloudinit is installed by default 58 | * AWS CLI is installed by default 59 | 60 | ### AMIs 61 | 62 | | Region | AMI ID | 63 | | -------------- | ------------ | 64 | | ap-northeast-1 | ami-918470f7 | 65 | | ap-south-1 | ami-74552f1b | 66 | | eu-west-2 | ami-a79485c3 | 67 | | eu-west-1 | ami-2909f950 | 68 | | ap-northeast-2 | ami-d675acb8 | 69 | | sa-east-1 | ami-8d2e5fe1 | 70 | | ca-central-1 | ami-4cc47a28 | 71 | | ap-southeast-1 | ami-981f84fb | 72 | | ap-southeast-2 | ami-99627afa | 73 | | eu-central-1 | ami-63a70e0c | 74 | | us-east-1 | ami-80b683fb | 75 | | us-east-2 | ami-5dba9a38 | 76 | | us-west-1 | ami-e583a885 | 77 | | us-west-2 | ami-8dd734f5 | 78 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | # Sample debian/rules that uses debhelper. 4 | # This file was originally written by Joey Hess and Craig Small. 5 | # As a special exception, when this file is copied by dh-make into a 6 | # dh-make output file, you may use that output file without restriction. 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. 8 | 9 | # Uncomment this to turn on verbose mode. 10 | #export DH_VERBOSE=1 11 | 12 | 13 | # These are used for cross-compiling and for saving the configure script 14 | # from having to guess our platform (since we know it already) 15 | DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) 16 | DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) 17 | PACKAGE=vyos-cloudinit 18 | PKGDIR=$(CURDIR)/debian/$(PACKAGE) 19 | 20 | CFLAGS = -Wall -g 21 | 22 | configure = ./configure 23 | configure += --host=$(DEB_HOST_GNU_TYPE) 24 | configure += --build=$(DEB_BUILD_GNU_TYPE) 25 | configure += --prefix=/opt/vyatta 26 | configure += --mandir=\$${prefix}/share/man 27 | configure += --infodir=\$${prefix}/share/info 28 | configure += CFLAGS="$(CFLAGS)" 29 | configure += LDFLAGS="-Wl,-z,defs" 30 | 31 | ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) 32 | CFLAGS += -O0 33 | else 34 | CFLAGS += -O2 35 | endif 36 | 37 | configure: configure.ac Makefile.am 38 | chmod +x debian/autogen.sh 39 | debian/autogen.sh 40 | 41 | config.status: configure 42 | dh_testdir 43 | rm -f config.cache 44 | $(configure) 45 | 46 | build: build-stamp 47 | 48 | build-stamp: config.status 49 | dh_testdir 50 | $(MAKE) 51 | touch $@ 52 | 53 | clean: clean-patched 54 | 55 | # Clean everything up, including everything auto-generated 56 | # at build time that needs not to be kept around in the Debian diff 57 | clean-patched: 58 | dh_testdir 59 | dh_testroot 60 | if test -f Makefile ; then $(MAKE) clean distclean ; fi 61 | rm -f build-stamp 62 | rm -f config.status config.sub config.guess config.log 63 | rm -f aclocal.m4 configure Makefile.in Makefile INSTALL 64 | rm -rf config 65 | dh_clean 66 | 67 | install: build 68 | dh_testdir 69 | dh_testroot 70 | dh_clean -k 71 | dh_installdirs 72 | 73 | $(MAKE) DESTDIR=$(PKGDIR) install 74 | 75 | install -D --mode=0644 debian/lintian $(PKGDIR)/usr/share/lintian/overrides/$(PACKAGE) 76 | 77 | # Build architecture-independent files here. 78 | binary-indep: build install 79 | rm -f debian/files 80 | dh_testdir 81 | dh_testroot 82 | dh_installchangelogs ChangeLog 83 | dh_installdocs 84 | dh_install 85 | dh_installdebconf 86 | dh_link 87 | dh_strip 88 | dh_compress 89 | dh_fixperms 90 | dh_installdeb 91 | if [ -f "../.VYATTA_DEV_BUILD" ]; then \ 92 | dh_gencontrol -- -v999.dev; \ 93 | else \ 94 | dh_gencontrol; \ 95 | fi 96 | dh_md5sums 97 | dh_builddeb 98 | 99 | # Build architecture-dependent files here. 100 | binary-arch: build install 101 | # This is an architecture independent package 102 | # so; we have nothing to do by default. 103 | 104 | binary: binary-indep binary-arch 105 | .PHONY: build clean binary-indep binary-arch binary install 106 | -------------------------------------------------------------------------------- /scripts/vyos-cloudinit: -------------------------------------------------------------------------------- 1 | #!/bin/vbash 2 | 3 | : ${vyatta_env:=/etc/default/vyatta} 4 | source $vyatta_env 5 | 6 | ENVIRONMENT="" 7 | USER_DATA="" 8 | 9 | CONF_DIR="${vyatta_sysconfdir}/vyos-cloudinit" 10 | . ${CONF_DIR}/vyos-cloudinit.conf 11 | 12 | if [ -n "${ENVIRONMENT}" ]; then 13 | env_conf=${CONF_DIR}/${ENVIRONMENT}.conf 14 | if [ -f "${env_conf}" ]; then 15 | . ${env_conf} 16 | else 17 | echo "${ENVIRONMENT} is not supported" 18 | fi 19 | fi 20 | 21 | # override with user specified parameters 22 | . ${CONF_DIR}/vyos-cloudinit.conf 23 | 24 | if [[ -z "${USER_DATA}" ]]; then 25 | echo "user-data is not specified" 26 | exit 0 27 | fi 28 | 29 | LOAD_CONFIG="${vyatta_sbindir}/vyatta-load-config.pl" 30 | 31 | _exit=exit 32 | source ${vyatta_sysconfdir}/functions/script-template 33 | 34 | function execute_config_script { 35 | local TEMP_FILE=$1 36 | chmod +x "${TEMP_FILE}" 37 | result=$(${TEMP_FILE}) 38 | if [[ "$?" == 0 ]]; then 39 | echo "USER Config done" 40 | else 41 | echo "Configuration rendering failed ${result}" 42 | $_exit 1 43 | fi 44 | } 45 | 46 | function merge_config_script { 47 | tmpconf=$(mktemp /tmp/XXXXXX-config) 48 | output=$(mktemp /tmp/XXXXXX-output) 49 | tail -n +2 "${1}" > "${tmpconf}" 50 | echo Y | python -c 'import pty, sys; pty.spawn(sys.argv[1:])' ${LOAD_CONFIG} ${tmpconf} --merge > "${output}" 51 | result=$(cat "${output}" | tail -n +5 | head -n -1) 52 | grep -q fail "${output}" 53 | if [[ $? == 0 ]]; then 54 | echo "merge failed" 55 | echo "${result}" 56 | $_exit 1 57 | else 58 | commit 59 | save 60 | echo "USER Config done" 61 | fi 62 | rm -f "${tmpconf}" "${output}" 63 | } 64 | 65 | if [[ "${USER_DATA}" == "config_drive:"* ]]; then 66 | if [[ ! -d "/mnt/config" ]]; then 67 | mkdir -p "/mnt/config" 68 | fi 69 | IFS=':' read -a locs <<< "${USER_DATA}" 70 | if [[ "${#locs[@]}" -ge 2 ]]; then 71 | echo "${locs[1]}" 72 | mount "${locs[1]}" /mnt/config 73 | TEMP_FILE=$(mktemp /tmp/XXXXXX-config) 74 | cp /mnt/config/openstack/latest/user_data "${TEMP_FILE}" 75 | header=$(head -n1 "${TEMP_FILE}") 76 | echo "$header" 77 | if [[ "${header}" == "#!/bin/vbash" ]]; then 78 | execute_config_script "${TEMP_FILE}" 79 | elif [[ "${header}" == "#vyos-config" ]]; then 80 | merge_config_script "${TEMP_FILE}" 81 | fi 82 | umount /mnt/config 83 | rm -f "${TEMP_FILE}" 84 | else 85 | echo "WARNING: USER CONFIG not rendered. Invalid settings." 86 | fi 87 | $_exit 0 88 | fi 89 | 90 | if [[ "${USER_DATA}" == "http"* ]]; then 91 | tmpdata=$(mktemp /tmp/XXXXXX-user-data) 92 | /usr/bin/curl -m 3 -sf "${USER_DATA}" -o ${tmpdata} 93 | if [[ $? != 0 ]]; then 94 | echo "could not retrieve user-data from ${USER_DATA}" 95 | $_exit 1 96 | fi 97 | USER_DATA="${tmpdata}" 98 | fi 99 | 100 | header=$(head -n1 ${USER_DATA}) 101 | 102 | if [[ "${header}" == "#vyos-config" ]]; then 103 | echo "merging VyOS config..." 104 | merge_config_script "${USER_DATA}" 105 | elif [[ "${header}" == "#!/bin/vbash" ]]; then 106 | echo "running user script..." 107 | execute_config_script "${USER_DATA}" 108 | fi 109 | 110 | rm -f "${tmpdata}" 111 | --------------------------------------------------------------------------------