Initial commit. Includes a few types in development and __package_pkg_freebsd.

This commit is contained in:
Jake Guffey 2012-02-15 14:27:30 -05:00
parent 4a844ef265
commit 6a97cf8f26
20 changed files with 800 additions and 0 deletions

View File

@ -0,0 +1,56 @@
cdist-type__build(7)
===================
Jake Guffey <jake.guffey--@--eprotex.com>
NAME
----
cdist-type__build - Manage software build operations
DESCRIPTION
-----------
This cdist type allows you to build software on the target.
It dispatches the actual work to the build-dependant types.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
name::
The name of the software to build. Default is to use the object_id.
type::
The build type to use. Default is to build a port for direct installation
on the target host.
EXAMPLES
--------
--------------------------------------------------------------------------------
# Build and install a port
__build vim
# Build and install a port explicitly defining to use ports
__build vim --type port_freebsd
# Build a package to install via __package on another machine
__build vim --type pkg_freebsd
# Force use of a specific package type
__build nanobsd --name nanobsd-internaluse-9.0 --type nanobsd
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2012 Jake Guffey. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

46
conf/type/__build/manifest Executable file
View File

@ -0,0 +1,46 @@
#!/bin/sh
#
# 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist 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 cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# __build is an abstract type which dispatches to the lower level
# __build_$name types which do the actual interaction with the software
# build system.
#
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
else
name="$__object_id"
fi
if [ -f "$__object/parameter/type" ]; then
type="$(cat "$__object/parameter/type")"
else
type="port_freebsd"
fi
set -- "$@" "$__object_id"
cd "$__object/parameter"
for property in $(ls .); do
if [ "$property" != "type" ]; then
set -- "$@" "--$property" "$(cat "$property")"
fi
done
__build_$type "$@"

View File

@ -0,0 +1,2 @@
name
type

View File

@ -0,0 +1,69 @@
#!/bin/sh
#
# 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist 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 cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Build ports on FreeBSD
#
assert () # If condition false,
{ #+ exit from script with error message.
E_PARAM_ERR=98
E_ASSERT_FAILED=99
if [ -z "$2" ] # Not enough parameters passed.
then
return $E_PARAM_ERR # No damage done.
fi
lineno=$2
if [ ! $1 ]
then
echo "Assertion failed: \"$1\""
echo "File \"$0\", line $lineno, called by $(caller 0)"
exit $E_ASSERT_FAILED
fi
}
# Debug
#exec >&2
#set -x
if [ -f "$__object/parameter/name" ]; then
name="$__object/parameter/name"
else
name="$__object_id"
fi
# Get list of installed ports
installed="$(cat "$__object/explorer/installed")"
# Is port already built/installed? Check /var/db/ports
for PORT in $installed; do
if [ "$(eval "$PORT" : "$name")" != 0 ]; then # already installed
exit 0;
fi
done
# If not, build
echo "cd /usr/ports && "
# Debug
#set +x

View File

@ -0,0 +1,61 @@
cdist-type__package_pkg_freebsd(7)
==================================
Jake Guffey <jake.guffey--@--eprotex.com>
NAME
----
cdist-type__package_pkg_freebsd - Manage FreeBSD packages
DESCRIPTION
-----------
This type is usually used on FreeBSD to manage packages.
REQUIRED PARAMETERS
-------------------
state::
Either "installed" or "removed".
OPTIONAL PARAMETERS
-------------------
name::
If supplied, use the name and not the object id as the package name.
flavor::
If supplied, use to avoid ambiguity.
version::
If supplied, use to install a specific version of the package named.
EXAMPLES
--------
--------------------------------------------------------------------------------
# Ensure zsh is installed
__package_pkg_freebsd zsh --state installed
# Ensure vim is installed, use flavor no_x11
__package_pkg_freebsd vim --state installed --flavor no_x11
# If you don't want to follow pythonX packages, but always use python
__package_pkg_freebsd python --state installed --name python2
# Remove obsolete package
__package_pkg_freebsd puppet --state removed
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
- cdist-type__package(7)
COPYING
-------
Copyright \(C) 2012 Jake Guffey. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View File

@ -0,0 +1 @@
name

View File

