Compare commits

...

1 commit

Author SHA1 Message Date
Jérémy Lecour ecce011018
EvoFS : first draft
All checks were successful
Ansible Lint |Total|New|Outstanding|Fixed|Trend |:-:|:-:|:-:|:-:|:-: |2650|0|2650|0|:zzz:
gitea/ansible-roles/pipeline/head This commit looks good
2023-09-21 16:08:51 +02:00
5 changed files with 228 additions and 0 deletions

3
evofs/defaults/main.yml Normal file
View file

@ -0,0 +1,3 @@
---
evofs_base_dir: "/etc/evofs"

2
evofs/tasks/main.yml Normal file
View file

@ -0,0 +1,2 @@
---

View file

@ -0,0 +1,61 @@
#!/bin/env python
import sys
import os
import json
default_base_dir="{{ evofs_base_dir | mandatory }}"
def clean_lines(lines):
clean_lines=[]
# TODO: a map/reduce or a comprehension might be better
for line in lines:
# remove linebreaks
# TODO: see if a proper regex is needed
clean_line = line.replace("\n","")
# don't return empty lines
if len(clean_line) > 0:
clean_lines.append(clean_line)
return clean_lines
def read_entry(path):
f = open(path,"r")
lines = clean_lines(f.readlines())
if len(lines) > 1:
# return multiple lines as array
return lines
else:
# return single lines as string
return lines[0]
def build_dict(dir):
data = {}
for path in os.listdir(dir):
if os.path.isfile(os.path.join(dir, path)):
# if entry is a file, the value is the content of the file
data[path] = read_entry(os.path.join(dir, path))
elif os.path.isdir(os.path.join(dir, path)):
# is entry is a directory, add recursively
data[path] = build_dict(os.path.join(dir, path))
return data
def main():
if len(sys.argv) > 1:
basedir = sys.argv[1]
else:
basedir = default_base_dir
if os.path.isdir(basedir):
data = build_dict(basedir)
print(json.dumps(data, sort_keys=True))
sys.exit(0)
else:
print("Directory '" + basedir + "' not found", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()
sys.exit(0)

21
evofs/templates/test.py Executable file
View file

@ -0,0 +1,21 @@
#!/bin/env python3
import argparse
from pathlib import Path
parser = argparse.ArgumentParser(prog="test")
parser.add_argument("path")
args = parser.parse_args()
target_dir = Path(args.path)
if not target_dir.exists():
print("The target directory doesn't exist")
raise SystemExit(1)
for entry in target_dir.iterdir():
print(entry.name)

View file

@ -0,0 +1,141 @@
#!/bin/bash
PROGNAME="check-evoversions"
# REPOSITORY="https://gitea.evolix.org/evolix/dump-server-state"
VERSION="23.07-pre"
readonly VERSION
# base functions
show_version() {
cat <<END
${PROGNAME} version ${VERSION}
Copyright 2023 Evolix <info@evolix.fr>,
Jérémy Lecour <jlecour@evolix.fr>.
${REPOSITORY}
${PROGNAME} comes with ABSOLUTELY NO WARRANTY.This is free software,
and you are welcome to redistribute it under certain conditions.
See the GNU General Public License v3.0 for details.
END
}
show_help() {
cat <<END
${PROGNAME} is checking versions of software managed by Evolix
Usage: ${PROGNAME} [OPTIONS]
Main options
-v, --verbose print details about each task
-V, --version print version and exit
-h, --help print this message and exit
END
}
debug() {
if [ "${VERBOSE}" = "1" ]; then
msg="${1:-$(cat /dev/stdin)}"
echo "${msg}"
fi
}
add_to_temp_files() {
TEMP_FILES+=("${1}")
}
# Remove all temporary file created during the execution
clean_temp_files() {
# shellcheck disable=SC2086
rm -f "${TEMP_FILES[@]}"
}
detect_os() {
if [ -e /etc/debian_version ]; then
version=$(cut -d "." -f 1 < /etc/debian_version)
return "debian${version}"
elif uname | grep -q -i 'openbsd'; then
return "openbsd"
else
echo "Unknown/unsupported OS: $(uname -a)" >&2
exit 1
fi
}
main() {
# Initialize a list of temporary files
declare -a TEMP_FILES=()
# Any file in this list will be deleted when the program exits
trap "clean_temp_files" EXIT
os_release=$(detect_os)
versions_file=$(mktemp --tmpdir "evocheck.versions.XXXXX")
add_to_temp_files "${versions_file}"
download_versions "${versions_file}"
add_to_path "/usr/share/scripts"
grep -v '^ *#' < "${versions_file}" | while IFS= read -r line; do
local program
local version
program=$(echo "${line}" | cut -d ' ' -f 1)
version=$(echo "${line}" | cut -d ' ' -f 2)
if [ -n "${program}" ]; then
if [ -n "${version}" ]; then
check_version "${program}" "${version}"
else
failed "IS_CHECK_VERSIONS" "failed to lookup expected version for ${program}"
fi
fi
done
exit ${rc}
}
# parse options
# based on https://gist.github.com/deshion/10d3cb5f88a21671e17a
while :; do
case $1 in
-h|-\?|--help)
show_help
exit 0
;;
-V|--version)
show_version
exit 0
;;
-v|--verbose)
VERBOSE=1
;;
--)
# End of all options.
shift
break
;;
-?*)
# ignore unknown options
printf 'WARN: Unknown option : %s\n' "$1" >&2
exit 1
;;
*)
# Default case: If no more options then break out of the loop.
break
;;
esac
shift
done
# Default values
: "${VERBOSE:=0}"
export LC_ALL=C
set -u
main