From 6d74afcd0e11de5cb56623d9121472e9212e8481 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 12:28:59 -0700 Subject: 1. Moving around the packages dir. 2. Adjusting the bddep shell script 3. Starting to add a brpm --- packages/bddeb | 62 +++++++++++++++++++++++++++++++++++++++++ packages/brpm | 3 ++ packages/debian.trunk/changelog | 5 ++++ packages/debian.trunk/compat | 1 + packages/debian.trunk/control | 31 +++++++++++++++++++++ packages/debian.trunk/copyright | 51 +++++++++++++++++++++++++++++++++ packages/debian.trunk/dirs | 5 ++++ packages/debian.trunk/pycompat | 1 + packages/debian.trunk/rules | 28 +++++++++++++++++++ packages/make-dist-tarball | 25 +++++++++++++++++ 10 files changed, 212 insertions(+) create mode 100755 packages/bddeb create mode 100755 packages/brpm create mode 100644 packages/debian.trunk/changelog create mode 100644 packages/debian.trunk/compat create mode 100644 packages/debian.trunk/control create mode 100644 packages/debian.trunk/copyright create mode 100644 packages/debian.trunk/dirs create mode 100644 packages/debian.trunk/pycompat create mode 100755 packages/debian.trunk/rules create mode 100755 packages/make-dist-tarball (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb new file mode 100755 index 00000000..74932985 --- /dev/null +++ b/packages/bddeb @@ -0,0 +1,62 @@ +#!/bin/sh + +# Ensure we can find the setup.py file which +# should be at the root of the cloud-init tree +PKG_DIR=`pwd` +ROOT="$PKG_DIR/../" +if [ ! -e "$ROOT/setup.py" ]; then + echo "No setup.py found at $ROOT" + exit 1 +fi +echo "Using root directory $ROOT for building your debian package" + +# Ensure tempdir is cleaned and ready to go +TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXXX") +echo "With $TEMP_D as a temporary workspace" +rm -Rf "${TEMP_D}"; mkdir "${TEMP_D}" +set -e + +# Ensure tempdir removed if breaks... +trap "rm -Rf '${TEMP_D}'" EXIT SIGINT SIGTERM + +# Go to the root and start making a package! +cd $ROOT +files=$(bzr ls --versioned) +revno=$(bzr revno) +version=$(awk -F: \ + '$1 ~ /[0-9][.][0-9]+[.][0-9]+/ { print $1 ; exit(0); }' ChangeLog ) + +# Ensure that the version found in 'Changelog' is the same in the python +# cloud-init version directory +py_version=$(python -c 'from cloudinit import version; import sys; \ +sys.stdout.write(version.version_string())') + +# Canonicalize the changelog version +ch_version=$(python -c "from distutils import version; import sys; \ +sys.stdout.write(str(version.StrictVersion('$version')));") + +if [ "$py_version" != "$ch_version" ]; then + echo "Cloud-init python version $py_version" \ + " != changelog version $ch_version" + echo "Please ensure they are the same!" + exit 1 +fi + +mkdir "${TEMP_D}/cloud-init" +otar="$TEMP_D/cloud-init_$version~bzr${revno}.orig.tar.gz" +tar -czf - ${files} > "$otar" +tar -C "${TEMP_D}/cloud-init" -xzf - < "$otar" + +if [ ! -d "${TEMP_D}/cloud-init/debian" ]; then + rsync -a $PKG_DIR/debian.trunk/ "${TEMP_D}/cloud-init/debian" +fi + +sed -i -e "s,VERSION,$version," -e "s,REVNO,bzr$revno," \ + "$TEMP_D/cloud-init/debian/changelog" + +cd "${TEMP_D}/cloud-init" +debuild "$@" +debname="cloud-init_${version}~bzr${revno}-1_all.deb" +mv "../$debname" "$PKG_DIR" +echo "Wrote $debname to $PKG_DIR" + diff --git a/packages/brpm b/packages/brpm new file mode 100755 index 00000000..829303ea --- /dev/null +++ b/packages/brpm @@ -0,0 +1,3 @@ +#!/bin/sh + + diff --git a/packages/debian.trunk/changelog b/packages/debian.trunk/changelog new file mode 100644 index 00000000..a36d00d6 --- /dev/null +++ b/packages/debian.trunk/changelog @@ -0,0 +1,5 @@ +cloud-init (VERSION~REVNO-1) UNRELEASED; urgency=low + + * build + + -- Scott Moser Fri, 16 Dec 2011 11:50:25 -0500 diff --git a/packages/debian.trunk/compat b/packages/debian.trunk/compat new file mode 100644 index 00000000..7ed6ff82 --- /dev/null +++ b/packages/debian.trunk/compat @@ -0,0 +1 @@ +5 diff --git a/packages/debian.trunk/control b/packages/debian.trunk/control new file mode 100644 index 00000000..f0dcef6a --- /dev/null +++ b/packages/debian.trunk/control @@ -0,0 +1,31 @@ +Source: cloud-init +Section: admin +Priority: extra +Maintainer: Scott Moser +Build-Depends: cdbs, + debhelper (>= 5.0.38), + python (>= 2.6.6-3~), + python-nose, + pyflakes, + pylint, + python-mocker, +XS-Python-Version: all +Standards-Version: 3.9.3 + +Package: cloud-init +Architecture: all +Depends: cloud-utils, + procps, + python, + python-boto (>=2.0), + python-cheetah, + python-configobj, + python-oauth, + python-software-properties, + python-yaml, + ${misc:Depends}, + ${python:Depends} +XB-Python-Version: ${python:Versions} +Description: Init scripts for cloud instances + Cloud instances need special scripts to run during initialisation + to retrieve and install ssh keys and to let the user run various scripts. diff --git a/packages/debian.trunk/copyright b/packages/debian.trunk/copyright new file mode 100644 index 00000000..dc993525 --- /dev/null +++ b/packages/debian.trunk/copyright @@ -0,0 +1,51 @@ +Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135 +Name: cloud-init +Maintainer: Scott Moser +Source: https://launchpad.net/cloud-init + +This package was debianized by Soren Hansen on +Thu, 04 Sep 2008 12:49:15 +0200 as ec2-init. It was later renamed to +cloud-utils by Scott Moser + +Upstream Author: Scott Moser + Soren Hansen + Chuck Short + +Copyright: 2010, Canonical Ltd. +License: GPL-3 + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, 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 . + + The complete text of the GPL version 3 can be seen in + /usr/share/common-licenses/GPL-3. + +Files: cloudinit/boto_utils.py +Copyright: 2006,2007, Mitch Garnaat http://garnaat.org/ +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, dis- + tribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the fol- + lowing conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT + SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. diff --git a/packages/debian.trunk/dirs b/packages/debian.trunk/dirs new file mode 100644 index 00000000..f3de468d --- /dev/null +++ b/packages/debian.trunk/dirs @@ -0,0 +1,5 @@ +var/lib/cloud +usr/bin +etc/init +usr/share/doc/cloud +etc/cloud diff --git a/packages/debian.trunk/pycompat b/packages/debian.trunk/pycompat new file mode 100644 index 00000000..0cfbf088 --- /dev/null +++ b/packages/debian.trunk/pycompat @@ -0,0 +1 @@ +2 diff --git a/packages/debian.trunk/rules b/packages/debian.trunk/rules new file mode 100755 index 00000000..0f79136c --- /dev/null +++ b/packages/debian.trunk/rules @@ -0,0 +1,28 @@ +#!/usr/bin/make -f + +DEB_PYTHON2_MODULE_PACKAGES = cloud-init + +binary-install/cloud-init::cloud-init-fixups + +include /usr/share/cdbs/1/rules/debhelper.mk +include /usr/share/cdbs/1/class/python-distutils.mk + +DEB_DH_INSTALL_SOURCEDIR := debian/tmp + +cloud-init-fixups: + for x in $(DEB_DESTDIR)/usr/bin/*.py; do mv "$$x" "$${x%.py}"; done + install -d $(DEB_DESTDIR)/etc/rsyslog.d + cp tools/21-cloudinit.conf $(DEB_DESTDIR)/etc/rsyslog.d/21-cloudinit.conf + +# You only need to run this immediately after checking out the package from +# revision control. +# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572204 +quilt-setup: + @[ ! -d .pc ] || { echo ".pc exists. remove it and re-run to start fresh"; exit 1; } + set -e; for patch in $$(quilt series | tac); do \ + patch -p1 -R --no-backup-if-mismatch <"debian/patches/$$patch"; \ + done + quilt push -a + +.PHONY: quilt-setup + diff --git a/packages/make-dist-tarball b/packages/make-dist-tarball new file mode 100755 index 00000000..622283bd --- /dev/null +++ b/packages/make-dist-tarball @@ -0,0 +1,25 @@ +#!/bin/sh + +Usage() { + cat <&2 ; exit 1; } + +tmpd=$(mktemp -d ); +trap "rm -Rf '${tmpd}'" 0 + +out=${topdir}/cloud-init-${tag}.tar.gz + +cd ${tmpd} && + bzr branch -r "tag:${tag}" "${topdir}" ./cloud-init-${tag} && + tar czf "${out}" cloud-init-${tag}/ --exclude cloud-init-${tag}/.bzr && + echo "Wrote ${out}" -- cgit v1.2.3 From a1402ec7346dc935cec1dc1a02eff3816d98ffc2 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 13:07:00 -0700 Subject: This will be a rpm template file for the eventual specfile that will be created. --- packages/brpm.tmpl | 173 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 packages/brpm.tmpl (limited to 'packages') diff --git a/packages/brpm.tmpl b/packages/brpm.tmpl new file mode 100644 index 00000000..141578a5 --- /dev/null +++ b/packages/brpm.tmpl @@ -0,0 +1,173 @@ +%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} + +Name: cloud-init +Version: {{version}} +Release: {{release}}%{?dist} +Summary: Cloud instance init scripts + +Group: System Environment/Base +License: GPLv3 +URL: http://launchpad.net/cloud-init + +Source0: %{name}-%{version}-bzr532.tar.gz + +BuildArch: noarch +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) + +BuildRequires: python-devel +BuildRequires: python-setuptools-devel +Requires: e2fsprogs +Requires: iproute +Requires: libselinux-python +Requires: net-tools +Requires: procps +Requires: python-boto +Requires: python-cheetah +Requires: python-configobj +Requires: PyYAML +Requires: rsyslog +Requires: shadow-utils +Requires: /usr/bin/run-parts +Requires(post): chkconfig +Requires(preun): chkconfig +Requires(postun): initscripts + +%description +Cloud-init is a set of init scripts for cloud instances. Cloud instances +need special scripts to run during initialization to retrieve and install +ssh keys and to let the user run various scripts. + + +%prep +%setup -q -n %{name}-%{version}-bzr532 +%patch0 -p0 +%patch1 -p0 +%patch2 -p1 +%patch3 -p1 + +cp -p %{SOURCE2} README.fedora + + +%build +%{__python} setup.py build + + +%install +rm -rf $RPM_BUILD_ROOT +%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT + +for x in $RPM_BUILD_ROOT/%{_bindir}/*.py; do mv "$x" "${x%.py}"; done +chmod +x $RPM_BUILD_ROOT/%{python_sitelib}/cloudinit/SshUtil.py +mkdir -p $RPM_BUILD_ROOT/%{_sharedstatedir}/cloud + +# We supply our own config file since our software differs from Ubuntu's. +cp -p %{SOURCE1} $RPM_BUILD_ROOT/%{_sysconfdir}/cloud/cloud.cfg + +# Note that /etc/rsyslog.d didn't exist by default until F15. +# el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420 +mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d +cp -p tools/21-cloudinit.conf $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf + +# Install the init scripts +install -p -D -m 755 %{SOURCE3} %{buildroot}%{_initrddir}/cloud-config +install -p -D -m 755 %{SOURCE4} %{buildroot}%{_initrddir}/cloud-final +install -p -D -m 755 %{SOURCE5} %{buildroot}%{_initrddir}/cloud-init +install -p -D -m 755 %{SOURCE6} %{buildroot}%{_initrddir}/cloud-init-local + + +%clean +rm -rf $RPM_BUILD_ROOT + + +%post +if [ $1 -eq 1 ] ; then + # Initial installation + # Enabled by default per "runs once then goes away" exception + for svc in config final init init-local; do + chkconfig --add cloud-$svc + chkconfig cloud-$svc on + done +fi + +%preun +if [ $1 -eq 0 ] ; then + # Package removal, not upgrade + for svc in config final init init-local; do + chkconfig --del cloud-$svc + chkconfig cloud-$svc on + done + # One-shot services -> no need to stop +fi + +%postun +# One-shot services -> no need to restart + + +%files +%doc ChangeLog LICENSE TODO README.fedora +%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg +%dir %{_sysconfdir}/cloud/cloud.cfg.d +%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg.d/*.cfg +%doc %{_sysconfdir}/cloud/cloud.cfg.d/README +%dir %{_sysconfdir}/cloud/templates +%config(noreplace) %{_sysconfdir}/cloud/templates/* +%{_initrddir}/cloud-* +%{python_sitelib}/* +%{_libexecdir}/%{name} +%{_bindir}/cloud-init* +%doc %{_datadir}/doc/%{name} +%dir %{_sharedstatedir}/cloud + +%config(noreplace) %{_sysconfdir}/rsyslog.d/21-cloudinit.conf + + +%changelog +* Mon Jun 18 2012 Pádraig Brady - 0.6.3-0.6.bzr532 +- Further adjustments to support EPEL 6 + +* Fri Jun 15 2012 Tomas Karasek - 0.6.3-0.5.bzr532 +- Fix cloud-init-cfg invocation in init script + +* Tue May 22 2012 Pádraig Brady - 0.6.3-0.4.bzr532 +- Support EPEL 6 + +* Sat Mar 31 2012 Andy Grimm - 0.6.3-0.2.bzr532 +- Fixed incorrect interpretation of relative path for + AuthorizedKeysFile (BZ #735521) + +* Mon Mar 5 2012 Garrett Holmstrom - 0.6.3-0.1.bzr532 +- Rebased against upstream rev 532 +- Fixed runparts() incompatibility with Fedora + +* Thu Jan 12 2012 Fedora Release Engineering - 0.6.2-0.8.bzr457 +- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild + +* Wed Oct 5 2011 Garrett Holmstrom - 0.6.2-0.7.bzr457 +- Disabled SSH key-deleting on startup + +* Wed Sep 28 2011 Garrett Holmstrom - 0.6.2-0.6.bzr457 +- Consolidated selinux file context patches +- Fixed cloud-init.service dependencies +- Updated sshkeytypes patch +- Dealt with differences from Ubuntu's sshd + +* Sat Sep 24 2011 Garrett Holmstrom - 0.6.2-0.5.bzr457 +- Rebased against upstream rev 457 +- Added missing dependencies + +* Fri Sep 23 2011 Garrett Holmstrom - 0.6.2-0.4.bzr450 +- Added more macros to the spec file + +* Fri Sep 23 2011 Garrett Holmstrom - 0.6.2-0.3.bzr450 +- Fixed logfile permission checking +- Fixed SSH key generation +- Fixed a bad method call in FQDN-guessing [LP:857891] +- Updated localefile patch +- Disabled the grub_dpkg module +- Fixed failures due to empty script dirs [LP:857926] + +* Fri Sep 23 2011 Garrett Holmstrom - 0.6.2-0.2.bzr450 +- Updated tzsysconfig patch + +* Wed Sep 21 2011 Garrett Holmstrom - 0.6.2-0.1.bzr450 +- Initial packaging -- cgit v1.2.3 From fcb055e3a58d50352e7c3f84fe42b8c71268b3b8 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 13:07:40 -0700 Subject: Use the new version extraction tool to get the current active version. --- packages/bddeb | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index 74932985..2a089295 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -23,24 +23,7 @@ trap "rm -Rf '${TEMP_D}'" EXIT SIGINT SIGTERM cd $ROOT files=$(bzr ls --versioned) revno=$(bzr revno) -version=$(awk -F: \ - '$1 ~ /[0-9][.][0-9]+[.][0-9]+/ { print $1 ; exit(0); }' ChangeLog ) - -# Ensure that the version found in 'Changelog' is the same in the python -# cloud-init version directory -py_version=$(python -c 'from cloudinit import version; import sys; \ -sys.stdout.write(version.version_string())') - -# Canonicalize the changelog version -ch_version=$(python -c "from distutils import version; import sys; \ -sys.stdout.write(str(version.StrictVersion('$version')));") - -if [ "$py_version" != "$ch_version" ]; then - echo "Cloud-init python version $py_version" \ - " != changelog version $ch_version" - echo "Please ensure they are the same!" - exit 1 -fi +version=$(tools/read-version) mkdir "${TEMP_D}/cloud-init" otar="$TEMP_D/cloud-init_$version~bzr${revno}.orig.tar.gz" -- cgit v1.2.3 From 41baae87ce4e24f296acc7f2448e3ad94e5cc1db Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 13:07:57 -0700 Subject: Continue working on getting a specfile generated. --- packages/brpm | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 829303ea..f2c3dac4 100755 --- a/packages/brpm +++ b/packages/brpm @@ -1,3 +1,45 @@ -#!/bin/sh +#!/usr/bin/python +# vi: ts=4 expandtab +import os +import subprocess +import sys +import tempfile +import re +import tempita + +# This is more just for running from the bin folder so that +# cloud-init binary can find the cloudinit module +possible_topdir = os.path.normpath(os.path.join(os.path.abspath( + sys.argv[0]), os.pardir, os.pardir)) +if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): + sys.path.insert(0, possible_topdir) + +PWD = os.getcwd() + +def info(msg): + sys.stderr.write("INFO: %s\n" % (msg)) + + +def warn(msg): + sys.stderr.write("WARNING: %s\n" % (msg)) + + +def main(): + if not os.path.isfile(os.path.join(PWD, 'brpm.tmpl')): + warn("Can not find required template file 'brpm.tmpl'") + return 1 + if not os.path.isfile(os.path.join(os.pardir, 'setup.py')): + warn("Can not find required root 'setup.py' file") + return 1 + + cmd = [os.path.join(os.pardir, 'tools', 'read-version')] + version = subprocess.check_Call(cmd) + + + return 0 + + +if __name__ == '__main__': + sys.exit(main()) -- cgit v1.2.3 From c36c782d3c3913611b86edeb7d371c54ced4b8bd Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 16:59:39 -0700 Subject: Get rpm building working with a template. --- packages/brpm | 270 +++++++++++++++++++++++++++++++++++++++++++++++++++-- packages/brpm.tmpl | 161 ++++++-------------------------- 2 files changed, 289 insertions(+), 142 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index f2c3dac4..5feade24 100755 --- a/packages/brpm +++ b/packages/brpm @@ -6,9 +6,19 @@ import subprocess import sys import tempfile import re +import textwrap +import shutil +import zipfile + +import glob import tempita +from datetime import datetime +from datetime import date + +from distutils import version as ver + # This is more just for running from the bin folder so that # cloud-init binary can find the cloudinit module possible_topdir = os.path.normpath(os.path.join(os.path.abspath( @@ -16,28 +26,268 @@ possible_topdir = os.path.normpath(os.path.join(os.path.abspath( if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): sys.path.insert(0, possible_topdir) +from cloudinit import util +from cloudinit import version + +import contextlib + +# Mapping of expected packages to there full name... +PKG_MP = { + 'boto': 'python-boto', + 'tempita': 'python-tempita', + 'prettytable': 'python-prettytable', + 'oauth': 'python-oauth', + 'configobj': 'python-configobj', + 'yaml': 'PyYAML', + 'argparse': 'python-argparse' +} + + +@contextlib.contextmanager +def chdir(where_to): + cur_cwd = os.path.abspath(os.getcwd()) + where_to = os.path.abspath(where_to) + os.chdir(where_to) + yield where_to + os.chdir(cur_cwd) + + PWD = os.getcwd() def info(msg): - sys.stderr.write("INFO: %s\n" % (msg)) + print("INFO: %s" % (msg)) def warn(msg): - sys.stderr.write("WARNING: %s\n" % (msg)) + print("WARNING: %s" % (msg)) -def main(): - if not os.path.isfile(os.path.join(PWD, 'brpm.tmpl')): - warn("Can not find required template file 'brpm.tmpl'") - return 1 - if not os.path.isfile(os.path.join(os.pardir, 'setup.py')): - warn("Can not find required root 'setup.py' file") - return 1 +def cut_up(entry, maxline=80): + if len(entry) < maxline: + return entry + else: + c = entry[0:maxline] + return "%s..." % (c) + + +def extract_entry(collecting): + a_entry = {} + for t in ['tags', 'revno', 'author', 'timestamp', 'committer']: + look_for = "%s:" % (t) + for v in collecting: + if v.startswith(look_for): + a_entry[t] = v[len(look_for):].strip() + break + i = -1 + for a, v in enumerate(collecting): + if v.startswith("message:"): + i = a + break + if i != -1: + msg_lines = collecting[i + 1:] + n_lines = [] + for m in msg_lines: + m = m.strip() + if not m: + continue + m = m.replace("\n", " ") + n_lines.append("" + m.lstrip()) + message = " ".join(n_lines).lstrip() + a_entry['message'] = message + return a_entry + + +def build_changelog(history=-1): + cmd = ['bzr', 'log', '--timezone=utc'] + (stdout, _stderr) = util.subp(cmd) + # Clean the format up + entries = stdout.splitlines() + all_entries = [] + collecting = [] + for e in entries: + if e.startswith("---"): + if collecting: + a_entry = extract_entry(collecting) + if a_entry: + all_entries.append(a_entry) + collecting = [] + else: + collecting.append(e) + a_entry = extract_entry(collecting) + if a_entry: + all_entries.append(a_entry) + + if history > 0: + take_entries = list(all_entries[0:history]) + else: + take_entries = list(all_entries) + + # Merge those with same date + date_entries = {} + for e in take_entries: + author = e.get('author') + if not author: + author = e.get('committer') + if not author: + continue + timestamp = e.get('timestamp') + if not timestamp: + continue + msg = e.get('message') + if not msg: + continue + revno = e.get('revno') + if not revno: + continue + # http://bugs.python.org/issue6641 + timestamp = timestamp.replace("+0000", '').strip() + ds = datetime.strptime(timestamp, '%a %Y-%m-%d %H:%M:%S') + c_ds = ds.date() + if c_ds not in date_entries: + ap_entry = {} + ap_entry['messages'] = [] + ap_entry['authors'] = [] + ap_entry['revnos'] = [] + date_entries[c_ds] = ap_entry + ap_entry = date_entries[c_ds] + ap_entry['messages'].append(msg) + ap_entry['authors'].append(author) + ap_entry['revnos'].append(revno) + + dates = sorted(date_entries.keys()) + chglog = [] + for ds in reversed(dates): + e = date_entries[ds] + authors = ", ".join(set(e['authors'])) + revnos = ", ".join(list(sorted(e['revnos']))) + top_line = "%s %s - %s" % (ds.strftime("%a %b %d %Y"), + authors, revnos) + chglog.append("* %s" % (top_line)) + for msg in e['messages']: + chglog.append("- %s" % (cut_up(msg))) + return "\n".join(chglog) + + +def generate_spec_contents(tmpl_fn): + # Version junk cmd = [os.path.join(os.pardir, 'tools', 'read-version')] - version = subprocess.check_Call(cmd) + (stdout, _stderr) = util.subp(cmd) + i_version = stdout.strip() + + # Ensure ok match! + if ver.StrictVersion(i_version) != version.version(): + raise RuntimeError("Version found does not match the code version") + + # Tmpl params + subs = {} + subs['version'] = i_version + (stdout, _stderr) = util.subp(['bzr', 'revno']) + subs['revno'] = "%s" % (stdout.strip()) + subs['release'] = "%s" % (subs['revno']) + subs['archive_name'] = '%{name}-%{version}-' + subs['revno'] + '.tar.gz' + subs['bd_requires'] = ['python-devel', 'python-setuptools'] + + requires = [] + cmd = [os.path.join(os.pardir, 'tools', 'read-dependencies')] + (stdout, _stderr) = util.subp(cmd) + pkgs = stdout.splitlines() + + # Map to known packages + for e in pkgs: + e = e.lower().strip() + tgt_pkg = None + for n in PKG_MP.keys(): + if e.find(n) != -1: + tgt_pkg = PKG_MP.get(n) + if not tgt_pkg: + raise RuntimeError(("Do not know how to translate %s to " + " a known package") % (e)) + else: + requires.append(tgt_pkg) + + base_name = 'cloud-init-%s-%s' % (i_version, subs['revno']) + subs['requires'] = requires + subs['changelog'] = build_changelog() + + # See: http://www.zarb.org/~jasonc/macros.php + # Pickup any special files + docs = [ + 'TODO', + 'LICENSE', + 'ChangeLog', + 'Requires', + '%{_defaultdocdir}/cloud-init/*', + ] + subs['docs'] = docs + configs = [ + 'cloud/cloud.cfg', + 'cloud/cloud.cfg.d/*.cfg', + 'cloud/cloud.cfg.d/README', + 'cloud/templates/*', + ] + subs['configs'] = configs + other_files = [ + '%{_bindir}/*', + '/usr/lib/cloud-init/*', + ] + subs['files'] = other_files + with open(tmpl_fn, 'r') as fh: + tmpl = tempita.Template(fh.read()) + contents = tmpl.substitute(**subs) + return (base_name, '%s.tar.gz' % (base_name), contents) + + +def main(): + root_dir = os.path.expanduser("~/rpmbuild") + info("Cleaning %s" % (root_dir)) + util.delete_dir_contents(root_dir) + arc_dir = os.path.join(root_dir, 'SOURCES') + util.ensure_dirs([root_dir, arc_dir]) + tmpl_fn = os.path.join(os.getcwd(), 'brpm.tmpl') + info("Generated spec file from template %s" % (tmpl_fn)) + (base_name, arc_name, contents) = generate_spec_contents(tmpl_fn) + spec_fn = os.path.join(root_dir, 'cloud-init.spec') + util.write_file(spec_fn, contents) + info("Wrote spec file to %s" % (spec_fn)) + with util.tempdir() as td: + src_dir = os.path.join(td, base_name) + os.makedirs(src_dir) + for fn in os.listdir(os.pardir): + if fn.startswith("."): + continue + full_fn = os.path.abspath(os.path.join(os.pardir, fn)) + if os.path.isfile(full_fn): + shutil.copy(full_fn, os.path.join(src_dir, fn)) + else: + shutil.copytree(full_fn, os.path.join(src_dir, fn), + ignore=shutil.ignore_patterns('*.pyc', + '.bzr', + 'tmp*', + '*bzr*')) + arc_fn = os.path.join(arc_dir, arc_name) + cmd = ['tar', '-zcvf', arc_fn, '-C', td] + cmd.extend(os.listdir(td)) + util.subp(cmd) + info("Archived code at %s" % (arc_fn)) + cmd = ['rpmbuild', '-ba', spec_fn] + info("Running rpmbuild %s" % (cmd)) + util.subp(cmd) + info("Rpmbuild completed!") + globs = [] + globs.extend(glob.glob("%s/*.rpm" % + (os.path.join(root_dir, 'RPMS', 'noarch')))) + globs.extend(glob.glob("%s/*.rpm" % + (os.path.join(root_dir, 'RPMS')))) + globs.extend(glob.glob("%s/*.rpm" % + (os.path.join(root_dir, 'SRPMS')))) + for fn in globs: + n = os.path.basename(fn) + tgt_fn = os.path.join(os.getcwd(), n) + util.copy(fn, tgt_fn) + info("Copied %s to %s" % (n, tgt_fn)) return 0 diff --git a/packages/brpm.tmpl b/packages/brpm.tmpl index 141578a5..f0c874ee 100644 --- a/packages/brpm.tmpl +++ b/packages/brpm.tmpl @@ -9,28 +9,21 @@ Group: System Environment/Base License: GPLv3 URL: http://launchpad.net/cloud-init -Source0: %{name}-%{version}-bzr532.tar.gz +Source0: {{archive_name}} BuildArch: noarch -BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) - -BuildRequires: python-devel -BuildRequires: python-setuptools-devel -Requires: e2fsprogs -Requires: iproute -Requires: libselinux-python -Requires: net-tools -Requires: procps -Requires: python-boto -Requires: python-cheetah -Requires: python-configobj -Requires: PyYAML -Requires: rsyslog -Requires: shadow-utils -Requires: /usr/bin/run-parts -Requires(post): chkconfig -Requires(preun): chkconfig -Requires(postun): initscripts + +BuildRoot: %{_tmppath} + + +{{for r in bd_requires}} +BuildRequires: {{r}} +{{endfor}} + +# Install requirements +{{for r in requires}} +Requires: {{r}} +{{endfor}} %description Cloud-init is a set of init scripts for cloud instances. Cloud instances @@ -39,14 +32,7 @@ ssh keys and to let the user run various scripts. %prep -%setup -q -n %{name}-%{version}-bzr532 -%patch0 -p0 -%patch1 -p0 -%patch2 -p1 -%patch3 -p1 - -cp -p %{SOURCE2} README.fedora - +%setup -q -n %{name}-%{version}-{{revno}} %build %{__python} setup.py build @@ -56,118 +42,29 @@ cp -p %{SOURCE2} README.fedora rm -rf $RPM_BUILD_ROOT %{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT -for x in $RPM_BUILD_ROOT/%{_bindir}/*.py; do mv "$x" "${x%.py}"; done -chmod +x $RPM_BUILD_ROOT/%{python_sitelib}/cloudinit/SshUtil.py -mkdir -p $RPM_BUILD_ROOT/%{_sharedstatedir}/cloud - -# We supply our own config file since our software differs from Ubuntu's. -cp -p %{SOURCE1} $RPM_BUILD_ROOT/%{_sysconfdir}/cloud/cloud.cfg - -# Note that /etc/rsyslog.d didn't exist by default until F15. -# el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420 -mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d -cp -p tools/21-cloudinit.conf $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf - -# Install the init scripts -install -p -D -m 755 %{SOURCE3} %{buildroot}%{_initrddir}/cloud-config -install -p -D -m 755 %{SOURCE4} %{buildroot}%{_initrddir}/cloud-final -install -p -D -m 755 %{SOURCE5} %{buildroot}%{_initrddir}/cloud-init -install -p -D -m 755 %{SOURCE6} %{buildroot}%{_initrddir}/cloud-init-local - - %clean rm -rf $RPM_BUILD_ROOT +%files -%post -if [ $1 -eq 1 ] ; then - # Initial installation - # Enabled by default per "runs once then goes away" exception - for svc in config final init init-local; do - chkconfig --add cloud-$svc - chkconfig cloud-$svc on - done -fi - -%preun -if [ $1 -eq 0 ] ; then - # Package removal, not upgrade - for svc in config final init init-local; do - chkconfig --del cloud-$svc - chkconfig cloud-$svc on - done - # One-shot services -> no need to stop -fi +# Docs +{{for r in docs}} +%doc {{r}} +{{endfor}} -%postun -# One-shot services -> no need to restart +# Configs +{{for r in configs}} +%config(noreplace) %{_sysconfdir}/{{r}} +{{endfor}} +# Other files +{{for r in files}} +{{r}} +{{endfor}} -%files -%doc ChangeLog LICENSE TODO README.fedora -%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg -%dir %{_sysconfdir}/cloud/cloud.cfg.d -%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg.d/*.cfg -%doc %{_sysconfdir}/cloud/cloud.cfg.d/README -%dir %{_sysconfdir}/cloud/templates -%config(noreplace) %{_sysconfdir}/cloud/templates/* -%{_initrddir}/cloud-* +# Python sitelib %{python_sitelib}/* -%{_libexecdir}/%{name} -%{_bindir}/cloud-init* -%doc %{_datadir}/doc/%{name} -%dir %{_sharedstatedir}/cloud - -%config(noreplace) %{_sysconfdir}/rsyslog.d/21-cloudinit.conf - %changelog -* Mon Jun 18 2012 Pádraig Brady - 0.6.3-0.6.bzr532 -- Further adjustments to support EPEL 6 - -* Fri Jun 15 2012 Tomas Karasek - 0.6.3-0.5.bzr532 -- Fix cloud-init-cfg invocation in init script - -* Tue May 22 2012 Pádraig Brady - 0.6.3-0.4.bzr532 -- Support EPEL 6 - -* Sat Mar 31 2012 Andy Grimm - 0.6.3-0.2.bzr532 -- Fixed incorrect interpretation of relative path for - AuthorizedKeysFile (BZ #735521) - -* Mon Mar 5 2012 Garrett Holmstrom - 0.6.3-0.1.bzr532 -- Rebased against upstream rev 532 -- Fixed runparts() incompatibility with Fedora - -* Thu Jan 12 2012 Fedora Release Engineering - 0.6.2-0.8.bzr457 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild - -* Wed Oct 5 2011 Garrett Holmstrom - 0.6.2-0.7.bzr457 -- Disabled SSH key-deleting on startup - -* Wed Sep 28 2011 Garrett Holmstrom - 0.6.2-0.6.bzr457 -- Consolidated selinux file context patches -- Fixed cloud-init.service dependencies -- Updated sshkeytypes patch -- Dealt with differences from Ubuntu's sshd - -* Sat Sep 24 2011 Garrett Holmstrom - 0.6.2-0.5.bzr457 -- Rebased against upstream rev 457 -- Added missing dependencies - -* Fri Sep 23 2011 Garrett Holmstrom - 0.6.2-0.4.bzr450 -- Added more macros to the spec file - -* Fri Sep 23 2011 Garrett Holmstrom - 0.6.2-0.3.bzr450 -- Fixed logfile permission checking -- Fixed SSH key generation -- Fixed a bad method call in FQDN-guessing [LP:857891] -- Updated localefile patch -- Disabled the grub_dpkg module -- Fixed failures due to empty script dirs [LP:857926] - -* Fri Sep 23 2011 Garrett Holmstrom - 0.6.2-0.2.bzr450 -- Updated tzsysconfig patch -* Wed Sep 21 2011 Garrett Holmstrom - 0.6.2-0.1.bzr450 -- Initial packaging +{{changelog}} -- cgit v1.2.3 From b91062834960e17ac053bc47db020df3b5c5102e Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 17:01:41 -0700 Subject: Ensure rpmbuild is actually a directory before cleaning --- packages/brpm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 5feade24..c11b86ff 100755 --- a/packages/brpm +++ b/packages/brpm @@ -243,7 +243,8 @@ def generate_spec_contents(tmpl_fn): def main(): root_dir = os.path.expanduser("~/rpmbuild") info("Cleaning %s" % (root_dir)) - util.delete_dir_contents(root_dir) + if os.path.isdir(root_dir): + util.delete_dir_contents(root_dir) arc_dir = os.path.join(root_dir, 'SOURCES') util.ensure_dirs([root_dir, arc_dir]) tmpl_fn = os.path.join(os.getcwd(), 'brpm.tmpl') -- cgit v1.2.3 From f39263c3a9e6e4afd01b48724e5a8054a1b456f8 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 18:50:29 -0700 Subject: Add a nicer helper util for the rpm changelog --- packages/brpm | 145 ++++---------------------------- packages/rpm-changelog | 220 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+), 130 deletions(-) create mode 100755 packages/rpm-changelog (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index c11b86ff..cc9325cb 100755 --- a/packages/brpm +++ b/packages/brpm @@ -2,21 +2,13 @@ # vi: ts=4 expandtab import os -import subprocess import sys -import tempfile -import re -import textwrap import shutil -import zipfile import glob import tempita -from datetime import datetime -from datetime import date - from distutils import version as ver # This is more just for running from the bin folder so that @@ -29,8 +21,6 @@ if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): from cloudinit import util from cloudinit import version -import contextlib - # Mapping of expected packages to there full name... PKG_MP = { 'boto': 'python-boto', @@ -43,17 +33,6 @@ PKG_MP = { } -@contextlib.contextmanager -def chdir(where_to): - cur_cwd = os.path.abspath(os.getcwd()) - where_to = os.path.abspath(where_to) - os.chdir(where_to) - yield where_to - os.chdir(cur_cwd) - - -PWD = os.getcwd() - def info(msg): print("INFO: %s" % (msg)) @@ -62,114 +41,8 @@ def warn(msg): print("WARNING: %s" % (msg)) -def cut_up(entry, maxline=80): - if len(entry) < maxline: - return entry - else: - c = entry[0:maxline] - return "%s..." % (c) - - -def extract_entry(collecting): - a_entry = {} - for t in ['tags', 'revno', 'author', 'timestamp', 'committer']: - look_for = "%s:" % (t) - for v in collecting: - if v.startswith(look_for): - a_entry[t] = v[len(look_for):].strip() - break - i = -1 - for a, v in enumerate(collecting): - if v.startswith("message:"): - i = a - break - if i != -1: - msg_lines = collecting[i + 1:] - n_lines = [] - for m in msg_lines: - m = m.strip() - if not m: - continue - m = m.replace("\n", " ") - n_lines.append("" + m.lstrip()) - message = " ".join(n_lines).lstrip() - a_entry['message'] = message - return a_entry - - -def build_changelog(history=-1): - cmd = ['bzr', 'log', '--timezone=utc'] - (stdout, _stderr) = util.subp(cmd) - # Clean the format up - entries = stdout.splitlines() - all_entries = [] - collecting = [] - for e in entries: - if e.startswith("---"): - if collecting: - a_entry = extract_entry(collecting) - if a_entry: - all_entries.append(a_entry) - collecting = [] - else: - collecting.append(e) - - a_entry = extract_entry(collecting) - if a_entry: - all_entries.append(a_entry) - - if history > 0: - take_entries = list(all_entries[0:history]) - else: - take_entries = list(all_entries) - - # Merge those with same date - date_entries = {} - for e in take_entries: - author = e.get('author') - if not author: - author = e.get('committer') - if not author: - continue - timestamp = e.get('timestamp') - if not timestamp: - continue - msg = e.get('message') - if not msg: - continue - revno = e.get('revno') - if not revno: - continue - # http://bugs.python.org/issue6641 - timestamp = timestamp.replace("+0000", '').strip() - ds = datetime.strptime(timestamp, '%a %Y-%m-%d %H:%M:%S') - c_ds = ds.date() - if c_ds not in date_entries: - ap_entry = {} - ap_entry['messages'] = [] - ap_entry['authors'] = [] - ap_entry['revnos'] = [] - date_entries[c_ds] = ap_entry - ap_entry = date_entries[c_ds] - ap_entry['messages'].append(msg) - ap_entry['authors'].append(author) - ap_entry['revnos'].append(revno) - - dates = sorted(date_entries.keys()) - chglog = [] - for ds in reversed(dates): - e = date_entries[ds] - authors = ", ".join(set(e['authors'])) - revnos = ", ".join(list(sorted(e['revnos']))) - top_line = "%s %s - %s" % (ds.strftime("%a %b %d %Y"), - authors, revnos) - chglog.append("* %s" % (top_line)) - for msg in e['messages']: - chglog.append("- %s" % (cut_up(msg))) - return "\n".join(chglog) - - def generate_spec_contents(tmpl_fn): + # Version junk cmd = [os.path.join(os.pardir, 'tools', 'read-version')] (stdout, _stderr) = util.subp(cmd) @@ -208,10 +81,11 @@ def generate_spec_contents(tmpl_fn): base_name = 'cloud-init-%s-%s' % (i_version, subs['revno']) subs['requires'] = requires - subs['changelog'] = build_changelog() + + (stdout, _stderr) = util.subp(['rpm-changelog']) + subs['changelog'] = stdout # See: http://www.zarb.org/~jasonc/macros.php - # Pickup any special files docs = [ 'TODO', @@ -241,18 +115,24 @@ def generate_spec_contents(tmpl_fn): def main(): + + # Clean out the root dir and make sure the dirs we want are in place root_dir = os.path.expanduser("~/rpmbuild") info("Cleaning %s" % (root_dir)) if os.path.isdir(root_dir): util.delete_dir_contents(root_dir) arc_dir = os.path.join(root_dir, 'SOURCES') util.ensure_dirs([root_dir, arc_dir]) + + # Form the spec file to be used tmpl_fn = os.path.join(os.getcwd(), 'brpm.tmpl') info("Generated spec file from template %s" % (tmpl_fn)) (base_name, arc_name, contents) = generate_spec_contents(tmpl_fn) spec_fn = os.path.join(root_dir, 'cloud-init.spec') util.write_file(spec_fn, contents) info("Wrote spec file to %s" % (spec_fn)) + + # Archive the code and files that we want to with util.tempdir() as td: src_dir = os.path.join(td, base_name) os.makedirs(src_dir) @@ -273,10 +153,14 @@ def main(): cmd.extend(os.listdir(td)) util.subp(cmd) info("Archived code at %s" % (arc_fn)) + + # Now build it! cmd = ['rpmbuild', '-ba', spec_fn] info("Running rpmbuild %s" % (cmd)) util.subp(cmd) info("Rpmbuild completed!") + + # Copy the items built to our local dir globs = [] globs.extend(glob.glob("%s/*.rpm" % (os.path.join(root_dir, 'RPMS', 'noarch')))) @@ -289,6 +173,7 @@ def main(): tgt_fn = os.path.join(os.getcwd(), n) util.copy(fn, tgt_fn) info("Copied %s to %s" % (n, tgt_fn)) + return 0 diff --git a/packages/rpm-changelog b/packages/rpm-changelog new file mode 100755 index 00000000..80db94c5 --- /dev/null +++ b/packages/rpm-changelog @@ -0,0 +1,220 @@ +#!/usr/bin/python +# vi: ts=4 expandtab + +import sys +import os +import re + +import textwrap + +from datetime import datetime +from datetime import date + +import subprocess + +def tiny_p(cmd): + sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, stdin=None) + (out, err) = sp.communicate() + return (out, err) + +# This util converts a bzr log into a useful rpm changelog + +def cut_up(entry, maxline=80): + if len(entry) < maxline: + return entry + else: + c = entry[0:maxline] + return "%s..." % (c) + + +def adj_iter(elems): + if not elems: + raise StopIteration() + curr = elems[0] + yield curr + for i in range(1, len(elems)): + e = elems[i] + if e != curr: + yield e + curr = e + +def extract_entry(collecting): + a_entry = {} + for t in ['tags', 'revno', 'author', 'timestamp', 'committer']: + look_for = "%s:" % (t) + for v in collecting: + if v.startswith(look_for): + a_entry[t] = v[len(look_for):].strip() + break + i = -1 + for a, v in enumerate(collecting): + if v.startswith("message:"): + i = a + break + if i != -1: + msg_lines = collecting[i + 1:] + a_entry['message'] = "\n".join(msg_lines) + return a_entry + + +def clean_authors(authors): + if not authors: + return '' + auth_cleaned = set() + for a in authors: + a = a.strip() + if a: + auth_cleaned.add(a) + if not auth_cleaned: + return '' + uniq_authors = list(auth_cleaned) + if len(uniq_authors) == 1: + return authors[0] + auths = "(%s)" % ", ".join(uniq_authors) + return auths + + +def clean_revnos(revnos): + novs = list() + for r in revnos: + r = r.strip() + r = r.replace("[merge]", "") + if r: + novs.append(int(r)) + entries = list(novs) + if not entries: + return '' + entries.sort() + if len(entries) == 1: + return "%s" % (entries[0]) + + # Check if consecutive + start = entries[0] + consec = True + for (i, v) in enumerate(entries): + if v != start + i: + consec = False + break + if consec: + end = entries[-1] + return "%s => %s" % (start, end) + v = [str(b) for b in entries] + return ", ".join(v) + + +def spacey(am): + return " " * am + + +def justify(text, space_wanted): + c_bef = len(text) + t_c = len(text.lstrip()) + space_am = (c_bef - t_c) + needed = (space_wanted - space_am) + if needed < 0: + return text + return (" " * (needed) + text) + + +def clean_messages(messages): + contents = [] + for msg in messages: + # Split into sub-messages... + # if we can + lines = [] + pieces = msg.splitlines() + if len(pieces) == 1: + lines.append("%s- %s " % + (spacey(4), msg.strip())) + else: + n_lines = [] + n_lines.append(pieces[0].strip()) + for line in pieces[1:]: + line = line.lstrip() + if not line: + continue + n_lines.append(justify(line, 6)) + lines.append("%s- %s" % (spacey(4), "\n".join(n_lines))) + contents.extend(lines) + return "\n".join(contents) + + +def build_changelog(history=-1): + cmd = ['bzr', 'log', '--timezone=utc'] + (stdout, _stderr) = tiny_p(cmd) + # Clean the format up + entries = stdout.splitlines() + all_entries = [] + collecting = [] + for e in entries: + if e.startswith("---"): + if collecting: + a_entry = extract_entry(collecting) + if a_entry: + all_entries.append(a_entry) + collecting = [] + else: + collecting.append(e) + + a_entry = extract_entry(collecting) + if a_entry: + all_entries.append(a_entry) + + if history > 0: + take_entries = list(all_entries[0:history]) + else: + take_entries = list(all_entries) + + # Merge those with same date + date_entries = {} + for e in take_entries: + author = e.get('author') + if not author: + author = e.get('committer') + if not author: + continue + timestamp = e.get('timestamp') + if not timestamp: + continue + msg = e.get('message') + if not msg: + continue + revno = e.get('revno') + if not revno: + continue + # http://bugs.python.org/issue6641 + timestamp = timestamp.replace("+0000", '').strip() + ds = datetime.strptime(timestamp, '%a %Y-%m-%d %H:%M:%S') + c_ds = ds.date() + if c_ds not in date_entries: + ap_entry = {} + ap_entry['messages'] = [] + ap_entry['authors'] = [] + ap_entry['revnos'] = [] + date_entries[c_ds] = ap_entry + ap_entry = date_entries[c_ds] + ap_entry['messages'].append(msg) + ap_entry['authors'].append(author) + ap_entry['revnos'].append(revno) + + dates = sorted(date_entries.keys()) + chglog = [] + for ds in reversed(dates): + e = date_entries[ds] + authors = clean_authors(e['authors']) + revnos = clean_revnos(e['revnos']) + top_line = "%s %s - %s" % (ds.strftime("%a %b %d %Y"), + authors, revnos) + chglog.append("* %s" % (top_line)) + chglog.append(clean_messages(e['messages'])) + return "\n".join(chglog) + + +if __name__ == '__main__': + args = sys.argv[1:] + history_am = -1 + if args: + history_am = int(args[0]) + chglog = build_changelog(history_am) + print chglog -- cgit v1.2.3 From d8d27efa2675fd18927791574862ce4cad5082e9 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 18:53:51 -0700 Subject: Fix call to rpm-changelog --- packages/brpm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index cc9325cb..50ac4467 100755 --- a/packages/brpm +++ b/packages/brpm @@ -82,7 +82,7 @@ def generate_spec_contents(tmpl_fn): base_name = 'cloud-init-%s-%s' % (i_version, subs['revno']) subs['requires'] = requires - (stdout, _stderr) = util.subp(['rpm-changelog']) + (stdout, _stderr) = util.subp([os.path.join(os.getcwd(), 'rpm-changelog')]) subs['changelog'] = stdout # See: http://www.zarb.org/~jasonc/macros.php -- cgit v1.2.3 From 29d581c6ffaaf82f331401382753642e8a05fda5 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 20:29:32 -0700 Subject: Remove need to depend on cloudinit for the util functions used --- packages/brpm | 78 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 32 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 50ac4467..c989892e 100755 --- a/packages/brpm +++ b/packages/brpm @@ -1,25 +1,15 @@ #!/usr/bin/python -# vi: ts=4 expandtab +import contextlib +import glob import os -import sys import shutil - -import glob +import subprocess +import sys +import tempfile import tempita -from distutils import version as ver - -# This is more just for running from the bin folder so that -# cloud-init binary can find the cloudinit module -possible_topdir = os.path.normpath(os.path.join(os.path.abspath( - sys.argv[0]), os.pardir, os.pardir)) -if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): - sys.path.insert(0, possible_topdir) - -from cloudinit import util -from cloudinit import version # Mapping of expected packages to there full name... PKG_MP = { @@ -33,6 +23,31 @@ PKG_MP = { } +@contextlib.contextmanager +def tmpdir(): + t = tempfile.mkdtemp() + try: + yield t + finally: + shutil.rmtree(t) + + +def join(*paths): + p = os.path.join(*paths) + return os.path.abspath(p) + + +def tiny_p(cmd): + # Darn python 2.6 doesn't have check_output (argggg) + info("Running %s" % (cmd)) + sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, stdin=None) + (out, err) = sp.communicate() + if sp.returncode not in [0]: + raise RuntimeError("Failed running %s [rc=%s]" % (cmd, sp.returncode)) + return (out, err) + + def info(msg): print("INFO: %s" % (msg)) @@ -44,26 +59,22 @@ def warn(msg): def generate_spec_contents(tmpl_fn): # Version junk - cmd = [os.path.join(os.pardir, 'tools', 'read-version')] - (stdout, _stderr) = util.subp(cmd) + cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')] + (stdout, _stderr) = tiny_p(cmd) i_version = stdout.strip() - # Ensure ok match! - if ver.StrictVersion(i_version) != version.version(): - raise RuntimeError("Version found does not match the code version") - # Tmpl params subs = {} subs['version'] = i_version - (stdout, _stderr) = util.subp(['bzr', 'revno']) + (stdout, _stderr) = tiny_p(['bzr', 'revno']) subs['revno'] = "%s" % (stdout.strip()) subs['release'] = "%s" % (subs['revno']) subs['archive_name'] = '%{name}-%{version}-' + subs['revno'] + '.tar.gz' subs['bd_requires'] = ['python-devel', 'python-setuptools'] requires = [] - cmd = [os.path.join(os.pardir, 'tools', 'read-dependencies')] - (stdout, _stderr) = util.subp(cmd) + cmd = [sys.executable, join(os.pardir, 'tools', 'read-dependencies')] + (stdout, _stderr) = tiny_p(cmd) pkgs = stdout.splitlines() # Map to known packages @@ -82,7 +93,8 @@ def generate_spec_contents(tmpl_fn): base_name = 'cloud-init-%s-%s' % (i_version, subs['revno']) subs['requires'] = requires - (stdout, _stderr) = util.subp([os.path.join(os.getcwd(), 'rpm-changelog')]) + (stdout, _stderr) = tiny_p([sys.executable, + join(os.getcwd(), 'rpm-changelog')]) subs['changelog'] = stdout # See: http://www.zarb.org/~jasonc/macros.php @@ -120,20 +132,22 @@ def main(): root_dir = os.path.expanduser("~/rpmbuild") info("Cleaning %s" % (root_dir)) if os.path.isdir(root_dir): - util.delete_dir_contents(root_dir) + shutil.rmtree(root_dir) arc_dir = os.path.join(root_dir, 'SOURCES') - util.ensure_dirs([root_dir, arc_dir]) + for d in [root_dir, arc_dir]: + os.makedirs(d) # Form the spec file to be used tmpl_fn = os.path.join(os.getcwd(), 'brpm.tmpl') info("Generated spec file from template %s" % (tmpl_fn)) (base_name, arc_name, contents) = generate_spec_contents(tmpl_fn) spec_fn = os.path.join(root_dir, 'cloud-init.spec') - util.write_file(spec_fn, contents) - info("Wrote spec file to %s" % (spec_fn)) + with open(spec_fn, 'w') as fh: + fh.write(contents) + info("Wrote spec file to %s" % (spec_fn)) # Archive the code and files that we want to - with util.tempdir() as td: + with tmpdir() as td: src_dir = os.path.join(td, base_name) os.makedirs(src_dir) for fn in os.listdir(os.pardir): @@ -151,13 +165,13 @@ def main(): arc_fn = os.path.join(arc_dir, arc_name) cmd = ['tar', '-zcvf', arc_fn, '-C', td] cmd.extend(os.listdir(td)) - util.subp(cmd) + tiny_p(cmd) info("Archived code at %s" % (arc_fn)) # Now build it! cmd = ['rpmbuild', '-ba', spec_fn] info("Running rpmbuild %s" % (cmd)) - util.subp(cmd) + tiny_p(cmd) info("Rpmbuild completed!") # Copy the items built to our local dir -- cgit v1.2.3 From b8cbd5d2541cc4d591d818b6f1df4cae2230e29b Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 20:29:58 -0700 Subject: Some cleanups around util functions and formatting --- packages/rpm-changelog | 79 ++++++++++++++++++++++---------------------------- 1 file changed, 35 insertions(+), 44 deletions(-) (limited to 'packages') diff --git a/packages/rpm-changelog b/packages/rpm-changelog index 80db94c5..8acaa5b9 100755 --- a/packages/rpm-changelog +++ b/packages/rpm-changelog @@ -1,61 +1,49 @@ #!/usr/bin/python # vi: ts=4 expandtab -import sys +# A crappy little script +# that changes bzr 'log' +# into someting that rpm spec files can use (best effort) + import os import re - -import textwrap +import sys from datetime import datetime from datetime import date import subprocess +E_TYPES = ['tags', 'revno', 'author', 'timestamp', 'committer'] + + def tiny_p(cmd): + # Darn python 2.6 doesn't have check_output (argggg) sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=None) (out, err) = sp.communicate() return (out, err) -# This util converts a bzr log into a useful rpm changelog - -def cut_up(entry, maxline=80): - if len(entry) < maxline: - return entry - else: - c = entry[0:maxline] - return "%s..." % (c) - - -def adj_iter(elems): - if not elems: - raise StopIteration() - curr = elems[0] - yield curr - for i in range(1, len(elems)): - e = elems[i] - if e != curr: - yield e - curr = e def extract_entry(collecting): - a_entry = {} - for t in ['tags', 'revno', 'author', 'timestamp', 'committer']: + entry = {} + for t in E_TYPES: look_for = "%s:" % (t) for v in collecting: if v.startswith(look_for): - a_entry[t] = v[len(look_for):].strip() + entry[t] = v[len(look_for):].strip() break i = -1 + # Messages seem to be the last element so suck + # those all up for a, v in enumerate(collecting): if v.startswith("message:"): i = a break if i != -1: msg_lines = collecting[i + 1:] - a_entry['message'] = "\n".join(msg_lines) - return a_entry + entry['message'] = "\n".join(msg_lines) + return entry def clean_authors(authors): @@ -143,6 +131,7 @@ def clean_messages(messages): def build_changelog(history=-1): cmd = ['bzr', 'log', '--timezone=utc'] (stdout, _stderr) = tiny_p(cmd) + # Clean the format up entries = stdout.splitlines() all_entries = [] @@ -157,9 +146,10 @@ def build_changelog(history=-1): else: collecting.append(e) - a_entry = extract_entry(collecting) - if a_entry: - all_entries.append(a_entry) + # Anything that we left behind?? + entry = extract_entry(collecting) + if entry: + all_entries.append(entry) if history > 0: take_entries = list(all_entries[0:history]) @@ -186,25 +176,26 @@ def build_changelog(history=-1): # http://bugs.python.org/issue6641 timestamp = timestamp.replace("+0000", '').strip() ds = datetime.strptime(timestamp, '%a %Y-%m-%d %H:%M:%S') - c_ds = ds.date() - if c_ds not in date_entries: - ap_entry = {} - ap_entry['messages'] = [] - ap_entry['authors'] = [] - ap_entry['revnos'] = [] - date_entries[c_ds] = ap_entry - ap_entry = date_entries[c_ds] - ap_entry['messages'].append(msg) - ap_entry['authors'].append(author) - ap_entry['revnos'].append(revno) - + ds = ds.date() + if ds not in date_entries: + entry = {} + entry['messages'] = [] + entry['authors'] = [] + entry['revnos'] = [] + date_entries[ds] = entry + entry = date_entries[ds] + entry['messages'].append(msg) + entry['authors'].append(author) + entry['revnos'].append(revno) + + # It wants them in chronological order... dates = sorted(date_entries.keys()) chglog = [] for ds in reversed(dates): e = date_entries[ds] authors = clean_authors(e['authors']) revnos = clean_revnos(e['revnos']) - top_line = "%s %s - %s" % (ds.strftime("%a %b %d %Y"), + top_line = "%s %s - [revison %s]" % (ds.strftime("%a %b %d %Y"), authors, revnos) chglog.append("* %s" % (top_line)) chglog.append(clean_messages(e['messages'])) -- cgit v1.2.3 From ed6dadf73545aec8bd31ec6a51f7a93be4cb95f3 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 21:04:38 -0700 Subject: Continue working on cleaning this up --- packages/brpm | 60 +++++++++++++++++++++++------------------------------- packages/brpm.tmpl | 2 +- 2 files changed, 26 insertions(+), 36 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index c989892e..241f08fd 100755 --- a/packages/brpm +++ b/packages/brpm @@ -44,7 +44,8 @@ def tiny_p(cmd): stderr=subprocess.PIPE, stdin=None) (out, err) = sp.communicate() if sp.returncode not in [0]: - raise RuntimeError("Failed running %s [rc=%s]" % (cmd, sp.returncode)) + raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" + % (cmd, sp.returncode, out, err)) return (out, err) @@ -56,19 +57,13 @@ def warn(msg): print("WARNING: %s" % (msg)) -def generate_spec_contents(tmpl_fn): - - # Version junk - cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')] - (stdout, _stderr) = tiny_p(cmd) - i_version = stdout.strip() +def generate_spec_contents(tmpl_fn, revno, version): # Tmpl params subs = {} - subs['version'] = i_version - (stdout, _stderr) = tiny_p(['bzr', 'revno']) - subs['revno'] = "%s" % (stdout.strip()) - subs['release'] = "%s" % (subs['revno']) + subs['version'] = version + subs['revno'] = revno + subs['release'] = revno subs['archive_name'] = '%{name}-%{version}-' + subs['revno'] + '.tar.gz' subs['bd_requires'] = ['python-devel', 'python-setuptools'] @@ -90,7 +85,7 @@ def generate_spec_contents(tmpl_fn): else: requires.append(tgt_pkg) - base_name = 'cloud-init-%s-%s' % (i_version, subs['revno']) + base_name = 'cloud-init-%s-%s' % (version, subs['revno']) subs['requires'] = requires (stdout, _stderr) = tiny_p([sys.executable, @@ -126,6 +121,16 @@ def generate_spec_contents(tmpl_fn): return (base_name, '%s.tar.gz' % (base_name), contents) +def archive_code(): + (stdout, _stderr) = tiny_p([sys.executable, + join(os.getcwd(), 'tar-me')]) + lines = stdout.splitlines() + revno = lines[0] + version = lines[1] + arc_fn = lines[2] + return (revno, version, arc_fn) + + def main(): # Clean out the root dir and make sure the dirs we want are in place @@ -136,38 +141,23 @@ def main(): arc_dir = os.path.join(root_dir, 'SOURCES') for d in [root_dir, arc_dir]: os.makedirs(d) + + # Archive the code + (revno, version, archive_fn) = archive_code() + real_archive_fn = os.path.join(arc_dir, os.path.basename(archive_fn)) + shutil.copy(archive_fn, real_archive_fn) + info("Archived code to %s" % (real_archive_fn)) # Form the spec file to be used tmpl_fn = os.path.join(os.getcwd(), 'brpm.tmpl') info("Generated spec file from template %s" % (tmpl_fn)) - (base_name, arc_name, contents) = generate_spec_contents(tmpl_fn) + (base_name, arc_name, contents) = generate_spec_contents(tmpl_fn, + revno, version) spec_fn = os.path.join(root_dir, 'cloud-init.spec') with open(spec_fn, 'w') as fh: fh.write(contents) info("Wrote spec file to %s" % (spec_fn)) - # Archive the code and files that we want to - with tmpdir() as td: - src_dir = os.path.join(td, base_name) - os.makedirs(src_dir) - for fn in os.listdir(os.pardir): - if fn.startswith("."): - continue - full_fn = os.path.abspath(os.path.join(os.pardir, fn)) - if os.path.isfile(full_fn): - shutil.copy(full_fn, os.path.join(src_dir, fn)) - else: - shutil.copytree(full_fn, os.path.join(src_dir, fn), - ignore=shutil.ignore_patterns('*.pyc', - '.bzr', - 'tmp*', - '*bzr*')) - arc_fn = os.path.join(arc_dir, arc_name) - cmd = ['tar', '-zcvf', arc_fn, '-C', td] - cmd.extend(os.listdir(td)) - tiny_p(cmd) - info("Archived code at %s" % (arc_fn)) - # Now build it! cmd = ['rpmbuild', '-ba', spec_fn] info("Running rpmbuild %s" % (cmd)) diff --git a/packages/brpm.tmpl b/packages/brpm.tmpl index f0c874ee..0128bb69 100644 --- a/packages/brpm.tmpl +++ b/packages/brpm.tmpl @@ -32,7 +32,7 @@ ssh keys and to let the user run various scripts. %prep -%setup -q -n %{name}-%{version}-{{revno}} +%setup -q -n %build %{__python} setup.py build -- cgit v1.2.3 From d10824b11ee31566e4cef7bb8bc617747eaa37c4 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 21:04:51 -0700 Subject: Add a small script to tall the whole code --- packages/tar-me | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100755 packages/tar-me (limited to 'packages') diff --git a/packages/tar-me b/packages/tar-me new file mode 100755 index 00000000..b15399a1 --- /dev/null +++ b/packages/tar-me @@ -0,0 +1,84 @@ +#!/usr/bin/python + +import contextlib +import os +import shutil +import subprocess +import sys +import tempfile + + +def join(*paths): + p = os.path.join(*paths) + return os.path.abspath(p) + + +def tiny_p(cmd): + # Darn python 2.6 doesn't have check_output (argggg) + sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, stdin=None) + (out, err) = sp.communicate() + if sp.returncode not in [0]: + raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" + % (cmd, sp.returncode, out, err)) + return (out, err) + + +@contextlib.contextmanager +def tmpdir(): + t = tempfile.mkdtemp() + try: + yield t + finally: + shutil.rmtree(t) + + + +def main(args): + + tag = None + if args: + tag = args[0] + + with tmpdir() as td: + (stdout, _stderr) = tiny_p(['bzr', 'revno']) + revno = stdout.strip() + + cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')] + (stdout, _stderr) = tiny_p(cmd) + version = stdout.strip() + + owcd = os.getcwd() + os.chdir(os.path.abspath(os.pardir)) + if not os.path.exists('setup.py'): + raise RuntimeError("No setup.py found in %s" % (os.getcwd())) + + cmd = ['bzr', 'ls', '--versioned'] + (stdout, _stderr) = tiny_p(cmd) + fns = [] + for fn in stdout.splitlines(): + fn = fn.strip() + if not fn or fn.startswith("."): + continue + fns.append(fn) + + bfn = 'cloud-init-%s-%s' % (version, revno) + fn = '%s.tar.gz' % (bfn) + o_fn = join(td, fn) + cmd = ['tar', '-czf', o_fn] + cmd.extend(fns) + tiny_p(cmd) + + os.chdir(owcd) + shutil.copy(o_fn, fn) + + print revno + print version + print(os.path.abspath(fn)) + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) + -- cgit v1.2.3 From c1b9c57b25a96b2af66fb89e418101623665aa5a Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 21:06:07 -0700 Subject: Continue working on cleaning this up --- packages/brpm.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/brpm.tmpl b/packages/brpm.tmpl index 0128bb69..f0c874ee 100644 --- a/packages/brpm.tmpl +++ b/packages/brpm.tmpl @@ -32,7 +32,7 @@ ssh keys and to let the user run various scripts. %prep -%setup -q -n +%setup -q -n %{name}-%{version}-{{revno}} %build %{__python} setup.py build -- cgit v1.2.3 From 7ac2e599f7f132ce63b933872b9c6649b94e06e3 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 21:11:57 -0700 Subject: Use a directory prefix --- packages/tar-me | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/tar-me b/packages/tar-me index b15399a1..4a4a0253 100755 --- a/packages/tar-me +++ b/packages/tar-me @@ -61,12 +61,18 @@ def main(args): if not fn or fn.startswith("."): continue fns.append(fn) - bfn = 'cloud-init-%s-%s' % (version, revno) + os.makedirs(join(td, bfn)) + + for fn in fns: + if os.path.isfile(fn): + shutil.copy(fn, join(td, bfn, fn)) + else: + shutil.copytree(fn, join(td, bfn, fn)) + fn = '%s.tar.gz' % (bfn) o_fn = join(td, fn) - cmd = ['tar', '-czf', o_fn] - cmd.extend(fns) + cmd = ['tar', '-czf', o_fn, '-C', join(td), bfn] tiny_p(cmd) os.chdir(owcd) -- cgit v1.2.3 From ba39827bbd6beacb6360844854760dda0687f408 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 21:13:29 -0700 Subject: Use move instead of copy --- packages/tar-me | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/tar-me b/packages/tar-me index 4a4a0253..261b77bb 100755 --- a/packages/tar-me +++ b/packages/tar-me @@ -76,7 +76,7 @@ def main(args): tiny_p(cmd) os.chdir(owcd) - shutil.copy(o_fn, fn) + shutil.move(o_fn, fn) print revno print version -- cgit v1.2.3 From b40acd43cd8a7849887147c293d41f0ee5e1145c Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 21:13:37 -0700 Subject: Use move and not util copy --- packages/bddeb | 109 ++++++++++++++++++++++++++++++++++----------------------- packages/brpm | 4 +-- 2 files changed, 67 insertions(+), 46 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index 2a089295..465bd986 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -1,45 +1,66 @@ -#!/bin/sh - -# Ensure we can find the setup.py file which -# should be at the root of the cloud-init tree -PKG_DIR=`pwd` -ROOT="$PKG_DIR/../" -if [ ! -e "$ROOT/setup.py" ]; then - echo "No setup.py found at $ROOT" - exit 1 -fi -echo "Using root directory $ROOT for building your debian package" - -# Ensure tempdir is cleaned and ready to go -TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.XXXXXXX") -echo "With $TEMP_D as a temporary workspace" -rm -Rf "${TEMP_D}"; mkdir "${TEMP_D}" -set -e - -# Ensure tempdir removed if breaks... -trap "rm -Rf '${TEMP_D}'" EXIT SIGINT SIGTERM - -# Go to the root and start making a package! -cd $ROOT -files=$(bzr ls --versioned) -revno=$(bzr revno) -version=$(tools/read-version) - -mkdir "${TEMP_D}/cloud-init" -otar="$TEMP_D/cloud-init_$version~bzr${revno}.orig.tar.gz" -tar -czf - ${files} > "$otar" -tar -C "${TEMP_D}/cloud-init" -xzf - < "$otar" - -if [ ! -d "${TEMP_D}/cloud-init/debian" ]; then - rsync -a $PKG_DIR/debian.trunk/ "${TEMP_D}/cloud-init/debian" -fi - -sed -i -e "s,VERSION,$version," -e "s,REVNO,bzr$revno," \ - "$TEMP_D/cloud-init/debian/changelog" - -cd "${TEMP_D}/cloud-init" -debuild "$@" -debname="cloud-init_${version}~bzr${revno}-1_all.deb" -mv "../$debname" "$PKG_DIR" -echo "Wrote $debname to $PKG_DIR" +#!/usr/bin/python +import contextlib +import glob +import os +import shutil +import subprocess +import sys +import tempfile + + +@contextlib.contextmanager +def tmpdir(): + t = tempfile.mkdtemp() + try: + yield t + finally: + shutil.rmtree(t) + + +def join(*paths): + p = os.path.join(*paths) + return os.path.abspath(p) + + +def tiny_p(cmd): + # Darn python 2.6 doesn't have check_output (argggg) + info("Running %s" % (cmd)) + sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, stdin=None) + (out, err) = sp.communicate() + if sp.returncode not in [0]: + raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" + % (cmd, sp.returncode, out, err)) + return (out, err) + + +def info(msg): + print("INFO: %s" % (msg)) + + +def warn(msg): + print("WARNING: %s" % (msg)) + + + +def main(): + + with tmpdir() as td: + info("Using %s as a temporary workspace" % (td)) + (stdout, _stderr) = tiny_p(['bzr', 'revno']) + revno = stdout.strip() + + + + cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')] + (stdout, _stderr) = tiny_p(cmd) + version = stdout.strip() + + + + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/packages/brpm b/packages/brpm index 241f08fd..febbfb5e 100755 --- a/packages/brpm +++ b/packages/brpm @@ -145,7 +145,7 @@ def main(): # Archive the code (revno, version, archive_fn) = archive_code() real_archive_fn = os.path.join(arc_dir, os.path.basename(archive_fn)) - shutil.copy(archive_fn, real_archive_fn) + shutil.move(archive_fn, real_archive_fn) info("Archived code to %s" % (real_archive_fn)) # Form the spec file to be used @@ -175,7 +175,7 @@ def main(): for fn in globs: n = os.path.basename(fn) tgt_fn = os.path.join(os.getcwd(), n) - util.copy(fn, tgt_fn) + shutil.move(fn, tgt_fn) info("Copied %s to %s" % (n, tgt_fn)) return 0 -- cgit v1.2.3 From 0b692aa1f4cd99332e47fca7a8cc27843ad1bbe5 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 21:33:25 -0700 Subject: Coverting this to use the python utils --- packages/bddeb | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index 465bd986..f2158d5b 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -42,22 +42,46 @@ def info(msg): def warn(msg): print("WARNING: %s" % (msg)) - + +def archive_code(): + (stdout, _stderr) = tiny_p([sys.executable, + join(os.getcwd(), 'tar-me')]) + lines = stdout.splitlines() + revno = lines[0] + version = lines[1] + bname = lines[2] + arc_fn = lines[3] + return (revno, version, bname, arc_fn) + def main(): with tmpdir() as td: - info("Using %s as a temporary workspace" % (td)) - (stdout, _stderr) = tiny_p(['bzr', 'revno']) - revno = stdout.strip() - - - - cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')] - (stdout, _stderr) = tiny_p(cmd) - version = stdout.strip() - + (revno, version, bname, archive_fn) = archive_code() + real_archive_fn = os.path.join(td, os.path.basename(archive_fn)) + shutil.move(archive_fn, real_archive_fn) + info("Archived code to %s" % (real_archive_fn)) + + cmd = ['tar', '-xvzf', real_archive_fn, '-C', td] + stdout, stderr = tiny_p(cmd) + + edir = join(td, bname) + shutil.move(edir, join(td, 'cloud-init')) + shutil.copytree('debian.trunk', join(td, 'cloud-init', 'debian')) + + cmd = ['sed', '-i', '-e',"s,VERSION,%s," %(version), + '-e', "s,REVNO,bzr%s," % (revno), + join(td, 'cloud-init', 'debian', 'changelog')] + tiny_p(cmd) + ocwd = os.getcwd() + os.chdir(join(td, 'cloud-init')) + cmd = ['debuild'] + tiny_p(cmd) + + debname = "cloud-init_%s~bzr%s-1_all.deb" % (version, revno) + shutil.move(debname, join(owcwd, debname)) + info("Wrote out debian package %s" % (join(owcwd, debname))) return 0 -- cgit v1.2.3 From eb9d93b3403b6289c1f5278eea8886fb7415a651 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 21:33:36 -0700 Subject: Output the base tar name --- packages/brpm | 5 +++-- packages/tar-me | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index febbfb5e..c3be5997 100755 --- a/packages/brpm +++ b/packages/brpm @@ -90,7 +90,7 @@ def generate_spec_contents(tmpl_fn, revno, version): (stdout, _stderr) = tiny_p([sys.executable, join(os.getcwd(), 'rpm-changelog')]) - subs['changelog'] = stdout + subs['changelog'] = stdout.strip() # See: http://www.zarb.org/~jasonc/macros.php # Pickup any special files @@ -127,7 +127,8 @@ def archive_code(): lines = stdout.splitlines() revno = lines[0] version = lines[1] - arc_fn = lines[2] + bname = lines[2] + arc_fn = lines[3] return (revno, version, arc_fn) diff --git a/packages/tar-me b/packages/tar-me index 261b77bb..14b59960 100755 --- a/packages/tar-me +++ b/packages/tar-me @@ -80,6 +80,7 @@ def main(args): print revno print version + print bfn print(os.path.abspath(fn)) return 0 -- cgit v1.2.3 From cb49d6d4a1b5699b5e0afca1ac15d7225a8728a4 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 21:51:36 -0700 Subject: Get the new builddeb working and fix the rules file --- packages/bddeb | 15 +++++++++++++-- packages/debian.trunk/rules | 1 - 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index f2158d5b..1a9f13f3 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -15,7 +15,8 @@ def tmpdir(): try: yield t finally: - shutil.rmtree(t) + pass + #shutil.rmtree(t) def join(*paths): @@ -56,6 +57,10 @@ def archive_code(): def main(): + # cmd = ['apt-get', 'install', 'python-nose', + #'pyflakes', 'python-mocker', 'cdbs', 'debhelper'] + # tiny_p(cmd) + with tmpdir() as td: (revno, version, bname, archive_fn) = archive_code() real_archive_fn = os.path.join(td, os.path.basename(archive_fn)) @@ -68,12 +73,18 @@ def main(): edir = join(td, bname) shutil.move(edir, join(td, 'cloud-init')) shutil.copytree('debian.trunk', join(td, 'cloud-init', 'debian')) - + cmd = ['sed', '-i', '-e',"s,VERSION,%s," %(version), '-e', "s,REVNO,bzr%s," % (revno), join(td, 'cloud-init', 'debian', 'changelog')] tiny_p(cmd) + # Seems to want an original tar ball + o_tar = "cloud-init_%s~bzr%s.orig.tar.gz" % (version, revno) + cmd = ['tar', '-czf', join(td, o_tar), '-C', join(td, 'cloud-init')] + cmd.extend(os.listdir(join(td, 'cloud-init'))) + tiny_p(cmd) + ocwd = os.getcwd() os.chdir(join(td, 'cloud-init')) cmd = ['debuild'] diff --git a/packages/debian.trunk/rules b/packages/debian.trunk/rules index 0f79136c..a907b594 100755 --- a/packages/debian.trunk/rules +++ b/packages/debian.trunk/rules @@ -10,7 +10,6 @@ include /usr/share/cdbs/1/class/python-distutils.mk DEB_DH_INSTALL_SOURCEDIR := debian/tmp cloud-init-fixups: - for x in $(DEB_DESTDIR)/usr/bin/*.py; do mv "$$x" "$${x%.py}"; done install -d $(DEB_DESTDIR)/etc/rsyslog.d cp tools/21-cloudinit.conf $(DEB_DESTDIR)/etc/rsyslog.d/21-cloudinit.conf -- cgit v1.2.3 From 838a65e9c988cecb281c99a8de89c921fdfc9c61 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 23:55:40 -0700 Subject: Move redhat spec file templates to this directory --- packages/brpm.tmpl | 70 ----------------------------------------- packages/redhat/cloud-init.spec | 70 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 70 deletions(-) delete mode 100644 packages/brpm.tmpl create mode 100644 packages/redhat/cloud-init.spec (limited to 'packages') diff --git a/packages/brpm.tmpl b/packages/brpm.tmpl deleted file mode 100644 index f0c874ee..00000000 --- a/packages/brpm.tmpl +++ /dev/null @@ -1,70 +0,0 @@ -%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} - -Name: cloud-init -Version: {{version}} -Release: {{release}}%{?dist} -Summary: Cloud instance init scripts - -Group: System Environment/Base -License: GPLv3 -URL: http://launchpad.net/cloud-init - -Source0: {{archive_name}} - -BuildArch: noarch - -BuildRoot: %{_tmppath} - - -{{for r in bd_requires}} -BuildRequires: {{r}} -{{endfor}} - -# Install requirements -{{for r in requires}} -Requires: {{r}} -{{endfor}} - -%description -Cloud-init is a set of init scripts for cloud instances. Cloud instances -need special scripts to run during initialization to retrieve and install -ssh keys and to let the user run various scripts. - - -%prep -%setup -q -n %{name}-%{version}-{{revno}} - -%build -%{__python} setup.py build - - -%install -rm -rf $RPM_BUILD_ROOT -%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT - -%clean -rm -rf $RPM_BUILD_ROOT - -%files - -# Docs -{{for r in docs}} -%doc {{r}} -{{endfor}} - -# Configs -{{for r in configs}} -%config(noreplace) %{_sysconfdir}/{{r}} -{{endfor}} - -# Other files -{{for r in files}} -{{r}} -{{endfor}} - -# Python sitelib -%{python_sitelib}/* - -%changelog - -{{changelog}} diff --git a/packages/redhat/cloud-init.spec b/packages/redhat/cloud-init.spec new file mode 100644 index 00000000..f0c874ee --- /dev/null +++ b/packages/redhat/cloud-init.spec @@ -0,0 +1,70 @@ +%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} + +Name: cloud-init +Version: {{version}} +Release: {{release}}%{?dist} +Summary: Cloud instance init scripts + +Group: System Environment/Base +License: GPLv3 +URL: http://launchpad.net/cloud-init + +Source0: {{archive_name}} + +BuildArch: noarch + +BuildRoot: %{_tmppath} + + +{{for r in bd_requires}} +BuildRequires: {{r}} +{{endfor}} + +# Install requirements +{{for r in requires}} +Requires: {{r}} +{{endfor}} + +%description +Cloud-init is a set of init scripts for cloud instances. Cloud instances +need special scripts to run during initialization to retrieve and install +ssh keys and to let the user run various scripts. + + +%prep +%setup -q -n %{name}-%{version}-{{revno}} + +%build +%{__python} setup.py build + + +%install +rm -rf $RPM_BUILD_ROOT +%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT + +%clean +rm -rf $RPM_BUILD_ROOT + +%files + +# Docs +{{for r in docs}} +%doc {{r}} +{{endfor}} + +# Configs +{{for r in configs}} +%config(noreplace) %{_sysconfdir}/{{r}} +{{endfor}} + +# Other files +{{for r in files}} +{{r}} +{{endfor}} + +# Python sitelib +%{python_sitelib}/* + +%changelog + +{{changelog}} -- cgit v1.2.3 From c9fa666745567d7e3c9d55a83dfedad40e13ea9a Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 23:55:48 -0700 Subject: Rename this to be 'make-tarball' to match the other tar tools name, also change output to be tab separated. --- packages/make-tarball | 89 +++++++++++++++++++++++++++++++++++++++++++++++++ packages/tar-me | 91 --------------------------------------------------- 2 files changed, 89 insertions(+), 91 deletions(-) create mode 100755 packages/make-tarball delete mode 100755 packages/tar-me (limited to 'packages') diff --git a/packages/make-tarball b/packages/make-tarball new file mode 100755 index 00000000..98f669a9 --- /dev/null +++ b/packages/make-tarball @@ -0,0 +1,89 @@ +#!/usr/bin/python + +import contextlib +import os +import shutil +import subprocess +import sys +import tempfile + + +def join(*paths): + p = os.path.join(*paths) + return os.path.abspath(p) + + +def tiny_p(cmd): + # Darn python 2.6 doesn't have check_output (argggg) + sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.PIPE, stdin=None) + (out, err) = sp.communicate() + if sp.returncode not in [0]: + raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" + % (cmd, sp.returncode, out, err)) + return (out, err) + + +@contextlib.contextmanager +def tmpdir(): + t = tempfile.mkdtemp() + try: + yield t + finally: + shutil.rmtree(t) + + + +def main(args): + + tag = None + if args: + tag = args[0] + + with tmpdir() as td: + (stdout, _stderr) = tiny_p(['bzr', 'revno']) + revno = stdout.strip() + + cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')] + (stdout, _stderr) = tiny_p(cmd) + version = stdout.strip() + + owcd = os.getcwd() + os.chdir(os.path.abspath(os.pardir)) + if not os.path.exists('setup.py'): + raise RuntimeError("No setup.py found in %s" % (os.getcwd())) + + cmd = ['bzr', 'ls', '--versioned'] + (stdout, _stderr) = tiny_p(cmd) + fns = [] + for fn in stdout.splitlines(): + fn = fn.strip() + if not fn or fn.startswith("."): + continue + fns.append(fn) + bfn = 'cloud-init-%s-%s' % (version, revno) + os.makedirs(join(td, bfn)) + + for fn in fns: + if os.path.isfile(fn): + shutil.copy(fn, join(td, bfn, fn)) + else: + shutil.copytree(fn, join(td, bfn, fn)) + + fn = '%s.tar.gz' % (bfn) + o_fn = join(td, fn) + cmd = ['tar', '-czf', o_fn, '-C', join(td), bfn] + tiny_p(cmd) + + os.chdir(owcd) + shutil.move(o_fn, fn) + + out = [revno, version, bfn, os.path.abspath(fn)] + print('\t'.join(out)) + + return 0 + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) + diff --git a/packages/tar-me b/packages/tar-me deleted file mode 100755 index 14b59960..00000000 --- a/packages/tar-me +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/python - -import contextlib -import os -import shutil -import subprocess -import sys -import tempfile - - -def join(*paths): - p = os.path.join(*paths) - return os.path.abspath(p) - - -def tiny_p(cmd): - # Darn python 2.6 doesn't have check_output (argggg) - sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, stdin=None) - (out, err) = sp.communicate() - if sp.returncode not in [0]: - raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" - % (cmd, sp.returncode, out, err)) - return (out, err) - - -@contextlib.contextmanager -def tmpdir(): - t = tempfile.mkdtemp() - try: - yield t - finally: - shutil.rmtree(t) - - - -def main(args): - - tag = None - if args: - tag = args[0] - - with tmpdir() as td: - (stdout, _stderr) = tiny_p(['bzr', 'revno']) - revno = stdout.strip() - - cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')] - (stdout, _stderr) = tiny_p(cmd) - version = stdout.strip() - - owcd = os.getcwd() - os.chdir(os.path.abspath(os.pardir)) - if not os.path.exists('setup.py'): - raise RuntimeError("No setup.py found in %s" % (os.getcwd())) - - cmd = ['bzr', 'ls', '--versioned'] - (stdout, _stderr) = tiny_p(cmd) - fns = [] - for fn in stdout.splitlines(): - fn = fn.strip() - if not fn or fn.startswith("."): - continue - fns.append(fn) - bfn = 'cloud-init-%s-%s' % (version, revno) - os.makedirs(join(td, bfn)) - - for fn in fns: - if os.path.isfile(fn): - shutil.copy(fn, join(td, bfn, fn)) - else: - shutil.copytree(fn, join(td, bfn, fn)) - - fn = '%s.tar.gz' % (bfn) - o_fn = join(td, fn) - cmd = ['tar', '-czf', o_fn, '-C', join(td), bfn] - tiny_p(cmd) - - os.chdir(owcd) - shutil.move(o_fn, fn) - - print revno - print version - print bfn - print(os.path.abspath(fn)) - - return 0 - - -if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) - -- cgit v1.2.3 From 86d7dfa8dae0b53866462ce8e737309a40436402 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 23:56:15 -0700 Subject: 1. Change these to be templates where possible. 2. Rename to be a debian subdir, matching the redhat subdir. --- packages/debian.trunk/changelog | 5 ---- packages/debian.trunk/compat | 1 - packages/debian.trunk/control | 31 ------------------------- packages/debian.trunk/copyright | 51 ----------------------------------------- packages/debian.trunk/dirs | 5 ---- packages/debian.trunk/pycompat | 1 - packages/debian.trunk/rules | 27 ---------------------- packages/debian/changelog | 5 ++++ packages/debian/compat | 1 + packages/debian/control | 29 +++++++++++++++++++++++ packages/debian/copyright | 51 +++++++++++++++++++++++++++++++++++++++++ packages/debian/dirs | 5 ++++ packages/debian/pycompat | 1 + packages/debian/rules | 27 ++++++++++++++++++++++ 14 files changed, 119 insertions(+), 121 deletions(-) delete mode 100644 packages/debian.trunk/changelog delete mode 100644 packages/debian.trunk/compat delete mode 100644 packages/debian.trunk/control delete mode 100644 packages/debian.trunk/copyright delete mode 100644 packages/debian.trunk/dirs delete mode 100644 packages/debian.trunk/pycompat delete mode 100755 packages/debian.trunk/rules create mode 100644 packages/debian/changelog create mode 100644 packages/debian/compat create mode 100644 packages/debian/control create mode 100644 packages/debian/copyright create mode 100644 packages/debian/dirs create mode 100644 packages/debian/pycompat create mode 100755 packages/debian/rules (limited to 'packages') diff --git a/packages/debian.trunk/changelog b/packages/debian.trunk/changelog deleted file mode 100644 index a36d00d6..00000000 --- a/packages/debian.trunk/changelog +++ /dev/null @@ -1,5 +0,0 @@ -cloud-init (VERSION~REVNO-1) UNRELEASED; urgency=low - - * build - - -- Scott Moser Fri, 16 Dec 2011 11:50:25 -0500 diff --git a/packages/debian.trunk/compat b/packages/debian.trunk/compat deleted file mode 100644 index 7ed6ff82..00000000 --- a/packages/debian.trunk/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/packages/debian.trunk/control b/packages/debian.trunk/control deleted file mode 100644 index f0dcef6a..00000000 --- a/packages/debian.trunk/control +++ /dev/null @@ -1,31 +0,0 @@ -Source: cloud-init -Section: admin -Priority: extra -Maintainer: Scott Moser -Build-Depends: cdbs, - debhelper (>= 5.0.38), - python (>= 2.6.6-3~), - python-nose, - pyflakes, - pylint, - python-mocker, -XS-Python-Version: all -Standards-Version: 3.9.3 - -Package: cloud-init -Architecture: all -Depends: cloud-utils, - procps, - python, - python-boto (>=2.0), - python-cheetah, - python-configobj, - python-oauth, - python-software-properties, - python-yaml, - ${misc:Depends}, - ${python:Depends} -XB-Python-Version: ${python:Versions} -Description: Init scripts for cloud instances - Cloud instances need special scripts to run during initialisation - to retrieve and install ssh keys and to let the user run various scripts. diff --git a/packages/debian.trunk/copyright b/packages/debian.trunk/copyright deleted file mode 100644 index dc993525..00000000 --- a/packages/debian.trunk/copyright +++ /dev/null @@ -1,51 +0,0 @@ -Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135 -Name: cloud-init -Maintainer: Scott Moser -Source: https://launchpad.net/cloud-init - -This package was debianized by Soren Hansen on -Thu, 04 Sep 2008 12:49:15 +0200 as ec2-init. It was later renamed to -cloud-utils by Scott Moser - -Upstream Author: Scott Moser - Soren Hansen - Chuck Short - -Copyright: 2010, Canonical Ltd. -License: GPL-3 - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License version 3, 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 . - - The complete text of the GPL version 3 can be seen in - /usr/share/common-licenses/GPL-3. - -Files: cloudinit/boto_utils.py -Copyright: 2006,2007, Mitch Garnaat http://garnaat.org/ -License: MIT - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, dis- - tribute, sublicense, and/or sell copies of the Software, and to permit - persons to whom the Software is furnished to do so, subject to the fol- - lowing conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- - ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT - SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. diff --git a/packages/debian.trunk/dirs b/packages/debian.trunk/dirs deleted file mode 100644 index f3de468d..00000000 --- a/packages/debian.trunk/dirs +++ /dev/null @@ -1,5 +0,0 @@ -var/lib/cloud -usr/bin -etc/init -usr/share/doc/cloud -etc/cloud diff --git a/packages/debian.trunk/pycompat b/packages/debian.trunk/pycompat deleted file mode 100644 index 0cfbf088..00000000 --- a/packages/debian.trunk/pycompat +++ /dev/null @@ -1 +0,0 @@ -2 diff --git a/packages/debian.trunk/rules b/packages/debian.trunk/rules deleted file mode 100755 index a907b594..00000000 --- a/packages/debian.trunk/rules +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/make -f - -DEB_PYTHON2_MODULE_PACKAGES = cloud-init - -binary-install/cloud-init::cloud-init-fixups - -include /usr/share/cdbs/1/rules/debhelper.mk -include /usr/share/cdbs/1/class/python-distutils.mk - -DEB_DH_INSTALL_SOURCEDIR := debian/tmp - -cloud-init-fixups: - install -d $(DEB_DESTDIR)/etc/rsyslog.d - cp tools/21-cloudinit.conf $(DEB_DESTDIR)/etc/rsyslog.d/21-cloudinit.conf - -# You only need to run this immediately after checking out the package from -# revision control. -# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572204 -quilt-setup: - @[ ! -d .pc ] || { echo ".pc exists. remove it and re-run to start fresh"; exit 1; } - set -e; for patch in $$(quilt series | tac); do \ - patch -p1 -R --no-backup-if-mismatch <"debian/patches/$$patch"; \ - done - quilt push -a - -.PHONY: quilt-setup - diff --git a/packages/debian/changelog b/packages/debian/changelog new file mode 100644 index 00000000..ac5bcf98 --- /dev/null +++ b/packages/debian/changelog @@ -0,0 +1,5 @@ +cloud-init ({{version}}~{{revision}}-1) UNRELEASED; urgency=low + + * build + + -- Scott Moser Fri, 16 Dec 2011 11:50:25 -0500 diff --git a/packages/debian/compat b/packages/debian/compat new file mode 100644 index 00000000..7ed6ff82 --- /dev/null +++ b/packages/debian/compat @@ -0,0 +1 @@ +5 diff --git a/packages/debian/control b/packages/debian/control new file mode 100644 index 00000000..e00901af --- /dev/null +++ b/packages/debian/control @@ -0,0 +1,29 @@ +Source: cloud-init +Section: admin +Priority: extra +Maintainer: Scott Moser +Build-Depends: cdbs, + debhelper (>= 5.0.38), + python (>= 2.6.6-3~), + python-nose, + pyflakes, + pylint, + python-mocker, +XS-Python-Version: all +Standards-Version: 3.9.3 + +Package: cloud-init +Architecture: all +Depends: cloud-utils, + procps, + python, +{{for r in requires}} + {{r}}, +{{endfor}} + python-software-properties, + ${misc:Depends}, + ${python:Depends} +XB-Python-Version: ${python:Versions} +Description: Init scripts for cloud instances + Cloud instances need special scripts to run during initialisation + to retrieve and install ssh keys and to let the user run various scripts. diff --git a/packages/debian/copyright b/packages/debian/copyright new file mode 100644 index 00000000..dc993525 --- /dev/null +++ b/packages/debian/copyright @@ -0,0 +1,51 @@ +Format-Specification: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=135 +Name: cloud-init +Maintainer: Scott Moser +Source: https://launchpad.net/cloud-init + +This package was debianized by Soren Hansen on +Thu, 04 Sep 2008 12:49:15 +0200 as ec2-init. It was later renamed to +cloud-utils by Scott Moser + +Upstream Author: Scott Moser + Soren Hansen + Chuck Short + +Copyright: 2010, Canonical Ltd. +License: GPL-3 + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License version 3, 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 . + + The complete text of the GPL version 3 can be seen in + /usr/share/common-licenses/GPL-3. + +Files: cloudinit/boto_utils.py +Copyright: 2006,2007, Mitch Garnaat http://garnaat.org/ +License: MIT + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, dis- + tribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the fol- + lowing conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- + ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT + SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. diff --git a/packages/debian/dirs b/packages/debian/dirs new file mode 100644 index 00000000..f3de468d --- /dev/null +++ b/packages/debian/dirs @@ -0,0 +1,5 @@ +var/lib/cloud +usr/bin +etc/init +usr/share/doc/cloud +etc/cloud diff --git a/packages/debian/pycompat b/packages/debian/pycompat new file mode 100644 index 00000000..0cfbf088 --- /dev/null +++ b/packages/debian/pycompat @@ -0,0 +1 @@ +2 diff --git a/packages/debian/rules b/packages/debian/rules new file mode 100755 index 00000000..a907b594 --- /dev/null +++ b/packages/debian/rules @@ -0,0 +1,27 @@ +#!/usr/bin/make -f + +DEB_PYTHON2_MODULE_PACKAGES = cloud-init + +binary-install/cloud-init::cloud-init-fixups + +include /usr/share/cdbs/1/rules/debhelper.mk +include /usr/share/cdbs/1/class/python-distutils.mk + +DEB_DH_INSTALL_SOURCEDIR := debian/tmp + +cloud-init-fixups: + install -d $(DEB_DESTDIR)/etc/rsyslog.d + cp tools/21-cloudinit.conf $(DEB_DESTDIR)/etc/rsyslog.d/21-cloudinit.conf + +# You only need to run this immediately after checking out the package from +# revision control. +# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572204 +quilt-setup: + @[ ! -d .pc ] || { echo ".pc exists. remove it and re-run to start fresh"; exit 1; } + set -e; for patch in $$(quilt series | tac); do \ + patch -p1 -R --no-backup-if-mismatch <"debian/patches/$$patch"; \ + done + quilt push -a + +.PHONY: quilt-setup + -- cgit v1.2.3 From 2e05cec5cc9b5b334f7e46b629d424b09b9925b2 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 25 Jun 2012 23:57:01 -0700 Subject: Get these working again after the subdirectory and output format changes. --- packages/bddeb | 99 +++++++++++++++++++++++++++++++++++++++++++--------------- packages/brpm | 32 +++++++++---------- 2 files changed, 89 insertions(+), 42 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index 1a9f13f3..c39965da 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -8,6 +8,17 @@ import subprocess import sys import tempfile +import tempita + +PKG_MP = { + 'tempita': 'python-tempita', + 'boto': 'python-boto', + 'configobj': 'python-configobj', + 'oauth': 'python-oauth', + 'yaml': 'python-yaml', + 'prettytable': 'python-prettytable', + 'argparse': 'python-argparse', +} @contextlib.contextmanager def tmpdir(): @@ -24,11 +35,16 @@ def join(*paths): return os.path.abspath(p) -def tiny_p(cmd): +def tiny_p(cmd, capture=True): # Darn python 2.6 doesn't have check_output (argggg) info("Running %s" % (cmd)) - sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, stdin=None) + stdout = subprocess.PIPE + stderr = subprocess.PIPE + if not capture: + stdout = None + stderr = None + sp = subprocess.Popen(cmd, stdout=stdout, + stderr=stderr, stdin=None) (out, err) = sp.communicate() if sp.returncode not in [0]: raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" @@ -36,6 +52,53 @@ def tiny_p(cmd): return (out, err) +def tmpl_file(name, params): + with open(join('debian', name), 'r') as fh: + contents = fh.read() + tpl = tempita.Template(contents) + return tpl.substitute(**params) + + +def write_debian(version, revno, root): + db_dir = join(root, 'debian') + os.makedirs(db_dir) + + # Fill in the change log template + with open(join(db_dir, 'changelog'), 'w') as fh: + params = { + 'version': version, + 'revision': revno, + } + contents = tmpl_file('changelog', params) + fh.write(contents) + + # Write out the control file template + cmd = [sys.executable, join(os.pardir, 'tools', 'read-dependencies')] + (stdout, _stderr) = tiny_p(cmd) + pkgs = stdout.splitlines() + requires = [] + + # Map to known packages + for e in pkgs: + e = e.lower().strip() + tgt_pkg = None + for n in PKG_MP.keys(): + if e.find(n) != -1: + tgt_pkg = PKG_MP.get(n) + if not tgt_pkg: + raise RuntimeError(("Do not know how to translate %s to " + " a known package") % (e)) + else: + requires.append(tgt_pkg) + contents = tmpl_file('control', {'requires': requires}) + with open(join(db_dir, 'control'), 'w') as fh: + fh.write(contents) + + # Just copy the following directly + for fn in ['dirs', 'copyright', 'compat', 'pycompat', 'rules']: + shutil.copy(join('debian', fn), + join(db_dir, fn)) + def info(msg): print("INFO: %s" % (msg)) @@ -46,49 +109,33 @@ def warn(msg): def archive_code(): (stdout, _stderr) = tiny_p([sys.executable, - join(os.getcwd(), 'tar-me')]) - lines = stdout.splitlines() - revno = lines[0] - version = lines[1] - bname = lines[2] - arc_fn = lines[3] - return (revno, version, bname, arc_fn) + join(os.getcwd(), 'make-tarball')]) + return stdout.split(None) def main(): - # cmd = ['apt-get', 'install', 'python-nose', - #'pyflakes', 'python-mocker', 'cdbs', 'debhelper'] - # tiny_p(cmd) - with tmpdir() as td: (revno, version, bname, archive_fn) = archive_code() real_archive_fn = os.path.join(td, os.path.basename(archive_fn)) shutil.move(archive_fn, real_archive_fn) - info("Archived code to %s" % (real_archive_fn)) - cmd = ['tar', '-xvzf', real_archive_fn, '-C', td] stdout, stderr = tiny_p(cmd) edir = join(td, bname) shutil.move(edir, join(td, 'cloud-init')) - shutil.copytree('debian.trunk', join(td, 'cloud-init', 'debian')) - - cmd = ['sed', '-i', '-e',"s,VERSION,%s," %(version), - '-e', "s,REVNO,bzr%s," % (revno), - join(td, 'cloud-init', 'debian', 'changelog')] - tiny_p(cmd) - + write_debian(version, revno, join(td, 'cloud-init')) + # Seems to want an original tar ball - o_tar = "cloud-init_%s~bzr%s.orig.tar.gz" % (version, revno) - cmd = ['tar', '-czf', join(td, o_tar), '-C', join(td, 'cloud-init')] + o_tar = "cloud-init_%s~%s.orig.tar.gz" % (version, revno) + cmd = ['tar', '-czvf', join(td, o_tar), '-C', join(td, 'cloud-init')] cmd.extend(os.listdir(join(td, 'cloud-init'))) tiny_p(cmd) ocwd = os.getcwd() os.chdir(join(td, 'cloud-init')) cmd = ['debuild'] - tiny_p(cmd) + tiny_p(cmd, capture=False) debname = "cloud-init_%s~bzr%s-1_all.deb" % (version, revno) shutil.move(debname, join(owcwd, debname)) diff --git a/packages/brpm b/packages/brpm index c3be5997..bbe637e8 100755 --- a/packages/brpm +++ b/packages/brpm @@ -37,11 +37,16 @@ def join(*paths): return os.path.abspath(p) -def tiny_p(cmd): +def tiny_p(cmd, capture=True): # Darn python 2.6 doesn't have check_output (argggg) info("Running %s" % (cmd)) - sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, stdin=None) + stdout = subprocess.PIPE + stderr = subprocess.PIPE + if not capture: + stdout = None + stderr = None + sp = subprocess.Popen(cmd, stdout=stdout, + stderr=stderr, stdin=None) (out, err) = sp.communicate() if sp.returncode not in [0]: raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" @@ -123,12 +128,8 @@ def generate_spec_contents(tmpl_fn, revno, version): def archive_code(): (stdout, _stderr) = tiny_p([sys.executable, - join(os.getcwd(), 'tar-me')]) - lines = stdout.splitlines() - revno = lines[0] - version = lines[1] - bname = lines[2] - arc_fn = lines[3] + join(os.getcwd(), 'make-tarball')]) + (revno, version, bname, arc_fn) = stdout.split(None) return (revno, version, arc_fn) @@ -136,7 +137,7 @@ def main(): # Clean out the root dir and make sure the dirs we want are in place root_dir = os.path.expanduser("~/rpmbuild") - info("Cleaning %s" % (root_dir)) + info("Cleaning %r" % (root_dir)) if os.path.isdir(root_dir): shutil.rmtree(root_dir) arc_dir = os.path.join(root_dir, 'SOURCES') @@ -147,22 +148,21 @@ def main(): (revno, version, archive_fn) = archive_code() real_archive_fn = os.path.join(arc_dir, os.path.basename(archive_fn)) shutil.move(archive_fn, real_archive_fn) - info("Archived code to %s" % (real_archive_fn)) + info("Archived code to %r" % (real_archive_fn)) # Form the spec file to be used - tmpl_fn = os.path.join(os.getcwd(), 'brpm.tmpl') - info("Generated spec file from template %s" % (tmpl_fn)) + tmpl_fn = os.path.join(os.getcwd(), 'redhat', 'cloud-init.spec') + info("Generated spec file from template %r" % (tmpl_fn)) (base_name, arc_name, contents) = generate_spec_contents(tmpl_fn, revno, version) spec_fn = os.path.join(root_dir, 'cloud-init.spec') with open(spec_fn, 'w') as fh: fh.write(contents) - info("Wrote spec file to %s" % (spec_fn)) + info("Wrote spec file to %r" % (spec_fn)) # Now build it! cmd = ['rpmbuild', '-ba', spec_fn] - info("Running rpmbuild %s" % (cmd)) - tiny_p(cmd) + tiny_p(cmd, capture=False) info("Rpmbuild completed!") # Copy the items built to our local dir -- cgit v1.2.3 From 33812679bb6950986f18ee88d8dae86062aa319f Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 26 Jun 2012 00:48:38 -0700 Subject: Removed, just going to use the base 'ChangeLog' file. --- packages/rpm-changelog | 211 ------------------------------------------------- 1 file changed, 211 deletions(-) delete mode 100755 packages/rpm-changelog (limited to 'packages') diff --git a/packages/rpm-changelog b/packages/rpm-changelog deleted file mode 100755 index 8acaa5b9..00000000 --- a/packages/rpm-changelog +++ /dev/null @@ -1,211 +0,0 @@ -#!/usr/bin/python -# vi: ts=4 expandtab - -# A crappy little script -# that changes bzr 'log' -# into someting that rpm spec files can use (best effort) - -import os -import re -import sys - -from datetime import datetime -from datetime import date - -import subprocess - -E_TYPES = ['tags', 'revno', 'author', 'timestamp', 'committer'] - - -def tiny_p(cmd): - # Darn python 2.6 doesn't have check_output (argggg) - sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, stdin=None) - (out, err) = sp.communicate() - return (out, err) - - -def extract_entry(collecting): - entry = {} - for t in E_TYPES: - look_for = "%s:" % (t) - for v in collecting: - if v.startswith(look_for): - entry[t] = v[len(look_for):].strip() - break - i = -1 - # Messages seem to be the last element so suck - # those all up - for a, v in enumerate(collecting): - if v.startswith("message:"): - i = a - break - if i != -1: - msg_lines = collecting[i + 1:] - entry['message'] = "\n".join(msg_lines) - return entry - - -def clean_authors(authors): - if not authors: - return '' - auth_cleaned = set() - for a in authors: - a = a.strip() - if a: - auth_cleaned.add(a) - if not auth_cleaned: - return '' - uniq_authors = list(auth_cleaned) - if len(uniq_authors) == 1: - return authors[0] - auths = "(%s)" % ", ".join(uniq_authors) - return auths - - -def clean_revnos(revnos): - novs = list() - for r in revnos: - r = r.strip() - r = r.replace("[merge]", "") - if r: - novs.append(int(r)) - entries = list(novs) - if not entries: - return '' - entries.sort() - if len(entries) == 1: - return "%s" % (entries[0]) - - # Check if consecutive - start = entries[0] - consec = True - for (i, v) in enumerate(entries): - if v != start + i: - consec = False - break - if consec: - end = entries[-1] - return "%s => %s" % (start, end) - v = [str(b) for b in entries] - return ", ".join(v) - - -def spacey(am): - return " " * am - - -def justify(text, space_wanted): - c_bef = len(text) - t_c = len(text.lstrip()) - space_am = (c_bef - t_c) - needed = (space_wanted - space_am) - if needed < 0: - return text - return (" " * (needed) + text) - - -def clean_messages(messages): - contents = [] - for msg in messages: - # Split into sub-messages... - # if we can - lines = [] - pieces = msg.splitlines() - if len(pieces) == 1: - lines.append("%s- %s " % - (spacey(4), msg.strip())) - else: - n_lines = [] - n_lines.append(pieces[0].strip()) - for line in pieces[1:]: - line = line.lstrip() - if not line: - continue - n_lines.append(justify(line, 6)) - lines.append("%s- %s" % (spacey(4), "\n".join(n_lines))) - contents.extend(lines) - return "\n".join(contents) - - -def build_changelog(history=-1): - cmd = ['bzr', 'log', '--timezone=utc'] - (stdout, _stderr) = tiny_p(cmd) - - # Clean the format up - entries = stdout.splitlines() - all_entries = [] - collecting = [] - for e in entries: - if e.startswith("---"): - if collecting: - a_entry = extract_entry(collecting) - if a_entry: - all_entries.append(a_entry) - collecting = [] - else: - collecting.append(e) - - # Anything that we left behind?? - entry = extract_entry(collecting) - if entry: - all_entries.append(entry) - - if history > 0: - take_entries = list(all_entries[0:history]) - else: - take_entries = list(all_entries) - - # Merge those with same date - date_entries = {} - for e in take_entries: - author = e.get('author') - if not author: - author = e.get('committer') - if not author: - continue - timestamp = e.get('timestamp') - if not timestamp: - continue - msg = e.get('message') - if not msg: - continue - revno = e.get('revno') - if not revno: - continue - # http://bugs.python.org/issue6641 - timestamp = timestamp.replace("+0000", '').strip() - ds = datetime.strptime(timestamp, '%a %Y-%m-%d %H:%M:%S') - ds = ds.date() - if ds not in date_entries: - entry = {} - entry['messages'] = [] - entry['authors'] = [] - entry['revnos'] = [] - date_entries[ds] = entry - entry = date_entries[ds] - entry['messages'].append(msg) - entry['authors'].append(author) - entry['revnos'].append(revno) - - # It wants them in chronological order... - dates = sorted(date_entries.keys()) - chglog = [] - for ds in reversed(dates): - e = date_entries[ds] - authors = clean_authors(e['authors']) - revnos = clean_revnos(e['revnos']) - top_line = "%s %s - [revison %s]" % (ds.strftime("%a %b %d %Y"), - authors, revnos) - chglog.append("* %s" % (top_line)) - chglog.append(clean_messages(e['messages'])) - return "\n".join(chglog) - - -if __name__ == '__main__': - args = sys.argv[1:] - history_am = -1 - if args: - history_am = int(args[0]) - chglog = build_changelog(history_am) - print chglog -- cgit v1.2.3 From ec8ca070c3be9ef8622d1a618d78f6cacfb9653f Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 26 Jun 2012 00:48:55 -0700 Subject: Just use the base changelog. --- packages/brpm | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index bbe637e8..081d092b 100755 --- a/packages/brpm +++ b/packages/brpm @@ -7,9 +7,11 @@ import shutil import subprocess import sys import tempfile +import re import tempita +from datetime import datetime # Mapping of expected packages to there full name... PKG_MP = { @@ -53,6 +55,46 @@ def tiny_p(cmd, capture=True): % (cmd, sp.returncode, out, err)) return (out, err) +def get_log_header(version): + cmd = ['bzr', 'tags'] + (stdout, _stderr) = tiny_p(cmd) + a_rev = None + for t in stdout.splitlines(): + ver, rev = t.split(None) + if ver == version: + a_rev = rev + break + if not a_rev: + return format_change_line(datetime.now(), + '??', version) + cmd = ['bzr', 'log', '-r%s' % (a_rev), '--timezone=utc'] + (stdout, _stderr) = tiny_p(cmd) + kvs = { + 'comment': version, + } + for line in stdout.splitlines(): + if line.startswith('committer:'): + kvs['who'] = line[len('committer:'):].strip() + if line.startswith('timestamp:'): + ts = line[len('timestamp:'):] + ts = ts.strip() + # http://bugs.python.org/issue6641 + ts = ts.replace("+0000", '').strip() + ds = datetime.strptime(ts, '%a %Y-%m-%d %H:%M:%S') + kvs['ds'] = ds + return format_change_line(**kvs) + +def format_change_line(ds, who, comment=None): + d = format_rpm_date(ds) + d += " - %s" % (who) + if comment: + d += " - %s" % (comment) + return "* %s" % (d) + + +def format_rpm_date(ds): + return ds.strftime("%a %b %d %Y") + def info(msg): print("INFO: %s" % (msg)) @@ -93,9 +135,21 @@ def generate_spec_contents(tmpl_fn, revno, version): base_name = 'cloud-init-%s-%s' % (version, subs['revno']) subs['requires'] = requires - (stdout, _stderr) = tiny_p([sys.executable, - join(os.getcwd(), 'rpm-changelog')]) - subs['changelog'] = stdout.strip() + # Format a nice changelog (as best as we can) + changelog = '' + with open(join(os.pardir, 'ChangeLog')) as fh: + changelog = fh.read() + ch_lines = [] + for line in changelog.splitlines(): + if not line.strip(): + continue + if re.match(r"^\s*[\d][.][\d][.][\d]:\s*", line): + line = line.strip(":") + header = get_log_header(line) + ch_lines.append(header) + else: + ch_lines.append(line) + subs['changelog'] = "\n".join(ch_lines) # See: http://www.zarb.org/~jasonc/macros.php # Pickup any special files -- cgit v1.2.3 From 12d6cdce560be0b4788ae198f75d783a12b893c2 Mon Sep 17 00:00:00 2001 From: harlowja Date: Tue, 26 Jun 2012 07:48:12 -0700 Subject: Add in the ability to choose which type of boot type the rpm should have and adjust the specfile that is generated to remove the unwanted config files for the types which were not selected. --- packages/brpm | 30 ++++++++++++++++++++++++++++-- packages/redhat/cloud-init.spec | 6 +++++- 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 081d092b..b505e6b4 100755 --- a/packages/brpm +++ b/packages/brpm @@ -9,6 +9,8 @@ import sys import tempfile import re +import argparse + import tempita from datetime import datetime @@ -104,7 +106,7 @@ def warn(msg): print("WARNING: %s" % (msg)) -def generate_spec_contents(tmpl_fn, revno, version): +def generate_spec_contents(args, tmpl_fn, revno, version): # Tmpl params subs = {} @@ -172,6 +174,22 @@ def generate_spec_contents(tmpl_fn, revno, version): '%{_bindir}/*', '/usr/lib/cloud-init/*', ] + # Since setup.py installs them + # all, we need to selectively + # knock off the wrong ones and + # ensure the right one is kept + post_remove_keep = { + 'initd': '/etc/init.d/', + 'systemd': '/etc/systemd/', + 'upstart': '/etc/init/', + } + post_remove = [] + for (k, v) in post_remove_keep.iteritems(): + if k != args.boot: + post_remove.append(v) + else: + other_files.append(v) + subs['post_remove'] = post_remove subs['files'] = other_files with open(tmpl_fn, 'r') as fh: @@ -188,6 +206,13 @@ def archive_code(): def main(): + + parser = argparse.ArgumentParser() + parser.add_argument("-b", "--boot", dest="boot", + help="select boot type (default: %(default)s)", + metavar="TYPE", default='initd', + choices=['upstart', 'initd', 'systemd']) + args = parser.parse_args() # Clean out the root dir and make sure the dirs we want are in place root_dir = os.path.expanduser("~/rpmbuild") @@ -207,7 +232,8 @@ def main(): # Form the spec file to be used tmpl_fn = os.path.join(os.getcwd(), 'redhat', 'cloud-init.spec') info("Generated spec file from template %r" % (tmpl_fn)) - (base_name, arc_name, contents) = generate_spec_contents(tmpl_fn, + (base_name, arc_name, contents) = generate_spec_contents(args, + tmpl_fn, revno, version) spec_fn = os.path.join(root_dir, 'cloud-init.spec') with open(spec_fn, 'w') as fh: diff --git a/packages/redhat/cloud-init.spec b/packages/redhat/cloud-init.spec index f0c874ee..ddb6617d 100644 --- a/packages/redhat/cloud-init.spec +++ b/packages/redhat/cloud-init.spec @@ -37,11 +37,15 @@ ssh keys and to let the user run various scripts. %build %{__python} setup.py build - %install rm -rf $RPM_BUILD_ROOT %{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT +# Remove anything after it was installed?? +{{for r in post_remove}} +rm -rfv $RPM_BUILD_ROOT/{{r}} +{{endfor}} + %clean rm -rf $RPM_BUILD_ROOT -- cgit v1.2.3 From e657162aa2e0b3b4a92e4860f758ee85d8d85eba Mon Sep 17 00:00:00 2001 From: harlowja Date: Tue, 26 Jun 2012 08:04:28 -0700 Subject: 1. Remove unused return arguments 2. Adjust info statement to reflect better what it is doing. --- packages/brpm | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index b505e6b4..db60bf81 100755 --- a/packages/brpm +++ b/packages/brpm @@ -195,7 +195,7 @@ def generate_spec_contents(args, tmpl_fn, revno, version): with open(tmpl_fn, 'r') as fh: tmpl = tempita.Template(fh.read()) contents = tmpl.substitute(**subs) - return (base_name, '%s.tar.gz' % (base_name), contents) + return contents def archive_code(): @@ -231,10 +231,8 @@ def main(): # Form the spec file to be used tmpl_fn = os.path.join(os.getcwd(), 'redhat', 'cloud-init.spec') - info("Generated spec file from template %r" % (tmpl_fn)) - (base_name, arc_name, contents) = generate_spec_contents(args, - tmpl_fn, - revno, version) + info("Generating spec file from template %r" % (tmpl_fn)) + contents = generate_spec_contents(args, tmpl_fn, revno, version) spec_fn = os.path.join(root_dir, 'cloud-init.spec') with open(spec_fn, 'w') as fh: fh.write(contents) -- cgit v1.2.3 From 2b1916db723148dcc291f3ac991bb0340943587e Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 26 Jun 2012 12:17:11 -0700 Subject: Shrink these down by using the cloudinit utils. --- packages/bddeb | 177 +++++++++++++++++++++----------------------------- packages/brpm | 155 ++++++++++++++++++------------------------- packages/make-tarball | 108 ++++++++++++------------------ 3 files changed, 183 insertions(+), 257 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index c39965da..5f250738 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -1,15 +1,20 @@ #!/usr/bin/python -import contextlib -import glob import os import shutil -import subprocess import sys -import tempfile -import tempita +# Use the util functions from cloudinit +possible_topdir = os.path.normpath(os.path.join(os.path.abspath( + sys.argv[0]), os.pardir, os.pardir)) +if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): + sys.path.insert(0, possible_topdir) +from cloudinit import templater +from cloudinit import util + +# Package names that will showup in requires to what we can actually +# use in our debian 'control' file PKG_MP = { 'tempita': 'python-tempita', 'boto': 'python-boto', @@ -20,126 +25,94 @@ PKG_MP = { 'argparse': 'python-argparse', } -@contextlib.contextmanager -def tmpdir(): - t = tempfile.mkdtemp() - try: - yield t - finally: - pass - #shutil.rmtree(t) - - -def join(*paths): - p = os.path.join(*paths) - return os.path.abspath(p) - - -def tiny_p(cmd, capture=True): - # Darn python 2.6 doesn't have check_output (argggg) - info("Running %s" % (cmd)) - stdout = subprocess.PIPE - stderr = subprocess.PIPE - if not capture: - stdout = None - stderr = None - sp = subprocess.Popen(cmd, stdout=stdout, - stderr=stderr, stdin=None) - (out, err) = sp.communicate() - if sp.returncode not in [0]: - raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" - % (cmd, sp.returncode, out, err)) - return (out, err) - - -def tmpl_file(name, params): - with open(join('debian', name), 'r') as fh: - contents = fh.read() - tpl = tempita.Template(contents) - return tpl.substitute(**params) - -def write_debian(version, revno, root): - db_dir = join(root, 'debian') - os.makedirs(db_dir) +def write_debian_folder(root, version, revno): + deb_dir = util.abs_join(root, 'debian') + os.makedirs(deb_dir) # Fill in the change log template - with open(join(db_dir, 'changelog'), 'w') as fh: - params = { - 'version': version, - 'revision': revno, - } - contents = tmpl_file('changelog', params) - fh.write(contents) + templater.render_to_file(util.abs_join('debian', 'changelog'), + util.abs_join(deb_dir, 'changelog'), + params={ + 'version': version, + 'revision': revno, + }) # Write out the control file template - cmd = [sys.executable, join(os.pardir, 'tools', 'read-dependencies')] - (stdout, _stderr) = tiny_p(cmd) - pkgs = stdout.splitlines() - requires = [] + cmd = [sys.executable, + util.abs_join(os.pardir, 'tools', 'read-dependencies')] + (stdout, _stderr) = util.subp(cmd) # Map to known packages - for e in pkgs: - e = e.lower().strip() + pkgs = [p.lower().strip() for p in stdout.splitlines()] + requires = [] + for p in pkgs: tgt_pkg = None - for n in PKG_MP.keys(): - if e.find(n) != -1: - tgt_pkg = PKG_MP.get(n) + for name in PKG_MP.keys(): + if p.find(name) != -1: + tgt_pkg = PKG_MP.get(name) + break if not tgt_pkg: raise RuntimeError(("Do not know how to translate %s to " - " a known package") % (e)) + " a known package") % (p)) else: requires.append(tgt_pkg) - contents = tmpl_file('control', {'requires': requires}) - with open(join(db_dir, 'control'), 'w') as fh: - fh.write(contents) + + templater.render_to_file(util.abs_join('debian', 'control'), + util.abs_join(deb_dir, 'control'), + params={'requires': requires}) # Just copy the following directly - for fn in ['dirs', 'copyright', 'compat', 'pycompat', 'rules']: - shutil.copy(join('debian', fn), - join(db_dir, fn)) - -def info(msg): - print("INFO: %s" % (msg)) + for base_fn in ['dirs', 'copyright', 'compat', 'pycompat', 'rules']: + shutil.copy(util.abs_join('debian', base_fn), + util.abs_join(deb_dir, base_fn)) -def warn(msg): - print("WARNING: %s" % (msg)) +def main(): + with util.tempdir() as tdir: -def archive_code(): - (stdout, _stderr) = tiny_p([sys.executable, - join(os.getcwd(), 'make-tarball')]) - return stdout.split(None) + cmd = [sys.executable, + util.abs_join(os.pardir, 'tools', 'read-version')] + (sysout, _stderr) = util.subp(cmd) + version = sysout.strip() + cmd = ['bzr', 'revno'] + (sysout, _stderr) = util.subp(cmd) + revno = sysout.strip() + + cmd = [sys.executable, + util.abs_join(os.getcwd(), 'make-tarball')] + (sysout, _stderr) = util.subp(cmd) + arch_fn = sysout.strip() -def main(): + tmp_arch_fn = util.abs_join(tdir, os.path.basename(arch_fn)) + shutil.move(arch_fn, tmp_arch_fn) - with tmpdir() as td: - (revno, version, bname, archive_fn) = archive_code() - real_archive_fn = os.path.join(td, os.path.basename(archive_fn)) - shutil.move(archive_fn, real_archive_fn) - cmd = ['tar', '-xvzf', real_archive_fn, '-C', td] - stdout, stderr = tiny_p(cmd) - - edir = join(td, bname) - shutil.move(edir, join(td, 'cloud-init')) - write_debian(version, revno, join(td, 'cloud-init')) - - # Seems to want an original tar ball - o_tar = "cloud-init_%s~%s.orig.tar.gz" % (version, revno) - cmd = ['tar', '-czvf', join(td, o_tar), '-C', join(td, 'cloud-init')] - cmd.extend(os.listdir(join(td, 'cloud-init'))) - tiny_p(cmd) + cmd = ['tar', '-xvzf', tmp_arch_fn, '-C', tdir] + util.subp(cmd) + + base_name = os.path.basename(arch_fn)[:-len(".tar.gz")] + shutil.move(util.abs_join(tdir, base_name), + util.abs_join(tdir, 'cloud-init')) + + write_debian_folder(util.abs_join(tdir, 'cloud-init'), + version, revno) + + tar_fn = "cloud-init_%s~%s.orig.tar.gz" % (version, revno) + cmd = ['tar', '-czvf', + util.abs_join(tdir, tar_fn), + '-C', util.abs_join(tdir, 'cloud-init')] + cmd.extend(os.listdir(util.abs_join(tdir, 'cloud-init'))) + util.subp(cmd) ocwd = os.getcwd() - os.chdir(join(td, 'cloud-init')) - cmd = ['debuild'] - tiny_p(cmd, capture=False) - - debname = "cloud-init_%s~bzr%s-1_all.deb" % (version, revno) - shutil.move(debname, join(owcwd, debname)) - info("Wrote out debian package %s" % (join(owcwd, debname))) + with util.chdir(util.abs_join(tdir, 'cloud-init')): + util.subp(['debuild'], capture=False) + debname = "cloud-init_%s~bzr%s-1_all.deb" % (version, revno) + shutil.move(debname, util.abs_join(ocwd, debname)) + + print("Wrote out debian package %s" % (util.abs_join(ocwd, debname))) return 0 diff --git a/packages/brpm b/packages/brpm index db60bf81..f3ff2f58 100755 --- a/packages/brpm +++ b/packages/brpm @@ -11,10 +11,18 @@ import re import argparse -import tempita +# Use the util functions from cloudinit +possible_topdir = os.path.normpath(os.path.join(os.path.abspath( + sys.argv[0]), os.pardir, os.pardir)) +if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): + sys.path.insert(0, possible_topdir) + +from cloudinit import templater +from cloudinit import util from datetime import datetime + # Mapping of expected packages to there full name... PKG_MP = { 'boto': 'python-boto', @@ -27,39 +35,10 @@ PKG_MP = { } -@contextlib.contextmanager -def tmpdir(): - t = tempfile.mkdtemp() - try: - yield t - finally: - shutil.rmtree(t) - - -def join(*paths): - p = os.path.join(*paths) - return os.path.abspath(p) - - -def tiny_p(cmd, capture=True): - # Darn python 2.6 doesn't have check_output (argggg) - info("Running %s" % (cmd)) - stdout = subprocess.PIPE - stderr = subprocess.PIPE - if not capture: - stdout = None - stderr = None - sp = subprocess.Popen(cmd, stdout=stdout, - stderr=stderr, stdin=None) - (out, err) = sp.communicate() - if sp.returncode not in [0]: - raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" - % (cmd, sp.returncode, out, err)) - return (out, err) - def get_log_header(version): + # Try to find the version in the tags output cmd = ['bzr', 'tags'] - (stdout, _stderr) = tiny_p(cmd) + (stdout, _stderr) = util.subp(cmd) a_rev = None for t in stdout.splitlines(): ver, rev = t.split(None) @@ -69,11 +48,14 @@ def get_log_header(version): if not a_rev: return format_change_line(datetime.now(), '??', version) + + # Extract who made that tag as the header cmd = ['bzr', 'log', '-r%s' % (a_rev), '--timezone=utc'] - (stdout, _stderr) = tiny_p(cmd) + (stdout, _stderr) = util.subp(cmd) kvs = { 'comment': version, } + for line in stdout.splitlines(): if line.startswith('committer:'): kvs['who'] = line[len('committer:'):].strip() @@ -84,74 +66,73 @@ def get_log_header(version): ts = ts.replace("+0000", '').strip() ds = datetime.strptime(ts, '%a %Y-%m-%d %H:%M:%S') kvs['ds'] = ds + return format_change_line(**kvs) + def format_change_line(ds, who, comment=None): - d = format_rpm_date(ds) + d = ds.strftime("%a %b %d %Y") d += " - %s" % (who) if comment: d += " - %s" % (comment) return "* %s" % (d) -def format_rpm_date(ds): - return ds.strftime("%a %b %d %Y") - - -def info(msg): - print("INFO: %s" % (msg)) - - -def warn(msg): - print("WARNING: %s" % (msg)) +def generate_spec_contents(args, tmpl_fn): - -def generate_spec_contents(args, tmpl_fn, revno, version): + # Figure out the version and revno + cmd = [sys.executable, + util.abs_join(os.pardir, 'tools', 'read-version')] + (stdout, _stderr) = util.subp(cmd) + version = stdout.strip() + + cmd = ['bzr', 'revno'] + (stdout, _stderr) = util.subp(cmd) + revno = stdout.strip() # Tmpl params subs = {} subs['version'] = version subs['revno'] = revno subs['release'] = revno - subs['archive_name'] = '%{name}-%{version}-' + subs['revno'] + '.tar.gz' + subs['archive_name'] = '%{name}-%{version}-' + revno + '.tar.gz' subs['bd_requires'] = ['python-devel', 'python-setuptools'] - requires = [] - cmd = [sys.executable, join(os.pardir, 'tools', 'read-dependencies')] - (stdout, _stderr) = tiny_p(cmd) - pkgs = stdout.splitlines() - + cmd = [sys.executable, + util.abs_join(os.pardir, 'tools', 'read-dependencies')] + (stdout, _stderr) = util.subp(cmd) + # Map to known packages - for e in pkgs: - e = e.lower().strip() + pkgs = [p.lower().strip() for p in stdout.splitlines()] + + # Map to known packages + requires = [] + for p in pkgs: tgt_pkg = None - for n in PKG_MP.keys(): - if e.find(n) != -1: - tgt_pkg = PKG_MP.get(n) + for name in PKG_MP.keys(): + if p.find(name) != -1: + tgt_pkg = PKG_MP.get(name) + break if not tgt_pkg: raise RuntimeError(("Do not know how to translate %s to " - " a known package") % (e)) + " a known package") % (p)) else: requires.append(tgt_pkg) - - base_name = 'cloud-init-%s-%s' % (version, subs['revno']) subs['requires'] = requires # Format a nice changelog (as best as we can) - changelog = '' - with open(join(os.pardir, 'ChangeLog')) as fh: - changelog = fh.read() - ch_lines = [] + changelog = util.load_file(util.abs_join(os.pardir, 'ChangeLog')) + changelog_lines = [] for line in changelog.splitlines(): if not line.strip(): continue if re.match(r"^\s*[\d][.][\d][.][\d]:\s*", line): line = line.strip(":") header = get_log_header(line) - ch_lines.append(header) + changelog_lines.append(header) else: - ch_lines.append(line) - subs['changelog'] = "\n".join(ch_lines) + changelog_lines.append(line) + subs['changelog'] = "\n".join(changelog_lines) # See: http://www.zarb.org/~jasonc/macros.php # Pickup any special files @@ -174,6 +155,7 @@ def generate_spec_contents(args, tmpl_fn, revno, version): '%{_bindir}/*', '/usr/lib/cloud-init/*', ] + # Since setup.py installs them # all, we need to selectively # knock off the wrong ones and @@ -192,10 +174,7 @@ def generate_spec_contents(args, tmpl_fn, revno, version): subs['post_remove'] = post_remove subs['files'] = other_files - with open(tmpl_fn, 'r') as fh: - tmpl = tempita.Template(fh.read()) - contents = tmpl.substitute(**subs) - return contents + return templater.render_from_file(tmpl_fn, params=subs) def archive_code(): @@ -216,31 +195,28 @@ def main(): # Clean out the root dir and make sure the dirs we want are in place root_dir = os.path.expanduser("~/rpmbuild") - info("Cleaning %r" % (root_dir)) if os.path.isdir(root_dir): shutil.rmtree(root_dir) - arc_dir = os.path.join(root_dir, 'SOURCES') - for d in [root_dir, arc_dir]: - os.makedirs(d) - + arc_dir = util.abs_join(root_dir, 'SOURCES') + util.ensure_dirs([root_dir, arc_dir]) + # Archive the code - (revno, version, archive_fn) = archive_code() + cmd = [sys.executable, + util.abs_join(os.getcwd(), 'make-tarball')] + (stdout, _stderr) = util.subp(cmd) + archive_fn = stdout.strip() real_archive_fn = os.path.join(arc_dir, os.path.basename(archive_fn)) shutil.move(archive_fn, real_archive_fn) - info("Archived code to %r" % (real_archive_fn)) # Form the spec file to be used - tmpl_fn = os.path.join(os.getcwd(), 'redhat', 'cloud-init.spec') - info("Generating spec file from template %r" % (tmpl_fn)) - contents = generate_spec_contents(args, tmpl_fn, revno, version) + tmpl_fn = util.abs_join(os.getcwd(), 'redhat', 'cloud-init.spec') + contents = generate_spec_contents(args, tmpl_fn) spec_fn = os.path.join(root_dir, 'cloud-init.spec') - with open(spec_fn, 'w') as fh: - fh.write(contents) - info("Wrote spec file to %r" % (spec_fn)) + util.write_file(spec_fn, contents) # Now build it! cmd = ['rpmbuild', '-ba', spec_fn] - tiny_p(cmd, capture=False) + util.subp(cmd, capture=False) info("Rpmbuild completed!") # Copy the items built to our local dir @@ -251,11 +227,10 @@ def main(): (os.path.join(root_dir, 'RPMS')))) globs.extend(glob.glob("%s/*.rpm" % (os.path.join(root_dir, 'SRPMS')))) - for fn in globs: - n = os.path.basename(fn) - tgt_fn = os.path.join(os.getcwd(), n) - shutil.move(fn, tgt_fn) - info("Copied %s to %s" % (n, tgt_fn)) + for rpm_fn in globs: + tgt_fn = util.abs_join(os.getcwd(), os.path.basename(rpm_fn)) + shutil.move(rpm_fn, tgt_fn) + print(tgt_fn) return 0 diff --git a/packages/make-tarball b/packages/make-tarball index 98f669a9..479e11af 100755 --- a/packages/make-tarball +++ b/packages/make-tarball @@ -8,78 +8,56 @@ import sys import tempfile -def join(*paths): - p = os.path.join(*paths) - return os.path.abspath(p) +# Use the util functions from cloudinit +possible_topdir = os.path.normpath(os.path.join(os.path.abspath( + sys.argv[0]), os.pardir, os.pardir)) +if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): + sys.path.insert(0, possible_topdir) +from cloudinit import util -def tiny_p(cmd): - # Darn python 2.6 doesn't have check_output (argggg) - sp = subprocess.Popen(cmd, stdout=subprocess.PIPE, - stderr=subprocess.PIPE, stdin=None) - (out, err) = sp.communicate() - if sp.returncode not in [0]: - raise RuntimeError("Failed running %s [rc=%s] (%s, %s)" - % (cmd, sp.returncode, out, err)) - return (out, err) +def main(args): -@contextlib.contextmanager -def tmpdir(): - t = tempfile.mkdtemp() - try: - yield t - finally: - shutil.rmtree(t) - + base_fn = None + if args: + base_fn = args[0] + with util.tempdir() as tdir: -def main(args): + if not base_fn: + (stdout, _stderr) = util.subp(['bzr', 'revno']) + revno = stdout.strip() - tag = None - if args: - tag = args[0] - - with tmpdir() as td: - (stdout, _stderr) = tiny_p(['bzr', 'revno']) - revno = stdout.strip() - - cmd = [sys.executable, join(os.pardir, 'tools', 'read-version')] - (stdout, _stderr) = tiny_p(cmd) - version = stdout.strip() - - owcd = os.getcwd() - os.chdir(os.path.abspath(os.pardir)) - if not os.path.exists('setup.py'): - raise RuntimeError("No setup.py found in %s" % (os.getcwd())) - - cmd = ['bzr', 'ls', '--versioned'] - (stdout, _stderr) = tiny_p(cmd) - fns = [] - for fn in stdout.splitlines(): - fn = fn.strip() - if not fn or fn.startswith("."): - continue - fns.append(fn) - bfn = 'cloud-init-%s-%s' % (version, revno) - os.makedirs(join(td, bfn)) - - for fn in fns: - if os.path.isfile(fn): - shutil.copy(fn, join(td, bfn, fn)) - else: - shutil.copytree(fn, join(td, bfn, fn)) - - fn = '%s.tar.gz' % (bfn) - o_fn = join(td, fn) - cmd = ['tar', '-czf', o_fn, '-C', join(td), bfn] - tiny_p(cmd) - - os.chdir(owcd) - shutil.move(o_fn, fn) - - out = [revno, version, bfn, os.path.abspath(fn)] - print('\t'.join(out)) + cmd = [sys.executable, + util.abs_join(os.pardir, 'tools', 'read-version')] + (stdout, _stderr) = util.subp(cmd) + version = stdout.strip() + base_fn = 'cloud-init-%s-%s' % (version, revno) + + util.ensure_dir(util.abs_join(tdir, base_fn)) + arch_fn = '%s.tar.gz' % (base_fn) + + with util.chdir(os.pardir): + (stdout, _stderr) = util.subp(['bzr', 'ls', '--versioned']) + fns = [fn for fn in stdout.splitlines() + if fn and not fn.startswith('.')] + # TODO - only copy the right files + # ie do a recursive versioned... + for fn in fns: + if os.path.isfile(fn): + shutil.copy(fn, util.abs_join(tdir, base_fn, fn)) + else: + shutil.copytree(fn, util.abs_join(tdir, base_fn, fn)) + + cmd = ['tar', '-czf', + util.abs_join(tdir, arch_fn), + '-C', tdir, base_fn] + util.subp(cmd) + + shutil.move(util.abs_join(tdir, arch_fn), + util.abs_join(os.getcwd(), arch_fn)) + print(os.path.abspath(arch_fn)) return 0 -- cgit v1.2.3 From e04d4588b8972c329298d5d38c9712a5f4408e82 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 26 Jun 2012 13:08:31 -0700 Subject: 1. Fix old info call. --- packages/brpm | 1 - 1 file changed, 1 deletion(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index f3ff2f58..6870e172 100755 --- a/packages/brpm +++ b/packages/brpm @@ -217,7 +217,6 @@ def main(): # Now build it! cmd = ['rpmbuild', '-ba', spec_fn] util.subp(cmd, capture=False) - info("Rpmbuild completed!") # Copy the items built to our local dir globs = [] -- cgit v1.2.3 From c66ad5d6dbc0b7133b57092a52da09bb71157361 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 26 Jun 2012 15:20:07 -0700 Subject: 1. Add 'verbose' options to both. 2. Fixup the debian building after util changes --- packages/bddeb | 39 +++++++++++++++++++++++++++++++-------- packages/brpm | 10 +++++++++- 2 files changed, 40 insertions(+), 9 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index 5f250738..9015585b 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -13,6 +13,8 @@ if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): from cloudinit import templater from cloudinit import util +import argparse + # Package names that will showup in requires to what we can actually # use in our debian 'control' file PKG_MP = { @@ -70,6 +72,23 @@ def write_debian_folder(root, version, revno): def main(): + parser = argparse.ArgumentParser() + parser.add_argument("-n", "--no-sign", dest="sign", + help=("attempt to sign " + "the package (default: %(default)s)"), + default=True, + action='store_false') + parser.add_argument("-v", "--verbose", dest="verbose", + help=("run verbosely" + " (default: %(default)s)"), + default=False, + action='store_true') + args = parser.parse_args() + + capture = True + if args.verbose: + capture = False + with util.tempdir() as tdir: cmd = [sys.executable, @@ -95,24 +114,28 @@ def main(): base_name = os.path.basename(arch_fn)[:-len(".tar.gz")] shutil.move(util.abs_join(tdir, base_name), util.abs_join(tdir, 'cloud-init')) - + write_debian_folder(util.abs_join(tdir, 'cloud-init'), version, revno) - + tar_fn = "cloud-init_%s~%s.orig.tar.gz" % (version, revno) cmd = ['tar', '-czvf', util.abs_join(tdir, tar_fn), '-C', util.abs_join(tdir, 'cloud-init')] cmd.extend(os.listdir(util.abs_join(tdir, 'cloud-init'))) util.subp(cmd) + shutil.copy(util.abs_join(tdir, tar_fn), tar_fn) + print("Wrote out archive %r" % (util.abs_join(tar_fn))) - ocwd = os.getcwd() with util.chdir(util.abs_join(tdir, 'cloud-init')): - util.subp(['debuild'], capture=False) - debname = "cloud-init_%s~bzr%s-1_all.deb" % (version, revno) - shutil.move(debname, util.abs_join(ocwd, debname)) - - print("Wrote out debian package %s" % (util.abs_join(ocwd, debname))) + cmd = ['debuild'] + if not args.sign: + cmd.extend(['-us', '-uc']) + util.subp(cmd, capture=capture) + + debname = "cloud-init_%s~%s-1_all.deb" % (version, revno) + shutil.move(util.abs_join(tdir, debname), debname) + print("Wrote out debian package %r" % (util.abs_join(debname))) return 0 diff --git a/packages/brpm b/packages/brpm index 6870e172..b7246d8d 100755 --- a/packages/brpm +++ b/packages/brpm @@ -191,7 +191,15 @@ def main(): help="select boot type (default: %(default)s)", metavar="TYPE", default='initd', choices=['upstart', 'initd', 'systemd']) + parser.add_argument("-v", "--verbose", dest="verbose", + help=("run verbosely" + " (default: %(default)s)"), + default=False, + action='store_true') args = parser.parse_args() + capture = True + if args.verbose: + capture = False # Clean out the root dir and make sure the dirs we want are in place root_dir = os.path.expanduser("~/rpmbuild") @@ -216,7 +224,7 @@ def main(): # Now build it! cmd = ['rpmbuild', '-ba', spec_fn] - util.subp(cmd, capture=False) + util.subp(cmd, capture=capture) # Copy the items built to our local dir globs = [] -- cgit v1.2.3 From fc41d0b114ba6b6bd37d4701aeb1c8125b0e4c2d Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 27 Jun 2012 16:32:41 -0700 Subject: Take only the files in the directory, not the directory itself (this causes issues when installing) --- packages/brpm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index b7246d8d..2adbfc95 100755 --- a/packages/brpm +++ b/packages/brpm @@ -170,7 +170,8 @@ def generate_spec_contents(args, tmpl_fn): if k != args.boot: post_remove.append(v) else: - other_files.append(v) + take = v + "*" + other_files.append(take) subs['post_remove'] = post_remove subs['files'] = other_files -- cgit v1.2.3 From 1c2c043b970a62f82b5e19e368b348d48ebbb638 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 28 Jun 2012 16:48:18 -0400 Subject: packages/debian/rules: remove unused quilt section --- packages/debian/rules | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'packages') diff --git a/packages/debian/rules b/packages/debian/rules index a907b594..1739f4cf 100755 --- a/packages/debian/rules +++ b/packages/debian/rules @@ -12,16 +12,3 @@ DEB_DH_INSTALL_SOURCEDIR := debian/tmp cloud-init-fixups: install -d $(DEB_DESTDIR)/etc/rsyslog.d cp tools/21-cloudinit.conf $(DEB_DESTDIR)/etc/rsyslog.d/21-cloudinit.conf - -# You only need to run this immediately after checking out the package from -# revision control. -# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=572204 -quilt-setup: - @[ ! -d .pc ] || { echo ".pc exists. remove it and re-run to start fresh"; exit 1; } - set -e; for patch in $$(quilt series | tac); do \ - patch -p1 -R --no-backup-if-mismatch <"debian/patches/$$patch"; \ - done - quilt push -a - -.PHONY: quilt-setup - -- cgit v1.2.3 From a21edaa44a754de813df1bada063e25d5e8dfa08 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 28 Jun 2012 15:35:33 -0700 Subject: Continue working on removing and allowing the correct files in the spec generated file --- packages/brpm | 51 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 18 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 2adbfc95..51242e54 100755 --- a/packages/brpm +++ b/packages/brpm @@ -154,27 +154,41 @@ def generate_spec_contents(args, tmpl_fn): other_files = [ '%{_bindir}/*', '/usr/lib/cloud-init/*', + '/etc/init/*', + '/etc/systemd/*', + '/etc/init.d/*', ] - # Since setup.py installs them - # all, we need to selectively - # knock off the wrong ones and - # ensure the right one is kept - post_remove_keep = { - 'initd': '/etc/init.d/', - 'systemd': '/etc/systemd/', - 'upstart': '/etc/init/', + # Since setup.py installs them all, we need to selectively + # remove the wrong ones and ensure the right one/s are kept + # for the boot mode that is desired... + post_remove = { + 'initd': [ + '/etc/init.d/cloud-init-local', + '/etc/systemd/', + '/etc/init/', + ], + 'initd-local': [ + '/etc/init.d/cloud-init', + '/etc/systemd/', + '/etc/init/', + ], + # It seems like systemd can work with + # all of its files being 'active' (and not have naming + # or event name conflicts??) + 'systemd': [ + '/etc/init.d/', + '/etc/init/', + ], + 'upstart': [ + '/etc/init/cloud-init-nonet.conf', + '/etc/init/cloud-init-local.conf', + '/etc/init/', + '/etc/systemd/', + ], } - post_remove = [] - for (k, v) in post_remove_keep.iteritems(): - if k != args.boot: - post_remove.append(v) - else: - take = v + "*" - other_files.append(take) - subs['post_remove'] = post_remove + subs['post_remove'] = post_remove[args.boot] subs['files'] = other_files - return templater.render_from_file(tmpl_fn, params=subs) @@ -191,7 +205,8 @@ def main(): parser.add_argument("-b", "--boot", dest="boot", help="select boot type (default: %(default)s)", metavar="TYPE", default='initd', - choices=['upstart', 'initd', 'systemd']) + choices=('upstart', 'initd', 'systemd', + 'upstart-local', 'initd-local')) parser.add_argument("-v", "--verbose", dest="verbose", help=("run verbosely" " (default: %(default)s)"), -- cgit v1.2.3 From 27b0c2d6f19f83b453fec37e9f55f6c9513e1ce0 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 28 Jun 2012 15:41:54 -0700 Subject: 1. Match the variable names with what they are used for 2. Create a set of directories that need to be kept for the different boot modes. --- packages/brpm | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 51242e54..d2ff06f0 100755 --- a/packages/brpm +++ b/packages/brpm @@ -162,7 +162,7 @@ def generate_spec_contents(args, tmpl_fn): # Since setup.py installs them all, we need to selectively # remove the wrong ones and ensure the right one/s are kept # for the boot mode that is desired... - post_remove = { + boot_remove = { 'initd': [ '/etc/init.d/cloud-init-local', '/etc/systemd/', @@ -186,8 +186,31 @@ def generate_spec_contents(args, tmpl_fn): '/etc/init/', '/etc/systemd/', ], + 'upstart-local': [ + '/etc/init/cloud-init.conf', + '/etc/init/', + '/etc/systemd/', + ] } - subs['post_remove'] = post_remove[args.boot] + boot_keep = [ + 'systemd': [ + '/etc/systemd/*', + ], + 'upstart': [ + '/etc/init/*', + ], + 'upstart-local': [ + '/etc/init/*', + ], + 'initd-local': [ + '/etc/init.d/*', + ], + 'initd': [ + '/etc/init.d/*', + ], + ] + subs['post_remove'] = boot_remove[args.boot] + other_files.extend(boot_keep[args.boot] subs['files'] = other_files return templater.render_from_file(tmpl_fn, params=subs) -- cgit v1.2.3 From bcc21a15416f11eac1398cb8a7696557b434245c Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 28 Jun 2012 15:42:37 -0700 Subject: Remove the keep all the init directories which didn't work --- packages/brpm | 3 --- 1 file changed, 3 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index d2ff06f0..0826364f 100755 --- a/packages/brpm +++ b/packages/brpm @@ -154,9 +154,6 @@ def generate_spec_contents(args, tmpl_fn): other_files = [ '%{_bindir}/*', '/usr/lib/cloud-init/*', - '/etc/init/*', - '/etc/systemd/*', - '/etc/init.d/*', ] # Since setup.py installs them all, we need to selectively -- cgit v1.2.3 From 4b01419c139473ad368b7fca91e183ca073707c4 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 28 Jun 2012 16:13:23 -0700 Subject: Syntax error fixup --- packages/brpm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 0826364f..44fd24b3 100755 --- a/packages/brpm +++ b/packages/brpm @@ -189,7 +189,7 @@ def generate_spec_contents(args, tmpl_fn): '/etc/systemd/', ] } - boot_keep = [ + boot_keep = { 'systemd': [ '/etc/systemd/*', ], @@ -205,9 +205,9 @@ def generate_spec_contents(args, tmpl_fn): 'initd': [ '/etc/init.d/*', ], - ] + } subs['post_remove'] = boot_remove[args.boot] - other_files.extend(boot_keep[args.boot] + other_files.extend(boot_keep[args.boot]) subs['files'] = other_files return templater.render_from_file(tmpl_fn, params=subs) -- cgit v1.2.3 From 7f565b07cf7e1d05ba830d931f2d91d13b86a2e5 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Thu, 28 Jun 2012 16:32:47 -0700 Subject: Fix chopping off the wrong folers, oops --- packages/brpm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 44fd24b3..bbf30565 100755 --- a/packages/brpm +++ b/packages/brpm @@ -162,11 +162,13 @@ def generate_spec_contents(args, tmpl_fn): boot_remove = { 'initd': [ '/etc/init.d/cloud-init-local', + # Remove the other auto-start folders '/etc/systemd/', '/etc/init/', ], 'initd-local': [ '/etc/init.d/cloud-init', + # Remove the other auto-start folders '/etc/systemd/', '/etc/init/', ], @@ -174,18 +176,21 @@ def generate_spec_contents(args, tmpl_fn): # all of its files being 'active' (and not have naming # or event name conflicts??) 'systemd': [ + # Remove the other auto-start folders '/etc/init.d/', '/etc/init/', ], 'upstart': [ '/etc/init/cloud-init-nonet.conf', '/etc/init/cloud-init-local.conf', - '/etc/init/', + # Remove the other auto-start folders + '/etc/init.d/', '/etc/systemd/', ], 'upstart-local': [ '/etc/init/cloud-init.conf', - '/etc/init/', + # Remove the other auto-start folders + '/etc/init.d/', '/etc/systemd/', ] } -- cgit v1.2.3 From 505aae53f2c2a9ca363691e710c89da82137955b Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 29 Jun 2012 12:00:01 -0700 Subject: Add in the linking of the _all.deb with a symlink 'cloud-init_all.deb' --- packages/bddeb | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index 9015585b..b10f5a8e 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -133,9 +133,17 @@ def main(): cmd.extend(['-us', '-uc']) util.subp(cmd, capture=capture) - debname = "cloud-init_%s~%s-1_all.deb" % (version, revno) - shutil.move(util.abs_join(tdir, debname), debname) - print("Wrote out debian package %r" % (util.abs_join(debname))) + globs = [] + globs.extend(glob.glob("%s/*.deb" % + (os.path.join(tdir)))) + for fn in globs: + base_fn = os.path.basename(fn) + shutil.move(fn, base_fn) + print("Wrote out debian package %r" % (base_fn)) + if fn.endswith('_all.deb'): + # Add in the local link + util.del_file('cloud-init_all.deb') + util.symlink(base_fn, 'cloud-init_all.deb') return 0 -- cgit v1.2.3 From 9bb44707c1ae45574a83ea1409d53b762db912c9 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 29 Jun 2012 16:37:05 -0400 Subject: packages/bddeb: fix broken bddeb needed to import glob, and use os.symlink, not util.symlink. Also, here made the 'tar' verbose. if '-v' option given. --- packages/bddeb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index b10f5a8e..eeb64434 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -3,6 +3,7 @@ import os import shutil import sys +import glob # Use the util functions from cloudinit possible_topdir = os.path.normpath(os.path.join(os.path.abspath( @@ -123,7 +124,7 @@ def main(): util.abs_join(tdir, tar_fn), '-C', util.abs_join(tdir, 'cloud-init')] cmd.extend(os.listdir(util.abs_join(tdir, 'cloud-init'))) - util.subp(cmd) + util.subp(cmd, capture=capture) shutil.copy(util.abs_join(tdir, tar_fn), tar_fn) print("Wrote out archive %r" % (util.abs_join(tar_fn))) @@ -143,7 +144,7 @@ def main(): if fn.endswith('_all.deb'): # Add in the local link util.del_file('cloud-init_all.deb') - util.symlink(base_fn, 'cloud-init_all.deb') + os.symlink(base_fn, 'cloud-init_all.deb') return 0 -- cgit v1.2.3 From 37aa678a39d8ac568351ce754d202c1069034d1c Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Mon, 2 Jul 2012 15:40:51 -0700 Subject: 1. Fixup the setup.py to not include custom startup scripts, let the packaging solutions handle these 2. Get the cloud-init specfile working for the init.d case (with the right postun and post and install sections) a. It works!!! --- packages/brpm | 106 ++++-------------------- packages/redhat/cloud-init.spec | 179 ++++++++++++++++++++++++++++++++++------ setup.py | 8 -- 3 files changed, 171 insertions(+), 122 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index bbf30565..3abd9f15 100755 --- a/packages/brpm +++ b/packages/brpm @@ -71,6 +71,7 @@ def get_log_header(version): def format_change_line(ds, who, comment=None): + # Rpmbuild seems to be pretty strict about the date format d = ds.strftime("%a %b %d %Y") d += " - %s" % (who) if comment: @@ -134,94 +135,22 @@ def generate_spec_contents(args, tmpl_fn): changelog_lines.append(line) subs['changelog'] = "\n".join(changelog_lines) - # See: http://www.zarb.org/~jasonc/macros.php - # Pickup any special files - docs = [ - 'TODO', - 'LICENSE', - 'ChangeLog', - 'Requires', - '%{_defaultdocdir}/cloud-init/*', - ] - subs['docs'] = docs - configs = [ - 'cloud/cloud.cfg', - 'cloud/cloud.cfg.d/*.cfg', - 'cloud/cloud.cfg.d/README', - 'cloud/templates/*', - ] - subs['configs'] = configs - other_files = [ - '%{_bindir}/*', - '/usr/lib/cloud-init/*', - ] - - # Since setup.py installs them all, we need to selectively - # remove the wrong ones and ensure the right one/s are kept - # for the boot mode that is desired... - boot_remove = { - 'initd': [ - '/etc/init.d/cloud-init-local', - # Remove the other auto-start folders - '/etc/systemd/', - '/etc/init/', - ], - 'initd-local': [ - '/etc/init.d/cloud-init', - # Remove the other auto-start folders - '/etc/systemd/', - '/etc/init/', - ], - # It seems like systemd can work with - # all of its files being 'active' (and not have naming - # or event name conflicts??) - 'systemd': [ - # Remove the other auto-start folders - '/etc/init.d/', - '/etc/init/', - ], - 'upstart': [ - '/etc/init/cloud-init-nonet.conf', - '/etc/init/cloud-init-local.conf', - # Remove the other auto-start folders - '/etc/init.d/', - '/etc/systemd/', - ], - 'upstart-local': [ - '/etc/init/cloud-init.conf', - # Remove the other auto-start folders - '/etc/init.d/', - '/etc/systemd/', - ] - } - boot_keep = { - 'systemd': [ - '/etc/systemd/*', - ], - 'upstart': [ - '/etc/init/*', - ], - 'upstart-local': [ - '/etc/init/*', - ], - 'initd-local': [ - '/etc/init.d/*', - ], - 'initd': [ - '/etc/init.d/*', - ], - } - subs['post_remove'] = boot_remove[args.boot] - other_files.extend(boot_keep[args.boot]) - subs['files'] = other_files - return templater.render_from_file(tmpl_fn, params=subs) + if args.boot == 'initd': + subs['init_d'] = True + subs['init_d_local'] = False + elif args.boot == 'initd-local': + subs['init_d'] = True + subs['init_d_local'] = True + else: + subs['init_d'] = False + subs['init_d_local'] = False + + if args.boot == 'systemd': + subs['systemd'] = True + else: + subs['systemd'] = False - -def archive_code(): - (stdout, _stderr) = tiny_p([sys.executable, - join(os.getcwd(), 'make-tarball')]) - (revno, version, bname, arc_fn) = stdout.split(None) - return (revno, version, arc_fn) + return templater.render_from_file(tmpl_fn, params=subs) def main(): @@ -230,8 +159,7 @@ def main(): parser.add_argument("-b", "--boot", dest="boot", help="select boot type (default: %(default)s)", metavar="TYPE", default='initd', - choices=('upstart', 'initd', 'systemd', - 'upstart-local', 'initd-local')) + choices=('initd', 'systemd', 'initd-local')) parser.add_argument("-v", "--verbose", dest="verbose", help=("run verbosely" " (default: %(default)s)"), diff --git a/packages/redhat/cloud-init.spec b/packages/redhat/cloud-init.spec index ddb6617d..e9ce087a 100644 --- a/packages/redhat/cloud-init.spec +++ b/packages/redhat/cloud-init.spec @@ -1,5 +1,9 @@ %{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} +# See: See: http://www.zarb.org/~jasonc/macros.php +# Or: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets +# Or: http://www.rpm.org/max-rpm/ch-rpm-inside.html + Name: cloud-init Version: {{version}} Release: {{release}}%{?dist} @@ -10,27 +14,45 @@ License: GPLv3 URL: http://launchpad.net/cloud-init Source0: {{archive_name}} - BuildArch: noarch - BuildRoot: %{_tmppath} +BuildRequires: python-devel +BuildRequires: python-setuptools -{{for r in bd_requires}} -BuildRequires: {{r}} -{{endfor}} +# System util packages needed +Requires: shadow-utils +Requires: rsyslog +Requires: iproute +Requires: e2fsprogs +Requires: net-tools +Requires: procps +Requires: shadow-utils -# Install requirements +# Install pypi 'dynamic' requirements {{for r in requires}} -Requires: {{r}} +Requires: {{r}} {{endfor}} +{{if init_d}} +Requires(post): chkconfig +Requires(postun): initscripts +Requires(preun): chkconfig +Requires(preun): initscripts +{{endif}} + +{{if systemd}} +BuildRequires: systemd-units +Requires(post): systemd-units +Requires(postun): systemd-units +Requires(preun): systemd-units +{{endif}} + %description Cloud-init is a set of init scripts for cloud instances. Cloud instances need special scripts to run during initialization to retrieve and install ssh keys and to let the user run various scripts. - %prep %setup -q -n %{name}-%{version}-{{revno}} @@ -41,32 +63,139 @@ ssh keys and to let the user run various scripts. rm -rf $RPM_BUILD_ROOT %{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT -# Remove anything after it was installed?? -{{for r in post_remove}} -rm -rfv $RPM_BUILD_ROOT/{{r}} -{{endfor}} +# Note that /etc/rsyslog.d didn't exist by default until F15. +# el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420 +mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d +cp -p tools/21-cloudinit.conf \ + $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf + +{{if init_d}} +mkdir -p $RPM_BUILD_ROOT/%{_initddir}/ +{{endif}} +{{if init_d_local}} +cp -p initd/cloud-init-local $RPM_BUILD_ROOT/%{_initddir}/ +cp -p initd/cloud-config $RPM_BUILD_ROOT/%{_initddir}/ +cp -p initd/cloud-final $RPM_BUILD_ROOT/%{_initddir}/ +{{elif init_d}} +cp -p initd/cloud-init $RPM_BUILD_ROOT/%{_initddir}/ +cp -p initd/cloud-config $RPM_BUILD_ROOT/%{_initddir}/ +cp -p initd/cloud-final $RPM_BUILD_ROOT/%{_initddir}/ +{{endif}} + +{{if systemd}} +mkdir -p $RPM_BUILD_ROOT/%{_unitdir} +cp -p systemd/* $RPM_BUILD_ROOT/%{_unitdir} +{{endif}} %clean rm -rf $RPM_BUILD_ROOT +%post + +{{if systemd}} +if [ $1 -eq 1 ] +then + /bin/systemctl enable cloud-config.service >/dev/null 2>&1 || : + /bin/systemctl enable cloud-final.service >/dev/null 2>&1 || : + /bin/systemctl enable cloud-init.service >/dev/null 2>&1 || : + /bin/systemctl enable cloud-init-local.service >/dev/null 2>&1 || : +fi +{{endif}} + +{{if init_d_local}} +/sbin/chkconfig --add /etc/rc.d/init.d/cloud-init-local +{{elif init_d}} +/sbin/chkconfig --add /etc/rc.d/init.d/cloud-init +{{endif}} +{{if init_d}} +/sbin/chkconfig --add /etc/rc.d/init.d/cloud-config +/sbin/chkconfig --add /etc/rc.d/init.d/cloud-final +{{endif}} + +%preun + +{{if init_d_local}} +if [ $1 -eq 0 ] +then + /sbin/service cloud-init-local stop >/dev/null 2>&1 + /sbin/chkconfig --del cloud-init-local +fi +{{elif init_d}} +if [ $1 -eq 0 ] +then + /sbin/service cloud-init stop >/dev/null 2>&1 + /sbin/chkconfig --del cloud-init +fi +{{endif}} +{{if init_d}} +if [ $1 -eq 0 ] +then + /sbin/service cloud-config stop >/dev/null 2>&1 + /sbin/chkconfig --del cloud-config + /sbin/service cloud-final stop >/dev/null 2>&1 + /sbin/chkconfig --del cloud-final +fi +{{endif}} + +{{if systemd}} +if [ $1 -eq 0 ] +then + /bin/systemctl --no-reload disable cloud-config.service >/dev/null 2>&1 || : + /bin/systemctl --no-reload disable cloud-final.service >/dev/null 2>&1 || : + /bin/systemctl --no-reload disable cloud-init.service >/dev/null 2>&1 || : + /bin/systemctl --no-reload disable cloud-init-local.service >/dev/null 2>&1 || : +fi +{{endif}} + +%postun + +{{if systemd}} +/bin/systemctl daemon-reload >/dev/null 2>&1 || : +{{endif}} + %files +{{if init_d}} +%attr(0755, root, root) %{_initddir}/cloud-config +%attr(0755, root, root) %{_initddir}/cloud-final +{{endif}} +{{if init_d_local}} +%attr(0755, root, root) %{_initddir}/cloud-init-local +{{elif init_d}} +%attr(0755, root, root) %{_initddir}/cloud-init +{{endif}} + +{{if systemd}} +%{_unitdir}/cloud-config.service +%{_unitdir}/cloud-config.target +%{_unitdir}/cloud-init.service +%{_unitdir}/cloud-init-local.service +%{_unitdir}/cloud-final.service +{{endif}} + +# Program binaries +%{_bindir}/cloud-init* + +# There doesn't seem to be an agreed upon place for these +# although it appears the standard says /usr/lib but rpmbuild +# will try /usr/lib64 ?? +/usr/lib/%{name}/uncloud-init +/usr/lib/%{name}/write-ssh-key-fingerprints + # Docs -{{for r in docs}} -%doc {{r}} -{{endfor}} +%doc TODO LICENSE ChangeLog Requires +%doc %{_defaultdocdir}/cloud-init/* # Configs -{{for r in configs}} -%config(noreplace) %{_sysconfdir}/{{r}} -{{endfor}} - -# Other files -{{for r in files}} -{{r}} -{{endfor}} - -# Python sitelib +%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg +%dir %{_sysconfdir}/cloud/cloud.cfg.d +%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg.d/*.cfg +%config(noreplace) %{_sysconfdir}/cloud/cloud.cfg.d/README +%dir %{_sysconfdir}/cloud/templates +%config(noreplace) %{_sysconfdir}/cloud/templates/* +%config(noreplace) %{_sysconfdir}/rsyslog.d/21-cloudinit.conf + +# Python code is here... %{python_sitelib}/* %changelog diff --git a/setup.py b/setup.py index 810ebb48..d6253384 100755 --- a/setup.py +++ b/setup.py @@ -76,20 +76,12 @@ setuptools.setup(name='cloud-init', data_files=[('/etc/cloud', glob('config/*.cfg')), ('/etc/cloud/cloud.cfg.d', glob('config/cloud.cfg.d/*')), ('/etc/cloud/templates', glob('templates/*')), - # Only really need for upstart based systems - ('/etc/init', glob('upstart/*.conf')), - # Only really need for systemd based systems - ('/etc/systemd/system', glob('systemd/*.service')), - # Only really need for init.d based system - ('/etc/init.d', glob('initd/*')), ('/usr/share/cloud-init', []), ('/usr/lib/cloud-init', ['tools/uncloud-init', 'tools/write-ssh-key-fingerprints']), ('/usr/share/doc/cloud-init', filter(is_f, glob('doc/*'))), ('/usr/share/doc/cloud-init/examples', filter(is_f, glob('doc/examples/*'))), ('/usr/share/doc/cloud-init/examples/seed', filter(is_f, glob('doc/examples/seed/*'))), - # ?? - # ('/etc/profile.d', ['tools/Z99-cloud-locale-test.sh']), ], install_requires=read_requires(), ) -- cgit v1.2.3 From d0665e19efd69eee31344f1a1af212639dda0943 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 3 Jul 2012 16:04:58 -0700 Subject: Add the ability to have setup.py have a CLI option that specifies the daemon type which then later affects the installation of certain config files, which then can be extracted during package creation as needed. --- packages/brpm | 1 + packages/redhat/cloud-init.spec | 38 ++++++---------------- setup.py | 72 ++++++++++++++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 33 deletions(-) (limited to 'packages') diff --git a/packages/brpm b/packages/brpm index 3abd9f15..1212b0e4 100755 --- a/packages/brpm +++ b/packages/brpm @@ -150,6 +150,7 @@ def generate_spec_contents(args, tmpl_fn): else: subs['systemd'] = False + subs['daemon_type'] = args.boot return templater.render_from_file(tmpl_fn, params=subs) diff --git a/packages/redhat/cloud-init.spec b/packages/redhat/cloud-init.spec index e9ce087a..df13bcb7 100644 --- a/packages/redhat/cloud-init.spec +++ b/packages/redhat/cloud-init.spec @@ -1,6 +1,6 @@ %{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} -# See: See: http://www.zarb.org/~jasonc/macros.php +# See: http://www.zarb.org/~jasonc/macros.php # Or: http://fedoraproject.org/wiki/Packaging:ScriptletSnippets # Or: http://www.rpm.org/max-rpm/ch-rpm-inside.html @@ -61,7 +61,9 @@ ssh keys and to let the user run various scripts. %install rm -rf $RPM_BUILD_ROOT -%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT +%{__python} setup.py install -O1 \ + --skip-build --root $RPM_BUILD_ROOT \ + --daemon-type={{daemon_type}} # Note that /etc/rsyslog.d didn't exist by default until F15. # el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420 @@ -69,24 +71,6 @@ mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d cp -p tools/21-cloudinit.conf \ $RPM_BUILD_ROOT/%{_sysconfdir}/rsyslog.d/21-cloudinit.conf -{{if init_d}} -mkdir -p $RPM_BUILD_ROOT/%{_initddir}/ -{{endif}} -{{if init_d_local}} -cp -p initd/cloud-init-local $RPM_BUILD_ROOT/%{_initddir}/ -cp -p initd/cloud-config $RPM_BUILD_ROOT/%{_initddir}/ -cp -p initd/cloud-final $RPM_BUILD_ROOT/%{_initddir}/ -{{elif init_d}} -cp -p initd/cloud-init $RPM_BUILD_ROOT/%{_initddir}/ -cp -p initd/cloud-config $RPM_BUILD_ROOT/%{_initddir}/ -cp -p initd/cloud-final $RPM_BUILD_ROOT/%{_initddir}/ -{{endif}} - -{{if systemd}} -mkdir -p $RPM_BUILD_ROOT/%{_unitdir} -cp -p systemd/* $RPM_BUILD_ROOT/%{_unitdir} -{{endif}} - %clean rm -rf $RPM_BUILD_ROOT @@ -103,13 +87,13 @@ fi {{endif}} {{if init_d_local}} -/sbin/chkconfig --add /etc/rc.d/init.d/cloud-init-local +/sbin/chkconfig --add %{_initrddir}/cloud-init-local {{elif init_d}} -/sbin/chkconfig --add /etc/rc.d/init.d/cloud-init +/sbin/chkconfig --add %{_initrddir}/cloud-init {{endif}} {{if init_d}} -/sbin/chkconfig --add /etc/rc.d/init.d/cloud-config -/sbin/chkconfig --add /etc/rc.d/init.d/cloud-final +/sbin/chkconfig --add %{_initrddir}/cloud-config +/sbin/chkconfig --add %{_initrddir}/cloud-final {{endif}} %preun @@ -166,11 +150,7 @@ fi {{endif}} {{if systemd}} -%{_unitdir}/cloud-config.service -%{_unitdir}/cloud-config.target -%{_unitdir}/cloud-init.service -%{_unitdir}/cloud-init-local.service -%{_unitdir}/cloud-final.service +%{_unitdir}/cloud-* {{endif}} # Program binaries diff --git a/setup.py b/setup.py index d6253384..50e95e9d 100755 --- a/setup.py +++ b/setup.py @@ -26,10 +26,45 @@ import os import re import setuptools +from setuptools.command.install import install + +from distutils.command.install_data import install_data +from distutils.errors import DistutilsArgError import subprocess +def is_f(p): + return os.path.isfile(p) + + +DAEMON_FILES = { + 'initd': filter((lambda x: is_f(x) + and x.find('local') == -1), glob('initd/*')), + 'initd-local': filter((lambda x: is_f(x) + and not x.endswith('cloud-init')), glob('initd/*')), + 'systemd': filter((lambda x: is_f(x)), glob('systemd/*')), + 'upstart': filter((lambda x: is_f(x) + and x.find('local') == -1 + and x.find('nonet') == -1), glob('upstart/*')), + 'upstart-nonet': filter((lambda x: is_f(x) + and x.find('local') == -1 + and not x.endswith('cloud-init.conf')), glob('upstart/*')), + 'upstart-local': filter((lambda x: is_f(x) + and x.find('nonet') == -1 + and not x.endswith('cloud-init.conf')), glob('upstart/*')), +} +DAEMON_ROOTS = { + 'initd': '/etc/rc.d/init.d', + 'initd-local': '/etc/rc.d/init.d', + 'systemd': '/etc/systemd/system/', + 'upstart': '/etc/init/', + 'upstart-nonet': '/etc/init/', + 'upstart-local': '/etc/init/', +} +DAEMON_TYPES = sorted(list(DAEMON_ROOTS.keys())) + + def tiny_p(cmd, capture=True): # Darn python 2.6 doesn't have check_output (argggg) stdout = subprocess.PIPE @@ -46,10 +81,6 @@ def tiny_p(cmd, capture=True): return (out, err) -def is_f(p): - return os.path.isfile(p) - - def get_version(): cmd = ['tools/read-version'] (ver, _e) = tiny_p(cmd) @@ -62,6 +93,34 @@ def read_requires(): return deps.splitlines() +# TODO: Is there a better way to do this?? +class DaemonInstallData(install): + user_options = install.user_options + [ + # This will magically show up in member variable 'daemon_type' + ('daemon-type=', None, + ('daemon type to configure (%s) [default: None]') % + (", ".join(DAEMON_TYPES)) + ), + ] + + def initialize_options(self): + install.initialize_options(self) + self.daemon_type = None + + def finalize_options(self): + install.finalize_options(self) + if self.daemon_type and self.daemon_type not in DAEMON_TYPES: + raise DistutilsArgError( + ("You must specify one of (%s) when" + " specifying a daemon type!") % (", ".join(DAEMON_TYPES)) + ) + elif self.daemon_type: + self.distribution.data_files.append((DAEMON_ROOTS[self.daemon_type], + DAEMON_FILES[self.daemon_type])) + # Force that command to reinitalize (with new file list) + self.distribution.reinitialize_command('install_data', True) + + setuptools.setup(name='cloud-init', version=get_version(), description='EC2 initialisation magic', @@ -84,4 +143,9 @@ setuptools.setup(name='cloud-init', ('/usr/share/doc/cloud-init/examples/seed', filter(is_f, glob('doc/examples/seed/*'))), ], install_requires=read_requires(), + cmdclass = { + # Use a subclass for install that handles + # adding on the right daemon configuration files + 'install': DaemonInstallData, + }, ) -- cgit v1.2.3 From 51a8e6ee88e9ee83450215208e2aaad4ad2a2843 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Wed, 4 Jul 2012 13:52:34 -0700 Subject: 1. Make the debian rules file a template (and pass in the daemon-type) 2. Adjust the bddeb to pass this in (as well as other output statement being added) 3. Adjust make-tarball to only archive the bzr versioned files (using --recursive) --- packages/bddeb | 37 ++++++++++++++++++------ packages/debian/rules | 3 ++ packages/make-tarball | 78 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 81 insertions(+), 37 deletions(-) (limited to 'packages') diff --git a/packages/bddeb b/packages/bddeb index eeb64434..b5a70dd8 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -29,7 +29,7 @@ PKG_MP = { } -def write_debian_folder(root, version, revno): +def write_debian_folder(root, version, revno, daemon_type): deb_dir = util.abs_join(root, 'debian') os.makedirs(deb_dir) @@ -65,8 +65,12 @@ def write_debian_folder(root, version, revno): util.abs_join(deb_dir, 'control'), params={'requires': requires}) + templater.render_to_file(util.abs_join('debian', 'rules'), + util.abs_join(deb_dir, 'rules'), + params={'daemon_type': daemon_type}) + # Just copy the following directly - for base_fn in ['dirs', 'copyright', 'compat', 'pycompat', 'rules']: + for base_fn in ['dirs', 'copyright', 'compat', 'pycompat']: shutil.copy(util.abs_join('debian', base_fn), util.abs_join(deb_dir, base_fn)) @@ -84,6 +88,10 @@ def main(): " (default: %(default)s)"), default=False, action='store_true') + parser.add_argument("-b", "--boot", dest="boot", + help="select boot type (default: %(default)s)", + metavar="TYPE", default='upstart', + choices=('upstart', 'upstart-local')) args = parser.parse_args() capture = True @@ -101,25 +109,33 @@ def main(): (sysout, _stderr) = util.subp(cmd) revno = sysout.strip() + # This is really only a temporary archive + # since we will extract it then add in the debian + # folder, then re-archive it for debian happiness + print("Creating a temporary tarball using the 'make-tarball' helper") cmd = [sys.executable, util.abs_join(os.getcwd(), 'make-tarball')] (sysout, _stderr) = util.subp(cmd) arch_fn = sysout.strip() - tmp_arch_fn = util.abs_join(tdir, os.path.basename(arch_fn)) shutil.move(arch_fn, tmp_arch_fn) + print("Extracting temporary tarball %r" % (tmp_arch_fn)) cmd = ['tar', '-xvzf', tmp_arch_fn, '-C', tdir] - util.subp(cmd) - + util.subp(cmd, capture=capture) base_name = os.path.basename(arch_fn)[:-len(".tar.gz")] shutil.move(util.abs_join(tdir, base_name), util.abs_join(tdir, 'cloud-init')) + print("Creating a debian/ folder in %r" % + (util.abs_join(tdir, 'cloud-init'))) write_debian_folder(util.abs_join(tdir, 'cloud-init'), - version, revno) + version, revno, args.boot) + # The naming here seems to follow some debian standard + # so it will whine if it is changed... tar_fn = "cloud-init_%s~%s.orig.tar.gz" % (version, revno) + print("Archiving that new folder into %r" % (tar_fn)) cmd = ['tar', '-czvf', util.abs_join(tdir, tar_fn), '-C', util.abs_join(tdir, 'cloud-init')] @@ -127,7 +143,8 @@ def main(): util.subp(cmd, capture=capture) shutil.copy(util.abs_join(tdir, tar_fn), tar_fn) print("Wrote out archive %r" % (util.abs_join(tar_fn))) - + + print("Running 'debuild' in %r" % (util.abs_join(tdir, 'cloud-init'))) with util.chdir(util.abs_join(tdir, 'cloud-init')): cmd = ['debuild'] if not args.sign: @@ -137,14 +154,16 @@ def main(): globs = [] globs.extend(glob.glob("%s/*.deb" % (os.path.join(tdir)))) + link_fn = os.path.join(os.getcwd(), 'cloud-init_all.deb') for fn in globs: base_fn = os.path.basename(fn) shutil.move(fn, base_fn) print("Wrote out debian package %r" % (base_fn)) if fn.endswith('_all.deb'): # Add in the local link - util.del_file('cloud-init_all.deb') - os.symlink(base_fn, 'cloud-init_all.deb') + util.del_file(link_fn) + os.symlink(base_fn, link_fn) + print("Linked %r to %r" % (base_fn, link_fn)) return 0 diff --git a/packages/debian/rules b/packages/debian/rules index 1739f4cf..6814974f 100755 --- a/packages/debian/rules +++ b/packages/debian/rules @@ -7,8 +7,11 @@ binary-install/cloud-init::cloud-init-fixups include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/python-distutils.mk +DEB_PYTHON_INSTALL_ARGS_ALL += --daemon-type={{daemon_type}} + DEB_DH_INSTALL_SOURCEDIR := debian/tmp cloud-init-fixups: install -d $(DEB_DESTDIR)/etc/rsyslog.d cp tools/21-cloudinit.conf $(DEB_DESTDIR)/etc/rsyslog.d/21-cloudinit.conf + diff --git a/packages/make-tarball b/packages/make-tarball index 479e11af..43a6fc33 100755 --- a/packages/make-tarball +++ b/packages/make-tarball @@ -7,6 +7,8 @@ import subprocess import sys import tempfile +import optparse + # Use the util functions from cloudinit possible_topdir = os.path.normpath(os.path.join(os.path.abspath( @@ -17,51 +19,71 @@ if os.path.exists(os.path.join(possible_topdir, "cloudinit", "__init__.py")): from cloudinit import util -def main(args): +def find_versioned_files(): + (stdout, _stderr) = util.subp(['bzr', 'ls', '--versioned', '--recursive']) + fns = [fn for fn in stdout.splitlines() + if fn and not fn.startswith('.')] + fns.sort() + return fns - base_fn = None - if args: - base_fn = args[0] - with util.tempdir() as tdir: +def copy(fn, where_to, verbose): + if verbose: + print("Copying %r --> %r" % (fn, where_to)) + if os.path.isfile(fn): + shutil.copy(fn, where_to) + elif os.path.isdir(fn) and not os.path.isdir(where_to): + os.makedirs(where_to) + else: + raise RuntimeError("Do not know how to copy %s" % (fn)) + + +def main(): - if not base_fn: - (stdout, _stderr) = util.subp(['bzr', 'revno']) - revno = stdout.strip() - - cmd = [sys.executable, - util.abs_join(os.pardir, 'tools', 'read-version')] - (stdout, _stderr) = util.subp(cmd) - version = stdout.strip() - base_fn = 'cloud-init-%s-%s' % (version, revno) + parser = optparse.OptionParser() + parser.add_option("-f", "--file", dest="filename", + help="write archive to FILE", metavar="FILE") + parser.add_option("-v", "--verbose", + action="store_true", dest="verbose", default=False, + help="show verbose messaging") + (options, args) = parser.parse_args() + + base_fn = options.filename + if not base_fn: + (stdout, _stderr) = util.subp(['bzr', 'revno']) + revno = stdout.strip() + cmd = [sys.executable, + util.abs_join(os.pardir, 'tools', 'read-version')] + (stdout, _stderr) = util.subp(cmd) + version = stdout.strip() + base_fn = 'cloud-init-%s-%s' % (version, revno) + + with util.tempdir() as tdir: util.ensure_dir(util.abs_join(tdir, base_fn)) arch_fn = '%s.tar.gz' % (base_fn) with util.chdir(os.pardir): - (stdout, _stderr) = util.subp(['bzr', 'ls', '--versioned']) - fns = [fn for fn in stdout.splitlines() - if fn and not fn.startswith('.')] - # TODO - only copy the right files - # ie do a recursive versioned... + fns = find_versioned_files() for fn in fns: - if os.path.isfile(fn): - shutil.copy(fn, util.abs_join(tdir, base_fn, fn)) - else: - shutil.copytree(fn, util.abs_join(tdir, base_fn, fn)) + copy(fn, util.abs_join(tdir, base_fn, fn), + verbose=options.verbose) - cmd = ['tar', '-czf', - util.abs_join(tdir, arch_fn), - '-C', tdir, base_fn] - util.subp(cmd) + arch_full_fn = util.abs_join(tdir, arch_fn) + cmd = ['tar', '-czvf', arch_full_fn, '-C', tdir, base_fn] + if options.verbose: + print("Creating an archive from directory %r to %r" % + (util.abs_join(tdir, base_fn), arch_full_fn)) + util.subp(cmd, capture=(not options.verbose)) shutil.move(util.abs_join(tdir, arch_fn), util.abs_join(os.getcwd(), arch_fn)) + print(os.path.abspath(arch_fn)) return 0 if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) + sys.exit(main()) -- cgit v1.2.3 From 95711130af22f1d597aa0ab6b5a39d0af16f8a28 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Fri, 6 Jul 2012 17:03:11 -0400 Subject: setup.py: rename "daemon type" to "init system" This brings with it other changes, and also makes an install install all of the requisite init files. (ie, cloud-init needs the -local and the non-local) --- initd/cloud-config | 124 ---------------------------------------- initd/cloud-final | 124 ---------------------------------------- initd/cloud-init | 124 ---------------------------------------- initd/cloud-init-local | 124 ---------------------------------------- packages/bddeb | 4 +- packages/brpm | 2 +- packages/debian/rules | 2 +- packages/redhat/cloud-init.spec | 2 +- setup.py | 52 ++++++----------- sysvinit/cloud-config | 124 ++++++++++++++++++++++++++++++++++++++++ sysvinit/cloud-final | 124 ++++++++++++++++++++++++++++++++++++++++ sysvinit/cloud-init | 124 ++++++++++++++++++++++++++++++++++++++++ sysvinit/cloud-init-local | 124 ++++++++++++++++++++++++++++++++++++++++ 13 files changed, 520 insertions(+), 534 deletions(-) delete mode 100755 initd/cloud-config delete mode 100755 initd/cloud-final delete mode 100755 initd/cloud-init delete mode 100755 initd/cloud-init-local create mode 100755 sysvinit/cloud-config create mode 100755 sysvinit/cloud-final create mode 100755 sysvinit/cloud-init create mode 100755 sysvinit/cloud-init-local (limited to 'packages') diff --git a/initd/cloud-config b/initd/cloud-config deleted file mode 100755 index dd0bca8b..00000000 --- a/initd/cloud-config +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -# -# Copyright (C) 2012 Yahoo! Inc. -# -# Author: Joshua Harlow -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, 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 . -# - -# See: http://wiki.debian.org/LSBInitScripts -# See: http://tiny.cc/czvbgw -# See: http://www.novell.com/coolsolutions/feature/15380.html -# Also based on dhcpd in RHEL (for comparison) - -### BEGIN INIT INFO -# Provides: cloud-config -# Required-Start: cloud-init -# Should-Start: $time -# Required-Stop: -# Should-Stop: -# Default-Start: 3 5 -# Default-Stop: -# Short-Description: The config cloud-init job -# Description: Start cloud-init and runs the config phase -# and any associated config modules as desired. -### END INIT INFO - -. /etc/init.d/functions - -# Return values acc. to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - user had insufficient privileges -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) -# -# Note that starting an already running service, stopping -# or restarting a not-running service as well as the restart -# with force-reload (in case signaling is not supported) are -# considered a success. - -RETVAL=0 - -prog="cloud-init" -cloud_init="/usr/bin/cloud-init" -conf="/etc/cloud/cloud.cfg" - -# If there exists a sysconfig variable override file use it... -[ -f /etc/sysconfig/cloud-init ] && . /etc/sysconfig/cloud-init - -start() { - [ -x $cloud_init ] || return 5 - [ -f $conf ] || return 6 - - echo -n $"Starting $prog: " - $cloud_init $CLOUDINITARGS modules --mode config - RETVAL=$? - return $RETVAL -} - -stop() { - echo -n $"Shutting down $prog: " - # No-op - RETVAL=7 - return $RETVAL -} - -. /etc/init.d/functions - -case "$1" in - start) - start - RETVAL=$? - ;; - stop) - stop - RETVAL=$? - ;; - restart|try-restart|condrestart) - ## Stop the service and regardless of whether it was - ## running or not, start it again. - # - ## Note: try-restart is now part of LSB (as of 1.9). - ## RH has a similar command named condrestart. - start - RETVAL=$? - ;; - reload|force-reload) - # It does not support reload - RETVAL=3 - ;; - status) - echo -n $"Checking for service $prog:" - # Return value is slightly different for the status command: - # 0 - service up and running - # 1 - service dead, but /var/run/ pid file exists - # 2 - service dead, but /var/lock/ lock file exists - # 3 - service not running (unused) - # 4 - service status unknown :-( - # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) - RETVAL=3 - ;; - *) - echo "Usage: $0 {start|stop|status|try-restart|condrestart|restart|force-reload|reload}" - RETVAL=3 - ;; -esac - -exit $RETVAL diff --git a/initd/cloud-final b/initd/cloud-final deleted file mode 100755 index 2e462c17..00000000 --- a/initd/cloud-final +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -# -# Copyright (C) 2012 Yahoo! Inc. -# -# Author: Joshua Harlow -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, 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 . -# - -# See: http://wiki.debian.org/LSBInitScripts -# See: http://tiny.cc/czvbgw -# See: http://www.novell.com/coolsolutions/feature/15380.html -# Also based on dhcpd in RHEL (for comparison) - -### BEGIN INIT INFO -# Provides: cloud-final -# Required-Start: $all cloud-init cloud-config -# Should-Start: $time -# Required-Stop: -# Should-Stop: -# Default-Start: 3 5 -# Default-Stop: -# Short-Description: The final cloud-init job -# Description: Start cloud-init and runs the final phase -# and any associated final modules as desired. -### END INIT INFO - -. /etc/init.d/functions - -# Return values acc. to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - user had insufficient privileges -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) -# -# Note that starting an already running service, stopping -# or restarting a not-running service as well as the restart -# with force-reload (in case signaling is not supported) are -# considered a success. - -RETVAL=0 - -prog="cloud-init" -cloud_init="/usr/bin/cloud-init" -conf="/etc/cloud/cloud.cfg" - -# If there exists a sysconfig variable override file use it... -[ -f /etc/sysconfig/cloud-init ] && . /etc/sysconfig/cloud-init - -start() { - [ -x $cloud_init ] || return 5 - [ -f $conf ] || return 6 - - echo -n $"Starting $prog: " - $cloud_init $CLOUDINITARGS modules --mode final - RETVAL=$? - return $RETVAL -} - -stop() { - echo -n $"Shutting down $prog: " - # No-op - RETVAL=7 - return $RETVAL -} - -. /etc/init.d/functions - -case "$1" in - start) - start - RETVAL=$? - ;; - stop) - stop - RETVAL=$? - ;; - restart|try-restart|condrestart) - ## Stop the service and regardless of whether it was - ## running or not, start it again. - # - ## Note: try-restart is now part of LSB (as of 1.9). - ## RH has a similar command named condrestart. - start - RETVAL=$? - ;; - reload|force-reload) - # It does not support reload - RETVAL=3 - ;; - status) - echo -n $"Checking for service $prog:" - # Return value is slightly different for the status command: - # 0 - service up and running - # 1 - service dead, but /var/run/ pid file exists - # 2 - service dead, but /var/lock/ lock file exists - # 3 - service not running (unused) - # 4 - service status unknown :-( - # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) - RETVAL=3 - ;; - *) - echo "Usage: $0 {start|stop|status|try-restart|condrestart|restart|force-reload|reload}" - RETVAL=3 - ;; -esac - -exit $RETVAL diff --git a/initd/cloud-init b/initd/cloud-init deleted file mode 100755 index 7726c452..00000000 --- a/initd/cloud-init +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -# -# Copyright (C) 2012 Yahoo! Inc. -# -# Author: Joshua Harlow -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, 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 . -# - -# See: http://wiki.debian.org/LSBInitScripts -# See: http://tiny.cc/czvbgw -# See: http://www.novell.com/coolsolutions/feature/15380.html -# Also based on dhcpd in RHEL (for comparison) - -### BEGIN INIT INFO -# Provides: cloud-init -# Required-Start: $local_fs $network $named $remote_fs -# Should-Start: $time -# Required-Stop: -# Should-Stop: -# Default-Start: 3 5 -# Default-Stop: -# Short-Description: The initial cloud-init job (net and fs contingent) -# Description: Start cloud-init and runs the initialization phase -# and any associated initial modules as desired. -### END INIT INFO - -. /etc/init.d/functions - -# Return values acc. to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - user had insufficient privileges -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) -# -# Note that starting an already running service, stopping -# or restarting a not-running service as well as the restart -# with force-reload (in case signaling is not supported) are -# considered a success. - -RETVAL=0 - -prog="cloud-init" -cloud_init="/usr/bin/cloud-init" -conf="/etc/cloud/cloud.cfg" - -# If there exists a sysconfig variable override file use it... -[ -f /etc/sysconfig/cloud-init ] && . /etc/sysconfig/cloud-init - -start() { - [ -x $cloud_init ] || return 5 - [ -f $conf ] || return 6 - - echo -n $"Starting $prog: " - $cloud_init $CLOUDINITARGS init - RETVAL=$? - return $RETVAL -} - -stop() { - echo -n $"Shutting down $prog: " - # No-op - RETVAL=7 - return $RETVAL -} - -. /etc/init.d/functions - -case "$1" in - start) - start - RETVAL=$? - ;; - stop) - stop - RETVAL=$? - ;; - restart|try-restart|condrestart) - ## Stop the service and regardless of whether it was - ## running or not, start it again. - # - ## Note: try-restart is now part of LSB (as of 1.9). - ## RH has a similar command named condrestart. - start - RETVAL=$? - ;; - reload|force-reload) - # It does not support reload - RETVAL=3 - ;; - status) - echo -n $"Checking for service $prog:" - # Return value is slightly different for the status command: - # 0 - service up and running - # 1 - service dead, but /var/run/ pid file exists - # 2 - service dead, but /var/lock/ lock file exists - # 3 - service not running (unused) - # 4 - service status unknown :-( - # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) - RETVAL=3 - ;; - *) - echo "Usage: $0 {start|stop|status|try-restart|condrestart|restart|force-reload|reload}" - RETVAL=3 - ;; -esac - -exit $RETVAL diff --git a/initd/cloud-init-local b/initd/cloud-init-local deleted file mode 100755 index bf5d409a..00000000 --- a/initd/cloud-init-local +++ /dev/null @@ -1,124 +0,0 @@ -#!/bin/sh - -# -# Copyright (C) 2012 Yahoo! Inc. -# -# Author: Joshua Harlow -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 3, 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 . -# - -# See: http://wiki.debian.org/LSBInitScripts -# See: http://tiny.cc/czvbgw -# See: http://www.novell.com/coolsolutions/feature/15380.html -# Also based on dhcpd in RHEL (for comparison) - -### BEGIN INIT INFO -# Provides: cloud-init -# Required-Start: $local_fs $remote_fs -# Should-Start: $time -# Required-Stop: -# Should-Stop: -# Default-Start: 3 5 -# Default-Stop: -# Short-Description: The initial cloud-init job (local fs contingent) -# Description: Start cloud-init and runs the initialization phases -# and any associated initial modules as desired. -### END INIT INFO - -. /etc/init.d/functions - -# Return values acc. to LSB for all commands but status: -# 0 - success -# 1 - generic or unspecified error -# 2 - invalid or excess argument(s) -# 3 - unimplemented feature (e.g. "reload") -# 4 - user had insufficient privileges -# 5 - program is not installed -# 6 - program is not configured -# 7 - program is not running -# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) -# -# Note that starting an already running service, stopping -# or restarting a not-running service as well as the restart -# with force-reload (in case signaling is not supported) are -# considered a success. - -RETVAL=0 - -prog="cloud-init" -cloud_init="/usr/bin/cloud-init" -conf="/etc/cloud/cloud.cfg" - -# If there exists a sysconfig variable override file use it... -[ -f /etc/sysconfig/cloud-init ] && . /etc/sysconfig/cloud-init - -start() { - [ -x $cloud_init ] || return 5 - [ -f $conf ] || return 6 - - echo -n $"Starting $prog: " - $cloud_init $CLOUDINITARGS init --local - RETVAL=$? - return $RETVAL -} - -stop() { - echo -n $"Shutting down $prog: " - # No-op - RETVAL=7 - return $RETVAL -} - -. /etc/init.d/functions - -case "$1" in - start) - start - RETVAL=$? - ;; - stop) - stop - RETVAL=$? - ;; - restart|try-restart|condrestart) - ## Stop the service and regardless of whether it was - ## running or not, start it again. - # - ## Note: try-restart is now part of LSB (as of 1.9). - ## RH has a similar command named condrestart. - start - RETVAL=$? - ;; - reload|force-reload) - # It does not support reload - RETVAL=3 - ;; - status) - echo -n $"Checking for service $prog:" - # Return value is slightly different for the status command: - # 0 - service up and running - # 1 - service dead, but /var/run/ pid file exists - # 2 - service dead, but /var/lock/ lock file exists - # 3 - service not running (unused) - # 4 - service status unknown :-( - # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) - RETVAL=3 - ;; - *) - echo "Usage: $0 {start|stop|status|try-restart|condrestart|restart|force-reload|reload}" - RETVAL=3 - ;; -esac - -exit $RETVAL diff --git a/packages/bddeb b/packages/bddeb index b5a70dd8..10ad08b3 100755 --- a/packages/bddeb +++ b/packages/bddeb @@ -29,7 +29,7 @@ PKG_MP = { } -def write_debian_folder(root, version, revno, daemon_type): +def write_debian_folder(root, version, revno, init_sys): deb_dir = util.abs_join(root, 'debian') os.makedirs(deb_dir) @@ -67,7 +67,7 @@ def write_debian_folder(root, version, revno, daemon_type): templater.render_to_file(util.abs_join('debian', 'rules'), util.abs_join(deb_dir, 'rules'), - params={'daemon_type': daemon_type}) + params={'init_sys': init_sys}) # Just copy the following directly for base_fn in ['dirs', 'copyright', 'compat', 'pycompat']: diff --git a/packages/brpm b/packages/brpm index 1212b0e4..1d05bd2a 100755 --- a/packages/brpm +++ b/packages/brpm @@ -150,7 +150,7 @@ def generate_spec_contents(args, tmpl_fn): else: subs['systemd'] = False - subs['daemon_type'] = args.boot + subs['init_sys'] = args.boot return templater.render_from_file(tmpl_fn, params=subs) diff --git a/packages/debian/rules b/packages/debian/rules index 6814974f..87cd6538 100755 --- a/packages/debian/rules +++ b/packages/debian/rules @@ -7,7 +7,7 @@ binary-install/cloud-init::cloud-init-fixups include /usr/share/cdbs/1/rules/debhelper.mk include /usr/share/cdbs/1/class/python-distutils.mk -DEB_PYTHON_INSTALL_ARGS_ALL += --daemon-type={{daemon_type}} +DEB_PYTHON_INSTALL_ARGS_ALL += --init-system={{init_sys}} DEB_DH_INSTALL_SOURCEDIR := debian/tmp diff --git a/packages/redhat/cloud-init.spec b/packages/redhat/cloud-init.spec index df13bcb7..d0f83a4b 100644 --- a/packages/redhat/cloud-init.spec +++ b/packages/redhat/cloud-init.spec @@ -63,7 +63,7 @@ ssh keys and to let the user run various scripts. rm -rf $RPM_BUILD_ROOT %{__python} setup.py install -O1 \ --skip-build --root $RPM_BUILD_ROOT \ - --daemon-type={{daemon_type}} + --init-system={{init_sys}} # Note that /etc/rsyslog.d didn't exist by default until F15. # el6 request: https://bugzilla.redhat.com/show_bug.cgi?id=740420 diff --git a/setup.py b/setup.py index 50e95e9d..458d1a9e 100755 --- a/setup.py +++ b/setup.py @@ -38,31 +38,17 @@ def is_f(p): return os.path.isfile(p) -DAEMON_FILES = { - 'initd': filter((lambda x: is_f(x) - and x.find('local') == -1), glob('initd/*')), - 'initd-local': filter((lambda x: is_f(x) - and not x.endswith('cloud-init')), glob('initd/*')), +INITSYS_FILES = { + 'sysvinit': filter((lambda x: is_f(x)), glob('sysvinit/*')), 'systemd': filter((lambda x: is_f(x)), glob('systemd/*')), - 'upstart': filter((lambda x: is_f(x) - and x.find('local') == -1 - and x.find('nonet') == -1), glob('upstart/*')), - 'upstart-nonet': filter((lambda x: is_f(x) - and x.find('local') == -1 - and not x.endswith('cloud-init.conf')), glob('upstart/*')), - 'upstart-local': filter((lambda x: is_f(x) - and x.find('nonet') == -1 - and not x.endswith('cloud-init.conf')), glob('upstart/*')), + 'upstart': filter((lambda x: is_f(x)), glob('upstart/*')), } -DAEMON_ROOTS = { - 'initd': '/etc/rc.d/init.d', - 'initd-local': '/etc/rc.d/init.d', +INITSYS_ROOTS = { + 'sysvinit': '/etc/rc.d/init.d', 'systemd': '/etc/systemd/system/', 'upstart': '/etc/init/', - 'upstart-nonet': '/etc/init/', - 'upstart-local': '/etc/init/', } -DAEMON_TYPES = sorted(list(DAEMON_ROOTS.keys())) +INITSYS_TYPES = sorted(list(INITSYS_ROOTS.keys())) def tiny_p(cmd, capture=True): @@ -94,29 +80,29 @@ def read_requires(): # TODO: Is there a better way to do this?? -class DaemonInstallData(install): +class InitsysInstallData(install): user_options = install.user_options + [ - # This will magically show up in member variable 'daemon_type' - ('daemon-type=', None, - ('daemon type to configure (%s) [default: None]') % - (", ".join(DAEMON_TYPES)) + # This will magically show up in member variable 'init_sys' + ('init-system=', None, + ('init system to configure (%s) [default: None]') % + (", ".join(INITSYS_TYPES)) ), ] def initialize_options(self): install.initialize_options(self) - self.daemon_type = None + self.initsys = None def finalize_options(self): install.finalize_options(self) - if self.daemon_type and self.daemon_type not in DAEMON_TYPES: + if self.initsys and self.initsys not in INITSYS_TYPES: raise DistutilsArgError( ("You must specify one of (%s) when" - " specifying a daemon type!") % (", ".join(DAEMON_TYPES)) + " specifying a init system!") % (", ".join(INITSYS_TYPES)) ) - elif self.daemon_type: - self.distribution.data_files.append((DAEMON_ROOTS[self.daemon_type], - DAEMON_FILES[self.daemon_type])) + elif self.initsys: + self.distribution.data_files.append((INITSYS_ROOTS[self.initsys], + INITSYS_FILES[self.initsys])) # Force that command to reinitalize (with new file list) self.distribution.reinitialize_command('install_data', True) @@ -145,7 +131,7 @@ setuptools.setup(name='cloud-init', install_requires=read_requires(), cmdclass = { # Use a subclass for install that handles - # adding on the right daemon configuration files - 'install': DaemonInstallData, + # adding on the right init system configuration files + 'install': InitsysInstallData, }, ) diff --git a/sysvinit/cloud-config b/sysvinit/cloud-config new file mode 100755 index 00000000..dd0bca8b --- /dev/null +++ b/sysvinit/cloud-config @@ -0,0 +1,124 @@ +#!/bin/sh + +# +# Copyright (C) 2012 Yahoo! Inc. +# +# Author: Joshua Harlow +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, 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 . +# + +# See: http://wiki.debian.org/LSBInitScripts +# See: http://tiny.cc/czvbgw +# See: http://www.novell.com/coolsolutions/feature/15380.html +# Also based on dhcpd in RHEL (for comparison) + +### BEGIN INIT INFO +# Provides: cloud-config +# Required-Start: cloud-init +# Should-Start: $time +# Required-Stop: +# Should-Stop: +# Default-Start: 3 5 +# Default-Stop: +# Short-Description: The config cloud-init job +# Description: Start cloud-init and runs the config phase +# and any associated config modules as desired. +### END INIT INFO + +. /etc/init.d/functions + +# Return values acc. to LSB for all commands but status: +# 0 - success +# 1 - generic or unspecified error +# 2 - invalid or excess argument(s) +# 3 - unimplemented feature (e.g. "reload") +# 4 - user had insufficient privileges +# 5 - program is not installed +# 6 - program is not configured +# 7 - program is not running +# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) +# +# Note that starting an already running service, stopping +# or restarting a not-running service as well as the restart +# with force-reload (in case signaling is not supported) are +# considered a success. + +RETVAL=0 + +prog="cloud-init" +cloud_init="/usr/bin/cloud-init" +conf="/etc/cloud/cloud.cfg" + +# If there exists a sysconfig variable override file use it... +[ -f /etc/sysconfig/cloud-init ] && . /etc/sysconfig/cloud-init + +start() { + [ -x $cloud_init ] || return 5 + [ -f $conf ] || return 6 + + echo -n $"Starting $prog: " + $cloud_init $CLOUDINITARGS modules --mode config + RETVAL=$? + return $RETVAL +} + +stop() { + echo -n $"Shutting down $prog: " + # No-op + RETVAL=7 + return $RETVAL +} + +. /etc/init.d/functions + +case "$1" in + start) + start + RETVAL=$? + ;; + stop) + stop + RETVAL=$? + ;; + restart|try-restart|condrestart) + ## Stop the service and regardless of whether it was + ## running or not, start it again. + # + ## Note: try-restart is now part of LSB (as of 1.9). + ## RH has a similar command named condrestart. + start + RETVAL=$? + ;; + reload|force-reload) + # It does not support reload + RETVAL=3 + ;; + status) + echo -n $"Checking for service $prog:" + # Return value is slightly different for the status command: + # 0 - service up and running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running (unused) + # 4 - service status unknown :-( + # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) + RETVAL=3 + ;; + *) + echo "Usage: $0 {start|stop|status|try-restart|condrestart|restart|force-reload|reload}" + RETVAL=3 + ;; +esac + +exit $RETVAL diff --git a/sysvinit/cloud-final b/sysvinit/cloud-final new file mode 100755 index 00000000..2e462c17 --- /dev/null +++ b/sysvinit/cloud-final @@ -0,0 +1,124 @@ +#!/bin/sh + +# +# Copyright (C) 2012 Yahoo! Inc. +# +# Author: Joshua Harlow +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, 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 . +# + +# See: http://wiki.debian.org/LSBInitScripts +# See: http://tiny.cc/czvbgw +# See: http://www.novell.com/coolsolutions/feature/15380.html +# Also based on dhcpd in RHEL (for comparison) + +### BEGIN INIT INFO +# Provides: cloud-final +# Required-Start: $all cloud-init cloud-config +# Should-Start: $time +# Required-Stop: +# Should-Stop: +# Default-Start: 3 5 +# Default-Stop: +# Short-Description: The final cloud-init job +# Description: Start cloud-init and runs the final phase +# and any associated final modules as desired. +### END INIT INFO + +. /etc/init.d/functions + +# Return values acc. to LSB for all commands but status: +# 0 - success +# 1 - generic or unspecified error +# 2 - invalid or excess argument(s) +# 3 - unimplemented feature (e.g. "reload") +# 4 - user had insufficient privileges +# 5 - program is not installed +# 6 - program is not configured +# 7 - program is not running +# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) +# +# Note that starting an already running service, stopping +# or restarting a not-running service as well as the restart +# with force-reload (in case signaling is not supported) are +# considered a success. + +RETVAL=0 + +prog="cloud-init" +cloud_init="/usr/bin/cloud-init" +conf="/etc/cloud/cloud.cfg" + +# If there exists a sysconfig variable override file use it... +[ -f /etc/sysconfig/cloud-init ] && . /etc/sysconfig/cloud-init + +start() { + [ -x $cloud_init ] || return 5 + [ -f $conf ] || return 6 + + echo -n $"Starting $prog: " + $cloud_init $CLOUDINITARGS modules --mode final + RETVAL=$? + return $RETVAL +} + +stop() { + echo -n $"Shutting down $prog: " + # No-op + RETVAL=7 + return $RETVAL +} + +. /etc/init.d/functions + +case "$1" in + start) + start + RETVAL=$? + ;; + stop) + stop + RETVAL=$? + ;; + restart|try-restart|condrestart) + ## Stop the service and regardless of whether it was + ## running or not, start it again. + # + ## Note: try-restart is now part of LSB (as of 1.9). + ## RH has a similar command named condrestart. + start + RETVAL=$? + ;; + reload|force-reload) + # It does not support reload + RETVAL=3 + ;; + status) + echo -n $"Checking for service $prog:" + # Return value is slightly different for the status command: + # 0 - service up and running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running (unused) + # 4 - service status unknown :-( + # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) + RETVAL=3 + ;; + *) + echo "Usage: $0 {start|stop|status|try-restart|condrestart|restart|force-reload|reload}" + RETVAL=3 + ;; +esac + +exit $RETVAL diff --git a/sysvinit/cloud-init b/sysvinit/cloud-init new file mode 100755 index 00000000..7726c452 --- /dev/null +++ b/sysvinit/cloud-init @@ -0,0 +1,124 @@ +#!/bin/sh + +# +# Copyright (C) 2012 Yahoo! Inc. +# +# Author: Joshua Harlow +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, 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 . +# + +# See: http://wiki.debian.org/LSBInitScripts +# See: http://tiny.cc/czvbgw +# See: http://www.novell.com/coolsolutions/feature/15380.html +# Also based on dhcpd in RHEL (for comparison) + +### BEGIN INIT INFO +# Provides: cloud-init +# Required-Start: $local_fs $network $named $remote_fs +# Should-Start: $time +# Required-Stop: +# Should-Stop: +# Default-Start: 3 5 +# Default-Stop: +# Short-Description: The initial cloud-init job (net and fs contingent) +# Description: Start cloud-init and runs the initialization phase +# and any associated initial modules as desired. +### END INIT INFO + +. /etc/init.d/functions + +# Return values acc. to LSB for all commands but status: +# 0 - success +# 1 - generic or unspecified error +# 2 - invalid or excess argument(s) +# 3 - unimplemented feature (e.g. "reload") +# 4 - user had insufficient privileges +# 5 - program is not installed +# 6 - program is not configured +# 7 - program is not running +# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) +# +# Note that starting an already running service, stopping +# or restarting a not-running service as well as the restart +# with force-reload (in case signaling is not supported) are +# considered a success. + +RETVAL=0 + +prog="cloud-init" +cloud_init="/usr/bin/cloud-init" +conf="/etc/cloud/cloud.cfg" + +# If there exists a sysconfig variable override file use it... +[ -f /etc/sysconfig/cloud-init ] && . /etc/sysconfig/cloud-init + +start() { + [ -x $cloud_init ] || return 5 + [ -f $conf ] || return 6 + + echo -n $"Starting $prog: " + $cloud_init $CLOUDINITARGS init + RETVAL=$? + return $RETVAL +} + +stop() { + echo -n $"Shutting down $prog: " + # No-op + RETVAL=7 + return $RETVAL +} + +. /etc/init.d/functions + +case "$1" in + start) + start + RETVAL=$? + ;; + stop) + stop + RETVAL=$? + ;; + restart|try-restart|condrestart) + ## Stop the service and regardless of whether it was + ## running or not, start it again. + # + ## Note: try-restart is now part of LSB (as of 1.9). + ## RH has a similar command named condrestart. + start + RETVAL=$? + ;; + reload|force-reload) + # It does not support reload + RETVAL=3 + ;; + status) + echo -n $"Checking for service $prog:" + # Return value is slightly different for the status command: + # 0 - service up and running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running (unused) + # 4 - service status unknown :-( + # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) + RETVAL=3 + ;; + *) + echo "Usage: $0 {start|stop|status|try-restart|condrestart|restart|force-reload|reload}" + RETVAL=3 + ;; +esac + +exit $RETVAL diff --git a/sysvinit/cloud-init-local b/sysvinit/cloud-init-local new file mode 100755 index 00000000..bf5d409a --- /dev/null +++ b/sysvinit/cloud-init-local @@ -0,0 +1,124 @@ +#!/bin/sh + +# +# Copyright (C) 2012 Yahoo! Inc. +# +# Author: Joshua Harlow +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3, 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 . +# + +# See: http://wiki.debian.org/LSBInitScripts +# See: http://tiny.cc/czvbgw +# See: http://www.novell.com/coolsolutions/feature/15380.html +# Also based on dhcpd in RHEL (for comparison) + +### BEGIN INIT INFO +# Provides: cloud-init +# Required-Start: $local_fs $remote_fs +# Should-Start: $time +# Required-Stop: +# Should-Stop: +# Default-Start: 3 5 +# Default-Stop: +# Short-Description: The initial cloud-init job (local fs contingent) +# Description: Start cloud-init and runs the initialization phases +# and any associated initial modules as desired. +### END INIT INFO + +. /etc/init.d/functions + +# Return values acc. to LSB for all commands but status: +# 0 - success +# 1 - generic or unspecified error +# 2 - invalid or excess argument(s) +# 3 - unimplemented feature (e.g. "reload") +# 4 - user had insufficient privileges +# 5 - program is not installed +# 6 - program is not configured +# 7 - program is not running +# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) +# +# Note that starting an already running service, stopping +# or restarting a not-running service as well as the restart +# with force-reload (in case signaling is not supported) are +# considered a success. + +RETVAL=0 + +prog="cloud-init" +cloud_init="/usr/bin/cloud-init" +conf="/etc/cloud/cloud.cfg" + +# If there exists a sysconfig variable override file use it... +[ -f /etc/sysconfig/cloud-init ] && . /etc/sysconfig/cloud-init + +start() { + [ -x $cloud_init ] || return 5 + [ -f $conf ] || return 6 + + echo -n $"Starting $prog: " + $cloud_init $CLOUDINITARGS init --local + RETVAL=$? + return $RETVAL +} + +stop() { + echo -n $"Shutting down $prog: " + # No-op + RETVAL=7 + return $RETVAL +} + +. /etc/init.d/functions + +case "$1" in + start) + start + RETVAL=$? + ;; + stop) + stop + RETVAL=$? + ;; + restart|try-restart|condrestart) + ## Stop the service and regardless of whether it was + ## running or not, start it again. + # + ## Note: try-restart is now part of LSB (as of 1.9). + ## RH has a similar command named condrestart. + start + RETVAL=$? + ;; + reload|force-reload) + # It does not support reload + RETVAL=3 + ;; + status) + echo -n $"Checking for service $prog:" + # Return value is slightly different for the status command: + # 0 - service up and running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running (unused) + # 4 - service status unknown :-( + # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) + RETVAL=3 + ;; + *) + echo "Usage: $0 {start|stop|status|try-restart|condrestart|restart|force-reload|reload}" + RETVAL=3 + ;; +esac + +exit $RETVAL -- cgit v1.2.3