@ -34,6 +34,7 @@ else
debian|ubuntu) type="apt" ;;
gentoo) type="emerge" ;;
amazon|centos|fedora|redhat) type="yum" ;;
freebsd) type="pkg_freebsd" ;;
*)
echo "Don't know how to manage packages on: $os" >&2
exit 1

View File

@ -0,0 +1,35 @@
#!/bin/sh
#
# 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist 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 cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Retrieve the status of a package - parsed dpkg output
#
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
else
name="$__object_id"
fi
# Don't produce "no pkgs installed" output -- breaks things
PKG_OUTPUT=$(pkg_info 2>&1)
if [ ! "$PKG_OUTPUT" = "pkg_info: no packages installed" ]; then
echo "$(echo "$PKG_OUTPUT" | grep "^$name-" | cut '-d ' -f1 | sed "s/$name-//g")"
fi

View File

@ -0,0 +1,135 @@
#!/bin/sh
#
# 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist 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 cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Manage packages with pkg on FreeBSD
#
assert () # If condition false,
{ #+ exit from script with error message.
E_PARAM_ERR=98
E_ASSERT_FAILED=99
if [ -z "$2" ] # Not enough parameters passed.
then
return $E_PARAM_ERR # No damage done.
fi
lineno=$2
if [ ! $1 ]
then
echo "Assertion failed: \"$1\""
echo "File \"$0\", line $lineno, called by $(caller 0)"
exit $E_ASSERT_FAILED
fi
}
# Debug
#exec >&2
#set -x
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
else
name="$__object_id"
fi
if [ -f "$__object/parameter/flavor" ]; then
flavor="$(cat "$__object/parameter/flavor")"
fi
if [ -f "$__object/parameter/version" ]; then
version="$(cat "$__object/parameter/version")"
fi
if [ -f "$__object/parameter/pkgsite" ]; then
pkgsite="$(cat "$__object/parameter/pkgsite")"
fi
state="$(cat "$__object/parameter/state")"
curr_version="$(cat "$__object/explorer/pkg_version")"
add_cmd="pkg_add"
rm_cmd="pkg_delete"
cmd=""
# Print the command to be executed
# Parms: $1 -- mode, "remove" or "add"
# $2 -- the command to be echoed
# FIXME: This is ugly.
execcmd(){
# Set the PACKAGESITE if we're ADDing a new package
if [ "$1" = "add" -a -n "$pkgsite" ]; then
# Use http.../All/ if we know the exact version we want, use .../Latest/ otherwise
[ -n "$version" ] && pkgsite="${pkgsite}/All/" || pkgsite="${pkgsite}/Latest/"
echo "${pkgsite}"
fi
echo "${2} 2>&- >&-" # Silence the output of the command
echo "status=\$?"
echo "if [ \"\$status\" -ne \"0\" ]; then"
echo " echo \"Error: ${cmd} exited nonzero with \$status\"'!' >&2"
echo " exit 1"
echo "fi"
}
if [ -n "$curr_version" ]; then # PKG *is* installed
if [ "$state" = "removed" ]; then # Shouldn't be installed
if [ -n "$flavor" ]; then
cmd="${rm_cmd} ${name}-${flavor}-${curr_version}"
else
cmd="${rm_cmd} ${name}-${curr_version}"
fi
execcmd "remove" "${cmd}"
exit 0
else # Should be installed
if [ -n "$version" ]; then # Want a specific version
if [ "$version" = "$curr_version" ]; then # Current version is correct
exit 0
else # Current version is wrong, fix
#updatepkg "$name" "$version"
assert "! ${version} = ${curr_version}" $LINENO
cmd="${rm_cmd} ${name}-${curr_version}"
execcmd "remove" "${cmd}"
cmd="${add_cmd} ${name}-${version}"
execcmd "add" "${cmd}"
fi
else # Don't care what version to use
exit 0
fi
fi
else # PKG *isn't* installed
if [ "$state" = "removed" ]; then # Shouldn't be installed
exit 0
elif [ "$state" = "installed" ]; then # Is not currently installed, should be
if [ -n "$flavor" ]; then
cmd="${add_cmd} -r ${name}-${flavor}"
else
cmd="${add_cmd} -r ${name}"
fi
if [ -n "$version" ]; then
cmd="${cmd}-${version}"
fi
execcmd "add" "${cmd}"
exit 0
fi
fi
# Debug
#set +x

