| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
basename="${0##*/}" |
| 4 |
|
| 5 |
if [ $# -lt 3 ] |
| 6 |
then |
| 7 |
printf "usage: %s TYPE-NAME AUTHOR-NAME AUTHOR-EMAIL [TYPE-BASE-PATH] |
| 8 |
TYPE-NAME Name of the type. |
| 9 |
AUTHOR-NAME Type author's full name. |
| 10 |
AUTHOR-EMAIL Type author's email. |
| 11 |
TYPE-BASE-PATH Path to the base directory of the type. If not set it defaults |
| 12 |
to '\$PWD/type'.\n" "${basename}" |
| 13 |
exit 1 |
| 14 |
fi |
| 15 |
|
| 16 |
type_name="$1" |
| 17 |
shift |
| 18 |
author_name="$1" |
| 19 |
shift |
| 20 |
author_email="$1" |
| 21 |
shift |
| 22 |
|
| 23 |
if [ $# -ge 1 ] |
| 24 |
then |
| 25 |
type_base_path="$1" |
| 26 |
shift |
| 27 |
else |
| 28 |
#type_base_path=~/.cdist/type |
| 29 |
type_base_path="$PWD/type" |
| 30 |
fi |
| 31 |
|
| 32 |
error() { |
| 33 |
printf "%s\n" "$*" >&2 |
| 34 |
} |
| 35 |
|
| 36 |
die() { |
| 37 |
error "$@" |
| 38 |
exit 1 |
| 39 |
} |
| 40 |
|
| 41 |
cd "$type_base_path" || die "Could not change to type directory: $type_base_path. |
| 42 |
You have to specify type base path or run me from within a cdist conf directory, |
| 43 |
e.g. ~/.cdist." |
| 44 |
|
| 45 |
year=$(date +%Y) |
| 46 |
copyright="# $year $author_name ($author_email)" |
| 47 |
|
| 48 |
license="# This file is part of cdist. |
| 49 |
# |
| 50 |
# cdist is free software: you can redistribute it and/or modify |
| 51 |
# it under the terms of the GNU General Public License as published by |
| 52 |
# the Free Software Foundation, either version 3 of the License, or |
| 53 |
# (at your option) any later version. |
| 54 |
# |
| 55 |
# cdist is distributed in the hope that it will be useful, |
| 56 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 57 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 58 |
# GNU General Public License for more details. |
| 59 |
# |
| 60 |
# You should have received a copy of the GNU General Public License |
| 61 |
# along with cdist. If not, see <http://www.gnu.org/licenses/>. |
| 62 |
# |
| 63 |
" |
| 64 |
|
| 65 |
set -e |
| 66 |
|
| 67 |
mkdir "$type_name" |
| 68 |
cd "$type_name" |
| 69 |
|
| 70 |
### man page |
| 71 |
header="cdist-type${type_name}(7)" |
| 72 |
header_length="${#header}" |
| 73 |
cat >> man.rst << DONE |
| 74 |
$header |
| 75 |
$(while [ "${header_length}" -gt 0 ]; do printf "="; header_length=$((header_length - 1)); done; printf "\n";) |
| 76 |
|
| 77 |
NAME |
| 78 |
---- |
| 79 |
cdist-type${type_name} - TODO |
| 80 |
|
| 81 |
|
| 82 |
DESCRIPTION |
| 83 |
----------- |
| 84 |
This space intentionally left blank. |
| 85 |
|
| 86 |
|
| 87 |
REQUIRED PARAMETERS |
| 88 |
------------------- |
| 89 |
None. |
| 90 |
|
| 91 |
|
| 92 |
OPTIONAL PARAMETERS |
| 93 |
------------------- |
| 94 |
None. |
| 95 |
|
| 96 |
|
| 97 |
BOOLEAN PARAMETERS |
| 98 |
------------------ |
| 99 |
None. |
| 100 |
|
| 101 |
|
| 102 |
EXAMPLES |
| 103 |
-------- |
| 104 |
|
| 105 |
.. code-block:: sh |
| 106 |
|
| 107 |
# TODO |
| 108 |
${type_name} |
| 109 |
|
| 110 |
|
| 111 |
SEE ALSO |
| 112 |
-------- |
| 113 |
:strong:\`TODO\`\\ (7) |
| 114 |
|
| 115 |
|
| 116 |
AUTHORS |
| 117 |
------- |
| 118 |
$author_name <$author_email> |
| 119 |
|
| 120 |
|
| 121 |
COPYING |
| 122 |
------- |
| 123 |
Copyright \(C) $year $author_name. You can redistribute it |
| 124 |
and/or modify it under the terms of the GNU General Public License as |
| 125 |
published by the Free Software Foundation, either version 3 of the |
| 126 |
License, or (at your option) any later version. |
| 127 |
DONE |
| 128 |
|
| 129 |
### manifest |
| 130 |
cat >> manifest << DONE |
| 131 |
#!/bin/sh -e |
| 132 |
# |
| 133 |
${copyright} |
| 134 |
# |
| 135 |
${license} |
| 136 |
|
| 137 |
os=\$(cat "\$__global/explorer/os") |
| 138 |
|
| 139 |
case "\$os" in |
| 140 |
*) |
| 141 |
printf "Your operating system (%s) is currently not supported by this type (%s)\n" "\$os" "\${__type##*/}" >&2 |
| 142 |
printf "Please contribute an implementation for it if you can.\n" >&2 |
| 143 |
exit 1 |
| 144 |
;; |
| 145 |
esac |
| 146 |
DONE |
| 147 |
chmod +x manifest |
| 148 |
|
| 149 |
# gencode-remote |
| 150 |
cat >> gencode-remote << DONE |
| 151 |
#!/bin/sh -e |
| 152 |
# |
| 153 |
${copyright} |
| 154 |
# |
| 155 |
${license} |
| 156 |
DONE |
| 157 |
chmod +x gencode-remote |
| 158 |
|
| 159 |
printf "%s/%s\n" "$type_base_path" "$type_name" |