mirror of
https://github.com/ben-grande/qusal.git
synced 2025-08-10 07:00:01 -04:00
test
This commit is contained in:
commit
d5a47e99fa
569 changed files with 16873 additions and 0 deletions
32
scripts/salt-fix.sh
Executable file
32
scripts/salt-fix.sh
Executable file
|
@ -0,0 +1,32 @@
|
|||
#!/bin/sh
|
||||
# shellcheck disable=SC2086
|
||||
## Based on https://salt-lint.readthedocs.io/en/latest/#fix-common-issues
|
||||
set -eu
|
||||
|
||||
command -v git >/dev/null ||
|
||||
{ printf "Missing program: git\n" >&2; exit 1; }
|
||||
cd "$(git rev-parse --show-toplevel)" || exit 1
|
||||
|
||||
find_tool="find"
|
||||
if command -v fd; then
|
||||
find_tool="fd"
|
||||
elif command -v fdfind >/dev/null; then
|
||||
find_tool="fdfind"
|
||||
fi
|
||||
|
||||
case "${find_tool}" in
|
||||
fd|fdfind) files="minion.d/qusal.conf $(${find_tool} . qusal/ --max-depth=2 --type=f --extension=sls)";;
|
||||
find) files="minion.d/qusal.conf $(find . qusal/ -maxdepth 2 -type f -name '*.sls')";;
|
||||
esac
|
||||
|
||||
## 201 - Fix trailing whitespace:
|
||||
sed -i'' -e's/[[:space:]]*$//' ${files}
|
||||
|
||||
## 206 - Fix spacing around {{ var_name }}, eg. {{env}} --> {{ env }}:
|
||||
sed -i'' -E "s/\{\{\s?([^}]*[^} ])\s?\}\}/\{\{ \1 \}\}/g" ${files}
|
||||
|
||||
## 207 - Add quotes around numeric values that start with a 0:
|
||||
sed -i'' -E "s/\b(minute|hour): (0[0-7]?)\$/\1: '\2'/" ${files}
|
||||
|
||||
## 208 - Make dir_mode, file_mode and mode arguments in the desired syntax:
|
||||
sed -i'' -E "s/\b(dir_|file_|)mode: 0?([0-7]{3})/\1mode: '0\2'/" ${files}
|
27
scripts/salt-lint.sh
Executable file
27
scripts/salt-lint.sh
Executable file
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh
|
||||
# shellcheck disable=SC2086
|
||||
set -eu
|
||||
|
||||
command -v salt-lint >/dev/null ||
|
||||
{ printf >&2 "Missing program: salt-lint\n"; exit 1; }
|
||||
command -v git >/dev/null ||
|
||||
{ printf "Missing program: git\n" >&2; exit 1; }
|
||||
cd "$(git rev-parse --show-toplevel)" || exit 1
|
||||
|
||||
possible_conf="${PWD}/.salt-lint"
|
||||
conf=""
|
||||
test -f "${possible_conf}" && conf="-c ${possible_conf}"
|
||||
|
||||
find_tool="find"
|
||||
if command -v fd; then
|
||||
find_tool="fd"
|
||||
elif command -v fdfind >/dev/null; then
|
||||
find_tool="fdfind"
|
||||
fi
|
||||
|
||||
case "${find_tool}" in
|
||||
fd|fdfind) files="minion.d/qusal.conf $(${find_tool} . qusal/ --max-depth=1 --type=f --extension=sls --extension=top)";;
|
||||
find) files="minion.d/qusal.conf $(find qusal/* -maxdepth 1 -type f \( -name '*.sls' -o -name '*.top' \))";;
|
||||
esac
|
||||
|
||||
salt-lint ${conf} ${files}
|
13
scripts/setup.sh
Executable file
13
scripts/setup.sh
Executable file
|
@ -0,0 +1,13 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
test "$(hostname)" = "dom0" || { echo "Must be run from dom0" >&2; exit 1; }
|
||||
test "$(id -u)" = "0" || exec sudo "${0}"
|
||||
|
||||
group="qusal"
|
||||
file_roots="/srv/salt/${group}"
|
||||
## Avoid having extra unwanted files.
|
||||
rm -rf "${file_roots}"
|
||||
cp -f minion.d/"${group}".conf /etc/salt/minion.d/
|
||||
mkdir -p "${file_roots}"
|
||||
cp -r "${group}"/* "${file_roots}"
|
39
scripts/shell-lint.sh
Executable file
39
scripts/shell-lint.sh
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/bin/sh
|
||||
# shellcheck disable=SC2086
|
||||
set -eu
|
||||
|
||||
group="qusal"
|
||||
|
||||
command -v shellcheck >/dev/null ||
|
||||
{ printf >&2 "Missing program: shellcheck\n"; exit 1; }
|
||||
command -v file >/dev/null ||
|
||||
{ printf >&2 "Missing program: file\n"; exit 1; }
|
||||
command -v git >/dev/null ||
|
||||
{ printf "Missing program: git\n" >&2; exit 1; }
|
||||
cd "$(git rev-parse --show-toplevel)" || exit 1
|
||||
|
||||
if command -v fd; then
|
||||
find_tool="fd"
|
||||
elif command -v fdfind >/dev/null; then
|
||||
find_tool="fdfind"
|
||||
fi
|
||||
|
||||
case "${find_tool}" in
|
||||
fd|fdfind)
|
||||
# shellcheck disable=2016,2215
|
||||
files="$(${find_tool} . "${group}"/ --hidden --exclude=zsh --type=f \
|
||||
--exec sh -c '
|
||||
case $( file -bi "$1" ) in (*/x-shellscript*)
|
||||
printf "%s\n" "$1";; esac' sh)"
|
||||
files="${files} $(${find_tool} . --max-depth=1 --type=f --extension=sh)"
|
||||
;;
|
||||
find)
|
||||
## https://unix.stackexchange.com/a/483876
|
||||
files="$(find "${group}"/ -not \( -path "*/zsh" -prune \) -type f -exec sh -c '
|
||||
case $( file -bi "$1" ) in (*/x-shellscript*) exit 0;; esac
|
||||
exit 1' sh {} \; -print)"
|
||||
files="${files} $(find . -maxdepth 1 -type f -name "*.sh")"
|
||||
;;
|
||||
esac
|
||||
|
||||
shellcheck ${files}
|
27
scripts/spec-build.sh
Executable file
27
scripts/spec-build.sh
Executable file
|
@ -0,0 +1,27 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
command -v dnf >/dev/null ||
|
||||
{ printf "Missing program: dnf\n" >&2; exit 1; }
|
||||
command -v rpmlint >/dev/null ||
|
||||
{ printf "Missing program: rpmlint\n" >&2; exit 1; }
|
||||
command -v rpmdev-setuptree >/dev/null ||
|
||||
{ printf "Missing program: rpmdev-setuptree\n" >&2; exit 1; }
|
||||
command -v rpmbuild >/dev/null ||
|
||||
{ printf "Missing program: rpmbuild\n" >&2; exit 1; }
|
||||
command -v git >/dev/null ||
|
||||
{ printf "Missing program: git\n" >&2; exit 1; }
|
||||
cd "$(git rev-parse --show-toplevel)" || exit 1
|
||||
|
||||
project="${1}"
|
||||
group="qusal"
|
||||
spec="rpm_spec/${group}-${project}.spec"
|
||||
spec_gen="./scripts/spec-gen.sh"
|
||||
|
||||
"${spec_gen}" "${project}"
|
||||
sudo dnf build-dep "${spec}"
|
||||
rpmlint "${spec}"
|
||||
rpmdev-setuptree
|
||||
cp -r "${group}/${project}" ~/rpmbuild/BUILD/"${group}-${project}"
|
||||
cp -r "${group}/${project}" ~/rpmbuild/SOURCES/"${group}-${project}"
|
||||
rpmbuild -ba "${spec}"
|
46
scripts/spec-gen.sh
Executable file
46
scripts/spec-gen.sh
Executable file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
usage(){
|
||||
echo "Usage: ${0##*/} PROJECT [PROJECT ...]"
|
||||
}
|
||||
|
||||
gen_spec(){
|
||||
project="${1}"
|
||||
group="qusal"
|
||||
if ! test -d "${group}/${project}"; then
|
||||
echo "Project doesn't exist: ${group}/${project}" >&2
|
||||
exit 1
|
||||
fi
|
||||
template="rpm_spec/example.spec.tpl"
|
||||
target="rpm_spec/${group}-${project}.spec"
|
||||
|
||||
## Test if a standard option works without error.
|
||||
"${spec_get}" "${project}" name >/dev/null
|
||||
version="$("${spec_get}" "${project}" version)"
|
||||
changelog="$("${spec_get}" "${project}" changelog)"
|
||||
requires="$("${spec_get}" "${project}" requires)"
|
||||
|
||||
sed -e "s/@VERSION@/${version}/" -e "s/@PROJECT@/${project}/" \
|
||||
-e "/@CHANGELOG@/d" "${template}" | tee "${target}" >/dev/null
|
||||
requires_key=""
|
||||
for r in $(printf %s"${requires}" | tr " " "\n"); do
|
||||
requires_key="${requires_key}\nRequires: ${r}"
|
||||
done
|
||||
sed -i "s/@REQUIRES@/${requires_key}/" "${target}" >/dev/null
|
||||
echo "${changelog}" | tee -a "${target}" >/dev/null
|
||||
}
|
||||
|
||||
case "${1-}" in
|
||||
""|-h|--?help) usage; exit 1;;
|
||||
esac
|
||||
|
||||
command -v git >/dev/null ||
|
||||
{ printf "Missing program: git\n" >&2; exit 1; }
|
||||
cd "$(git rev-parse --show-toplevel)"
|
||||
|
||||
spec_get="./scripts/spec-get.sh"
|
||||
|
||||
for p in "$@"; do
|
||||
gen_spec "${p}"
|
||||
done
|
92
scripts/spec-get.sh
Executable file
92
scripts/spec-get.sh
Executable file
|
@ -0,0 +1,92 @@
|
|||
#!/bin/sh
|
||||
# shellcheck disable=SC2034
|
||||
set -eu
|
||||
|
||||
usage(){
|
||||
names="$(find qusal -maxdepth 1 -type d | cut -d "/" -f2 | tr "\n" " ")"
|
||||
echo "Usage: ${0##*/} NAME KEY"
|
||||
echo "Example: ${0##*/} qubes-builder description"
|
||||
echo "Names: ${names}"
|
||||
echo "Keys: ${keys}"
|
||||
}
|
||||
|
||||
block_max_chars(){
|
||||
char_key="${1}"
|
||||
char_key_expanded="$(eval echo '$'"${char_key}")"
|
||||
less_than="${2}"
|
||||
if test "${#char_key_expanded}" -ge "${less_than}"; then
|
||||
echo "Error: ${char_key} is too long. Must be less than ${less_than} chars." >&2
|
||||
echo "Key contents: ${char_key_expanded}" >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
keys="name branch group file_root vendor url version project project_dir changelog readme license description summary saltfiles"
|
||||
|
||||
case "${1-}" in
|
||||
"") usage; exit 1;;
|
||||
-h|--?help) usage; exit 0;;
|
||||
esac
|
||||
case "${2-}" in
|
||||
"") usage; exit 1;;
|
||||
esac
|
||||
|
||||
command -v git >/dev/null ||
|
||||
{ printf "Missing program: git\n" >&2; exit 1; }
|
||||
cd "$(git rev-parse --show-toplevel)" || exit 1
|
||||
|
||||
name="${1}"
|
||||
key="${2}"
|
||||
branch="$(git branch --show-current)"
|
||||
group="qusal"
|
||||
block_max_chars group 70
|
||||
file_roots="/srv/salt/${group}"
|
||||
vendor="Benjamin Grande"
|
||||
|
||||
url="https://github.com/ben-grande/qusal"
|
||||
version="1.0"
|
||||
|
||||
project="${group}-${name}"
|
||||
project_dir="${group}/${name}"
|
||||
changelog="$(TZ=UTC0 git log -n 50 --format=format:"* %cd %an <%ae> - %h%n- %s%n%n" --date=format:"%a %b %d %Y" -- "${project_dir}" | sed -re "s/^- +- */- /;/^$/d")"
|
||||
readme="${project_dir}/README.md"
|
||||
if ! test -f "${readme}"; then
|
||||
echo "Project ${name} does not have README.md" >&2
|
||||
exit 1
|
||||
fi
|
||||
license="$(awk '/^License: / {print $2}' "${readme}" | head -1)"
|
||||
block_max_chars license 70
|
||||
description="$(sed -n '/^## Description/,/^## /p' "${readme}" |
|
||||
sed '1d;$d' | sed "1{/^$/d}")"
|
||||
summary="$(echo "${description}" | sed "/^$/d" | head -1)"
|
||||
block_max_chars summary 70
|
||||
|
||||
saltfiles="$(find "${project_dir}" -maxdepth 1 -name "*.sls")"
|
||||
# shellcheck disable=SC2086
|
||||
if test -n "${saltfiles}"; then
|
||||
requires="$(sed -n '/^include:$/,/^\s*$/p' ${saltfiles} | sed "/^\s*- \./d;/{/d" | grep "^\s*- " | cut -d "." -f1 | sort -u | sed "s/- //")"
|
||||
else
|
||||
requires=""
|
||||
fi
|
||||
requires_valid=""
|
||||
for r in $(printf %s"${requires}" | tr " " "\n"); do
|
||||
if ! test -d "${group}/${r}"; then
|
||||
continue
|
||||
fi
|
||||
requires_valid="${requires_valid} ${r}"
|
||||
done
|
||||
requires="${requires_valid}"
|
||||
unset requires_valid
|
||||
|
||||
if test -z "${key}" || test "$(echo "${key}" | sed "s/ //g")" = ""; then
|
||||
echo "Key has no value: ${key}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## Not evaluating variables if it contains '*'.
|
||||
case "${key}" in
|
||||
"") exit 1;;
|
||||
description) echo "${description}";;
|
||||
changelog) echo "${changelog}";;
|
||||
*) eval echo "$""${key}";;
|
||||
esac
|
Loading…
Add table
Add a link
Reference in a new issue