View File

@ -0,0 +1,64 @@
cdist-type__package_pkg_freebsd(7)
==================================
Jake Guffey <jake.guffey--@--eprotex.com>
NAME
----
cdist-type__package_pkg_freebsd - Manage FreeBSD packages
DESCRIPTION
-----------
This type is usually used on FreeBSD to manage packages.
REQUIRED PARAMETERS
-------------------
state::
Either "installed" or "removed".
OPTIONAL PARAMETERS
-------------------
name::
If supplied, use the name and not the object id as the package name.
flavor::
If supplied, use to avoid ambiguity.
version::
If supplied, use to install a specific version of the package named.
pkgsite::
If supplied, use to install from a specific package repository.
EXAMPLES
--------
--------------------------------------------------------------------------------
# Ensure zsh is installed
__package_pkg_freebsd zsh --state installed
# Ensure vim is installed, use flavor no_x11
__package_pkg_freebsd vim --state installed --flavor no_x11
# If you don't want to follow pythonX packages, but always use python
__package_pkg_freebsd python --state installed --name python2
# Remove obsolete package
__package_pkg_freebsd puppet --state removed
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
- cdist-type__package(7)
COPYING
-------
Copyright \(C) 2012 Jake Guffey. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View File

@ -0,0 +1,4 @@
name
flavor
version
pkgsite

View File

@ -0,0 +1 @@
state

View File

