forked from ungleich-public/cdist
move scripts/* to bin/
This commit is contained in:
parent
3f1939716f
commit
fdc1ab93e9
3 changed files with 0 additions and 0 deletions
97
bin/cdist
Executable file
97
bin/cdist
Executable file
|
|
@ -0,0 +1,97 @@
|
|||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# 2010-2016 Nico Schottelius (nico-cdist at schottelius.org)
|
||||
# 2016 Darko Poljak (darko.poljak at gmail.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/>.
|
||||
#
|
||||
#
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
|
||||
cdist_bin = os.path.abspath(__file__)
|
||||
if os.path.islink(cdist_bin):
|
||||
cdist_bin = os.readlink(cdist_bin)
|
||||
cdist_dir = os.path.abspath(os.path.join(os.path.dirname(cdist_bin), os.pardir))
|
||||
sys.path.insert(0, cdist_dir)
|
||||
|
||||
import cdist
|
||||
import cdist.argparse
|
||||
import cdist.banner
|
||||
import cdist.config
|
||||
import cdist.install
|
||||
import cdist.shell
|
||||
import cdist.inventory
|
||||
|
||||
|
||||
def commandline():
|
||||
"""Parse command line"""
|
||||
|
||||
# preos subcommand hack
|
||||
if len(sys.argv) > 1 and sys.argv[1] == 'preos':
|
||||
return cdist.preos.PreOS.commandline(sys.argv[1:])
|
||||
parser, cfg = cdist.argparse.parse_and_configure(sys.argv[1:])
|
||||
args = cfg.get_args()
|
||||
|
||||
# Work around python 3.3 bug:
|
||||
# http://bugs.python.org/issue16308
|
||||
# http://bugs.python.org/issue9253
|
||||
|
||||
# FIXME: catching AttributeError also hides
|
||||
# real problems.. try a different way
|
||||
|
||||
# FIXME: we always print main help, not
|
||||
# the help of the actual parser being used!
|
||||
try:
|
||||
getattr(args, "func")
|
||||
except AttributeError:
|
||||
parser['main'].print_help()
|
||||
sys.exit(0)
|
||||
|
||||
args.func(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if sys.version < cdist.MIN_SUPPORTED_PYTHON_VERSION:
|
||||
print('Python >= {} is required on the source host.'.format(
|
||||
cdist.MIN_SUPPORTED_PYTHON_VERSIO), file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
exit_code = 0
|
||||
|
||||
try:
|
||||
import re
|
||||
import os
|
||||
|
||||
if re.match("__", os.path.basename(sys.argv[0])):
|
||||
import cdist.emulator
|
||||
emulator = cdist.emulator.Emulator(sys.argv)
|
||||
emulator.run()
|
||||
else:
|
||||
commandline()
|
||||
|
||||
except KeyboardInterrupt:
|
||||
exit_code = 2
|
||||
|
||||
except cdist.Error as e:
|
||||
log = logging.getLogger("cdist")
|
||||
log.error(e)
|
||||
exit_code = 1
|
||||
|
||||
sys.exit(exit_code)
|
||||
326
bin/cdist-dump
Executable file
326
bin/cdist-dump
Executable file
|
|
@ -0,0 +1,326 @@
|
|||
#!/bin/sh
|
||||
|
||||
VERSION="0.0.1"
|
||||
RELEASE=""
|
||||
|
||||
set -u
|
||||
# set -x
|
||||
|
||||
hosts=
|
||||
cache_dir=~/.cdist/cache
|
||||
|
||||
do_all=1
|
||||
do_global_explorer=
|
||||
do_type_explorer=
|
||||
do_script_stdout=
|
||||
do_script_stderr=
|
||||
do_gencode=
|
||||
do_code=
|
||||
do_messages=
|
||||
do_parameter=
|
||||
delimiter=':'
|
||||
ln=
|
||||
filename_prefix=1
|
||||
verbose=0
|
||||
|
||||
myname=${0##*/}
|
||||
|
||||
print_version()
|
||||
{
|
||||
printf "%s %s %s\n" "${myname}" "${VERSION}" "${RELEASE}"
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat << eof
|
||||
${myname}: [options] [host...]
|
||||
eof
|
||||
|
||||
print_version
|
||||
|
||||
cat << eof
|
||||
|
||||
Dump data from cache directories.
|
||||
|
||||
host
|
||||
Dump data for specified hosts. If not specified then all data
|
||||
from cache directory is dumped.
|
||||
|
||||
Options
|
||||
-a dump all
|
||||
-C CACHE-DIR use specified CACHE-DIR (default: ~/.cdist/cache)
|
||||
-c dump code-*
|
||||
-d DELIMITER delimiter used for filename and line number prefix (default: ':')
|
||||
-E dump global explorers
|
||||
-e dump type explorers
|
||||
-F disable filename prefix (enabled by default)
|
||||
-f enable filename prefix (default)
|
||||
-g dump gencode-*
|
||||
-h show this help screen and exit
|
||||
-L disable line number prefix (default)
|
||||
-l enable line number prefix (disabled by default)
|
||||
-m dump messages
|
||||
-o dump executions' stdout
|
||||
-p dump parameters
|
||||
-r dump executions' stderr
|
||||
-V show version and exit
|
||||
-v increase verbosity
|
||||
eof
|
||||
}
|
||||
|
||||
exit_err()
|
||||
{
|
||||
printf "%s\n" "$1"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# parse options
|
||||
while [ "$#" -ge 1 ]
|
||||
do
|
||||
case "$1" in
|
||||
-a)
|
||||
do_all=1
|
||||
;;
|
||||
-C)
|
||||
if [ "$#" -ge 2 ]
|
||||
then
|
||||
case "$2" in
|
||||
-*)
|
||||
exit_err "Missing cache directory"
|
||||
;;
|
||||
*)
|
||||
cache_dir="$2"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
else
|
||||
exit_err "Missing cache directory"
|
||||
fi
|
||||
;;
|
||||
-c)
|
||||
do_code=1
|
||||
do_all=
|
||||
;;
|
||||
-d)
|
||||
if [ "$#" -ge 2 ]
|
||||
then
|
||||
case "$2" in
|
||||
-*)
|
||||
exit_err "Missing delimiter"
|
||||
;;
|
||||
*)
|
||||
delimiter="$2"
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
else
|
||||
exit_err "Missing delimiter"
|
||||
fi
|
||||
;;
|
||||
-E)
|
||||
do_global_explorer=1
|
||||
do_all=
|
||||
;;
|
||||
-e)
|
||||
do_type_explorer=1
|
||||
do_all=
|
||||
;;
|
||||
-F)
|
||||
filename_prefix=
|
||||
;;
|
||||
-f)
|
||||
filename_prefix=1
|
||||
;;
|
||||
-g)
|
||||
do_gencode=1
|
||||
do_all=
|
||||
;;
|
||||
-h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-L)
|
||||
ln=
|
||||
;;
|
||||
-l)
|
||||
ln=1
|
||||
;;
|
||||
-m)
|
||||
do_messages=1
|
||||
do_all=
|
||||
;;
|
||||
-o)
|
||||
do_script_stdout=1
|
||||
do_all=
|
||||
;;
|
||||
-p)
|
||||
do_parameter=1
|
||||
do_all=
|
||||
;;
|
||||
-r)
|
||||
do_script_stderr=1
|
||||
do_all=
|
||||
;;
|
||||
-V)
|
||||
print_version
|
||||
exit 0
|
||||
;;
|
||||
-v)
|
||||
verbose=$((verbose + 1))
|
||||
;;
|
||||
*)
|
||||
hosts="${hosts} $1"
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
if [ "${ln}" = "1" ]
|
||||
then
|
||||
ln="NR \"${delimiter}\""
|
||||
fi
|
||||
|
||||
if [ "${filename_prefix}" = "1" ]
|
||||
then
|
||||
filename_prefix="{}${delimiter}"
|
||||
fi
|
||||
|
||||
if [ "${do_all}" = "1" ]
|
||||
then
|
||||
do_global_explorer=1
|
||||
do_type_explorer=1
|
||||
do_script_stdout=1
|
||||
do_script_stderr=1
|
||||
do_gencode=1
|
||||
do_code=1
|
||||
do_messages=1
|
||||
do_parameter=1
|
||||
fi
|
||||
|
||||
set -- -size +0
|
||||
set -- "$@" \(
|
||||
or=
|
||||
|
||||
print_verbose()
|
||||
{
|
||||
if [ "${verbose}" -ge "$1" ]
|
||||
then
|
||||
printf "%s\n" "$2"
|
||||
fi
|
||||
}
|
||||
|
||||
hor_line()
|
||||
{
|
||||
if [ $# -gt 0 ]
|
||||
then
|
||||
c="$1"
|
||||
else
|
||||
c='='
|
||||
fi
|
||||
printf "%78s\n" "" | tr ' ' "${c}"
|
||||
}
|
||||
|
||||
if [ "${do_global_explorer}" ]
|
||||
then
|
||||
print_verbose 2 "Dumping global explorers"
|
||||
# shellcheck disable=SC2086
|
||||
set -- "$@" ${or} \( \
|
||||
-path "*/explorer/*" -a \
|
||||
! -path "*/conf/*" -a \
|
||||
! -path "*/object/*/explorer/*" \
|
||||
\)
|
||||
or="-o"
|
||||
fi
|
||||
|
||||
if [ "${do_type_explorer}" ]
|
||||
then
|
||||
print_verbose 2 "Dumping type explorers"
|
||||
set -- "$@" ${or} -path "*/object/*/explorer/*"
|
||||
or="-o"
|
||||
fi
|
||||
|
||||
if [ "${do_script_stdout}" ]
|
||||
then
|
||||
print_verbose 2 "Dumping execution's stdout"
|
||||
set -- "$@" ${or} -path "*/stdout/*"
|
||||
or="-o"
|
||||
fi
|
||||
|
||||
if [ "${do_script_stderr}" ]
|
||||
then
|
||||
print_verbose 2 "Dumping execution's stderr"
|
||||
set -- "$@" ${or} -path "*/stderr/*"
|
||||
or="-o"
|
||||
fi
|
||||
|
||||
if [ "${do_gencode}" ]
|
||||
then
|
||||
print_verbose 2 "Dumping gencode-*"
|
||||
set -- "$@" ${or} \( -name "gencode-*" -a ! -path "*/stdout/*" -a ! -path "*/stderr/*" \)
|
||||
or="-o"
|
||||
fi
|
||||
|
||||
if [ "${do_code}" ]
|
||||
then
|
||||
print_verbose 2 "Dumping code-*"
|
||||
set -- "$@" ${or} \( -name "code-*" -a ! -path "*/stdout/*" -a ! -path "*/stderr/*" \)
|
||||
or="-o"
|
||||
fi
|
||||
|
||||
if [ "${do_messages}" ]
|
||||
then
|
||||
print_verbose 2 "Dumping messages"
|
||||
set -- "$@" ${or} -name "messages"
|
||||
or="-o"
|
||||
fi
|
||||
|
||||
if [ "${do_parameter}" ]
|
||||
then
|
||||
print_verbose 2 "Dumping parameters"
|
||||
set -- "$@" ${or} -path "*/parameter/*"
|
||||
or="-o"
|
||||
fi
|
||||
|
||||
set -- "$@" \)
|
||||
set -- '.' "$@" -exec awk -v prefix="${filename_prefix}" "{print prefix ${ln} \$0}" {} \;
|
||||
|
||||
# printf "+ %s\n" "$*"
|
||||
|
||||
print_verbose 2 "Using cache dir: ${cache_dir}"
|
||||
|
||||
OLD_PWD=$(pwd)
|
||||
cd "${cache_dir}" || exit
|
||||
|
||||
# If no host is specified then search all.
|
||||
[ -z "${hosts}" ] && hosts="-"
|
||||
|
||||
for host in ${hosts}
|
||||
do
|
||||
[ "${host}" = "-" ] && host=
|
||||
# find host cache directory
|
||||
host_dir=$(find . -name target_host -exec grep -l "${host}" {} +)
|
||||
print_verbose 3 "found host directory files:"
|
||||
print_verbose 3 "${host_dir}"
|
||||
|
||||
OLD_IFS="${IFS}"
|
||||
IFS="
|
||||
"
|
||||
|
||||
for d in ${host_dir}
|
||||
do
|
||||
dir=$(dirname "${d}")
|
||||
|
||||
print_verbose 0 "target host: $(cat "${dir}/target_host"), host directory: ${dir}"
|
||||
hor_line '='
|
||||
|
||||
PREV_PWD=$(pwd)
|
||||
cd "${dir}" || exit
|
||||
# set -x
|
||||
find "$@"
|
||||
# set +x
|
||||
cd "${PREV_PWD}" || exit
|
||||
done
|
||||
IFS="${OLD_IFS}"
|
||||
done
|
||||
cd "${OLD_PWD}" || exit
|
||||
159
bin/cdist-new-type
Executable file
159
bin/cdist-new-type
Executable file
|
|
@ -0,0 +1,159 @@
|
|||
#!/bin/sh
|
||||
|
||||
basename="${0##*/}"
|
||||
|
||||
if [ $# -lt 3 ]
|
||||
then
|
||||
printf "usage: %s TYPE-NAME AUTHOR-NAME AUTHOR-EMAIL [TYPE-BASE-PATH]
|
||||
TYPE-NAME Name of the type.
|
||||
AUTHOR-NAME Type author's full name.
|
||||
AUTHOR-EMAIL Type author's email.
|
||||
TYPE-BASE-PATH Path to the base directory of the type. If not set it defaults
|
||||
to '\$PWD/type'.\n" "${basename}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
type_name="$1"
|
||||
shift
|
||||
author_name="$1"
|
||||
shift
|
||||
author_email="$1"
|
||||
shift
|
||||
|
||||
if [ $# -ge 1 ]
|
||||
then
|
||||
type_base_path="$1"
|
||||
shift
|
||||
else
|
||||
#type_base_path=~/.cdist/type
|
||||
type_base_path="$PWD/type"
|
||||
fi
|
||||
|
||||
error() {
|
||||
printf "%s\n" "$*" >&2
|
||||
}
|
||||
|
||||
die() {
|
||||
error "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
cd "$type_base_path" || die "Could not change to type directory: $type_base_path.
|
||||
You have to specify type base path or run me from within a cdist conf directory,
|
||||
e.g. ~/.cdist."
|
||||
|
||||
year=$(date +%Y)
|
||||
copyright="# $year $author_name ($author_email)"
|
||||
|
||||
license="# 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/>.
|
||||
#
|
||||
"
|
||||
|
||||
set -e
|
||||
|
||||
mkdir "$type_name"
|
||||
cd "$type_name"
|
||||
|
||||
### man page
|
||||
header="cdist-type${type_name}(7)"
|
||||
header_length="${#header}"
|
||||
cat >> man.rst << DONE
|
||||
$header
|
||||
$(while [ "${header_length}" -gt 0 ]; do printf "="; header_length=$((header_length - 1)); done; printf "\n";)
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type${type_name} - TODO
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
This space intentionally left blank.
|
||||
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
None.
|
||||
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
None.
|
||||
|
||||
|
||||
BOOLEAN PARAMETERS
|
||||
------------------
|
||||
None.
|
||||
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
.. code-block:: sh
|
||||
|
||||
# TODO
|
||||
${type_name}
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
:strong:\`TODO\`\\ (7)
|
||||
|
||||
|
||||
AUTHORS
|
||||
-------
|
||||
$author_name <$author_email>
|
||||
|
||||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) $year $author_name. 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.
|
||||
DONE
|
||||
|
||||
### manifest
|
||||
cat >> manifest << DONE
|
||||
#!/bin/sh -e
|
||||
#
|
||||
${copyright}
|
||||
#
|
||||
${license}
|
||||
|
||||
os=\$(cat "\$__global/explorer/os")
|
||||
|
||||
case "\$os" in
|
||||
*)
|
||||
printf "Your operating system (%s) is currently not supported by this type (%s)\n" "\$os" "\${__type##*/}" >&2
|
||||
printf "Please contribute an implementation for it if you can.\n" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
DONE
|
||||
chmod +x manifest
|
||||
|
||||
# gencode-remote
|
||||
cat >> gencode-remote << DONE
|
||||
#!/bin/sh -e
|
||||
#
|
||||
${copyright}
|
||||
#
|
||||
${license}
|
||||
DONE
|
||||
chmod +x gencode-remote
|
||||
|
||||
printf "%s/%s\n" "$type_base_path" "$type_name"
|
||||
Loading…
Add table
Add a link
Reference in a new issue