@ -0,0 +1,71 @@
#!/bin/sh
#
# Copyright (C) 2011 Daniel Maher (phrawzty+cdist at gmail.com)
# Parts copyright (C) 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# This file is part of cdist (https://github.com/telmich/cdist/).
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist 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 cdist. If not, see <http://www.gnu.org/licenses/>.
#
# Debug
#exec >&2
#set -x
source="$(cat "$__object/parameter/source")"
if [ -f "$__object/parameter/destination" ]; then
destination="$(cat "$__object/parameter/destination")"
else
destination="/$__object_id"
fi
# The system binary is probably ok, but if not...
if [ -f "$__object/parameter/rsyncbin" ]; then
rsyncbin="$(cat "$__object/parameter/rsyncbin")"
else
rsyncbin=`which rsync`
fi
# Turned this into an array so that we can use the "-e" argument to get the
# "root@" stuff fixed and so that "ssh -l root" is a single arg (as rsync
# wants it to be).
args=('-a' '-e' '"ssh -l root"')
# If the --delete argument should be passed to rsync.
if [ -f "$__object/parameter/delete" ]; then
# This is from having args defined as an array previously. ${#args[@]}
# is the number of indices in args, and args[${#args[@]}]=... creates a
# new index of args, which is then filled with "--delete."
args[${#args[@]}]="--delete"
fi
cmd="${rsyncbin} ${args[@]} \"${source}\""
# If the --chroot argument was given
if [ -f "$__object/parameter/chroot" ]; then
chroot=$(cat $__object/parameter/chroot)
cmd="${cmd} \"$chroot/$destination\""
else
cmd="${cmd} \"$__target_host:$destination\""
fi
# FIXME:
# - align with __remote_{exec,copy} variables? -- done
# Run rsync (locally).
echo "${cmd}"
#set +x

View File

@ -0,0 +1,72 @@
cdist-type__rsyncer(7)
======================
Daniel Maher <phrawzty+cdist at gmail.com>
Jake Guffey <jake.guffey at eprotex.com>
NAME
----
cdist-type__rsyncer - Use rsync to copy files.
DESCRIPTION
-----------
This type is used to trigger rsync to copy files from the machine running cdist
(source) to the target machine in question (destination). The likely usage is
the rapid deployment of full directory trees, the cohorency of which can be
guarunteed with the optional --delete argument, which will remove any files
from the destination which are not present on the source.
REQUIRED PARAMETERS
-------------------
source::
The full path of the source from which to copy. This is passed directly
to rsync.
OPTIONAL PARAMETERS
-------------------
destination::
The full path of the destination. This is passed directly to rsync.
Default: object_id
delete::
If true, remove files from destination which are not in source. This is
effectively the --delete argument of rsync.
Default: false
rsyncbin::
Specify the full path to the rsync binary.
Default: `which rsync`
chroot::
Specify the use of a chroot environment. If given, rsync copies the source
to $chroot/$destination.
Default: none
EXAMPLES
--------
--------------------------------------------------------------------------------
# Basic example
__rsyncer '/home/foo' --source '/opt/dist/foo'
# Fancier example
__rsyncer FOO --source '/opt/dist/foo' --destination '/home/foo/' --delete true
# Chroot example
__rsyncer '/home/foo' --source '/opt/dist/foo' --chroot '/usr/chroot/home'
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2011-2012 Daniel Maher, Jake Guffey. Free use of this software
is granted under the terms of the GNU General Public License version 3 (GPLv3).

31
conf/type/__rsyncer/manifest Executable file
View File

@ -0,0 +1,31 @@
#!/bin/sh
#
# Copyright (C) 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# This file is part of cdist (https://github.com/telmich/cdist/).
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist 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 cdist. If not, see <http://www.gnu.org/licenses/>.
#
# Debug
#exec >&2
#set -x
# This type has a dependency of the rsync package on the "other" side.
# Ensure that it's installed.
__package rsync --state installed
# Debug
#set +x

View File

@ -0,0 +1,3 @@
destination
delete
rsyncbin

View File

@ -0,0 +1 @@
source

View File

@ -0,0 +1,98 @@
#!/bin/sh
#
# 2012 Jake Guffey (jake.guffey at eprotex.com)
#
# This file is part of cdist.
#
# cdist is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cdist 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 cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Debug
#exec >&2
#set -x
state="$(cat "$__object/parameter/status")"
### Begin forming $cmd
cmd=""
cmd="$(cat <<EOF
name="$__object_id"
# Stupid Bourne shell and its lack of array support...
rc_dirs="$(echo /etc/rc.d:/usr/local/etc/rc.d)"
exists=""
save_IFS="\$IFS"
IFS=":"
for dir in \$rc_dirs; do
[ -f "\$dir/\$name" ] && exists="\$dir/\$name"
done
IFS="\$save_IFS"
if [ -z "\$exists" ]; then
echo "\$name doesn't exist as a system service on \$__target_host." >&2
exit -1
fi
status="\$("\$exists" status || true)"
if [ "\$(expr "\$status" : "Cannot 'status' \$name. Set \${name}_enable to YES")" != "0" ]; then
echo "Can't status \$name. Set \${name}_enable to YES first in rc.conf on \$__target_host." >&2
exit -1
fi
EOF)"
### End forming $cmd
### Begin forming $running
running="$(cat <<EOF
if [ \$(expr "\$status" : ".*stopped.*") != "0" ]; then
"\$exists" start 2>&- >&-
elif [ \$(expr "\$status" : ".*not running.*") != "0" ]; then
"\$exists" start 2>&- >&-
elif [ \$(expr "\$status" : ".*dead.*") != "0" ]; then
"\$exists" restart 2>&- >&-
fi
EOF)"
### End forming $running
### Begin forming $stopped
stopped="$(cat <<EOF
if [ \$(expr "\$status" : ".*not running.*") != "0" ]; then
# Do nothing -- expr cannot handle negative fwd lookups
# (to my knowledge, anyway)
echo
elif [ \$(expr "\$status" : ".*running.*") != "0" ]; then
"\$exists" stop 2>&- >&-
fi
EOF)"
### End forming $stopped
case "$state" in
running)
cmd="$(echo "${cmd}\n${running}")"
;;
stopped)
cmd="$(echo "${cmd}\n${stopped}")"
;;
*)
echo "Unknown state: ${state}" >&2
exit 1
;;
esac
echo "${cmd}"
# Debug
#set +x

View File

@ -0,0 +1,48 @@
cdist-type__service(7)
======================
Jake Guffey <jake.guffey--@--eprotex.com>
NAME
----
cdist-type__service - Control a system service (daemon) state
DESCRIPTION
-----------
This cdist type allows you to control the state of a service (daemon).
REQUIRED PARAMETERS
-------------------
state::
State of the service: Either stopped or running.
OPTIONAL PARAMETERS
-------------------
None.
EXAMPLES
--------
--------------------------------------------------------------------------------
# Start if not running
__service syslog-ng --state running
# Stop the process if it is running
__service sshd --state stopped
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2012 Jake Guffey. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View File

@ -0,0 +1 @@
status