ajout des script de creation de l'environnement de dev Nextcloud

This commit is contained in:
philippe lhardy
2025-07-03 17:21:28 +02:00
parent fd21f5186a
commit f2ff78fa86
17 changed files with 1016 additions and 2 deletions

View File

@@ -1,9 +1,21 @@
# Plomberie pour utiliser l'algorithme du Jugement majoritaire dans des application de sondages/votes
Ce projet provient de https://www.astrolabe.coop/ pour l'ajout du jugement majoritaire dans l'application de sondage de Nextcloud : https://github.com/nextcloud/polls/issues/3472 .
## Qu'est-ce que le jugement majoritaire ?
https://fr.wikipedia.org/wiki/Jugement_majoritaire
# Libraire de calcul Jugement majoritaire
## Etude
Une étude de l'existant est dans le répertoire étude.
Après cette recherche il est évident que les implémentations à choisir sont dans https://github.com/MieuxVoter
## Préparation
Ce projet est plutot un jouet comparé à l'existant.
L'idée ici serait d'avoir une API commune ou à minima des formats d'échanges communs.
@@ -125,4 +137,19 @@ python3 convert_nextcloud_poll_csv.py ../samples/poll1.csv 'Très Bien' 'Bien' '
## Tests
Voir le README.md en anglais
Voir le README.md en anglais
# Applications de vote / sondages
|Nextcloud polls|https://github.com/nextcloud/polls|
|framadate|https://framagit.org/framasoft/framadate|
## Nextcloud Polls
https://github.com/nextcloud/polls
## Framadate ?
ex: https://framadate.org
https://framagit.org/framasoft/framadate

View File

@@ -1,7 +1,16 @@
# Library to deliver a poll result with majority judgement algorithm
# Glue to use majortiy judgement algorithm in various polls applications
Intial trigger of this project is implementation of this in Nextcloud poll app https://github.com/nextcloud/polls/issues/3472, project pushed by https://www.astrolabe.coop/
## What is majortiy judgement algorithm ?
https://en.wikipedia.org/wiki/Majority_judgment
# Library to deliver a poll result with majority judgement algorithm
After some research most of implementation is done in https://github.com/MieuxVoter
Sorry for inconvenience but currently only french version is available.
LISEZMOI.md

18
nextcloud_devenv/.gitignore vendored Normal file
View File

@@ -0,0 +1,18 @@
/home/plhardy/artisanlogiciel/code/artlog_toolbox
4create.makefile
4java.makefile
absant.sh
antify.sh
debianize.sh
doit.sh
eclipse_env.sh
generate_new.sh
locate_artlog_toolbox.sh
printclonesdep.sh
pythonize.sh
refresh_toolbox.sh
scrumify.sh
status.sh
test.txt
/bind_folder/
/snapshots/

View File

@@ -0,0 +1,16 @@
# Nextcloud Dev En
Create a dev env for nextcloud
setup databse :
./setupdatabase.sh
# not completed, done manualy
# ./setuppodman.sh
# comment out VOLUME var/www/html in 31/apache/Dockerfile
# cd podman; ./update.sh; cd 31/apache; podman build .
./runpodman.sh
./doit.sh

View File

@@ -0,0 +1,34 @@
CC=gcc
LD=gcc
CPPFLAGS=-g
BUILD=build
src=main.c
objects=$(patsubst %.c,$(BUILD)/obj/%.o,$(src))
$(objects): | $(BUILD)/obj
test:$(BUILD)/binary
mkdir -p $@
./$(BUILD)/binary test.binary >test/parse1.binary
./$(BUILD)/binary parse1.binary >test/parse2.binary
diff test/parse1.binary test/parse2.binary
$(BUILD)/binary: $(objects)
@echo link objects $(objects)
$(LD) $(LDFLAGS) $^ -o $@
$(BUILD)/obj:
mkdir -p $@
$(BUILD)/obj/%.o: %.c
@echo compile $<
@$(CC) -c $(CFLAGS) $(CPPFLAGS) $< -o $@
clean:
rm -f $(objects)
.PHONY:clean test

View File

@@ -0,0 +1 @@
source placeholder for nextcloud_devenv in c autogenerated by ./create_project.sh lun. 30 juin 2025 15:08:14 CEST

View File

@@ -0,0 +1 @@
NOJAVA='c only'

4
nextcloud_devenv/enter_root.sh Executable file
View File

@@ -0,0 +1,4 @@
#!/bin/bash
podman exec -it nextcloud_local /bin/bash

View File

@@ -0,0 +1,4 @@
#!/bin/bash
podman exec -u www-data -it nextcloud_local /bin/bash

101
nextcloud_devenv/init.sh Executable file
View File

@@ -0,0 +1,101 @@
#!/bin/bash
# search ARTLOG_TOOLBOX= within $toolboxparam file, no bash expansion is done.
extract_from_toolbox_param()
{
local toolboxparam=$1
if [[ -f $toolboxparam ]]
then
echo "extract from $toolboxparam" >&2
while read LINE
do
if [[ $LINE =~ ARTLOG_TOOLBOX=(.*) ]]
then
ARTLOG_TOOLBOX=${BASH_REMATCH[1]}
fi
done <$toolboxparam
fi
}
select_artlog_toolbox()
{
directory_name=${1:-artlog_toolbox}
potential_path=($(find .. -type d -name "$directory_name"))
# default to this.
ARTLOG_TOOLBOX=$(pwd)
toolboxparam=./toolbox.param
extract_from_toolbox_param "$toolboxparam"
echo "Current toolbox : $ARTLOG_TOOLBOX"
potential_number=${#potential_path[@]}
if (( $potential_number > 0 ))
then
for (( i=0; i<$potential_number; i++ ))
do
echo "$(( i + 1)) ${potential_path[$i]}"
done
echo "which one would you like to use (select number 1 to $potential_number) all other for current ?"
read a
if [[ -z $a ]]
then
a=0
fi
if (( $a > 0 ))
then
ARTLOG_TOOLBOX=$(readlink -f ${potential_path[$(( a - 1))]})
fi
echo "$ARTLOG_TOOLBOX"
else
echo "[INFO] No directory $directory_name name found"
fi
}
if [[ $0 =~ locate_artlog_toolbox.sh ]]
then
echo "[WARNING] function tool $0 used as main" >&2
if [[ $# > 0 ]]
then
echo "$0 called with with param $1" >&2
select_artlog_toolbox $1
else
extract_from_toolbox_param ./toolbox.param
if [[ -n $ARTLOG_TOOLBOX ]]
then
echo "$ARTLOG_TOOLBOX"
else
echo "no ARTLOG_TOOLBOX set" >&2
fi
fi
exit 0
fi
# AFTER function copied from /home/plhardy/artisanlogiciel/code/artlog_toolbox/scripts/locate_artlog_toolbox.sh
if [[ -z $ARTLOG_TOOLBOX ]]
then
ARTLOG_TOOLBOX=$(pwd)/artlog_toolbox
select_artlog_toolbox artlog_toolbox
echo "no ARTLOG_TOOLBOX found, use a dedicated one $ARTLOG_TOOLBOX"
fi
if [[ ! -d $ARTLOG_TOOLBOX ]]
then
git clone git@github.com:artlog/artlog_toolbox $ARTLOG_TOOLBOX
if [[ -d $ARTLOG_TOOLBOX ]]
then
pushd $ARTLOG_TOOLBOX
git checkout master
popd
else
echo "[ERROR] git creation of $ARTLOG_TOOLBOX failed" >&2
exit 1
fi
fi
echo "ARTLOG_TOOLBOX=$ARTLOG_TOOLBOX" >toolbox.param
$ARTLOG_TOOLBOX/deploy.sh copy

View File

@@ -0,0 +1,90 @@
# SHOULD BE INCLUDED WITH source or . from a bash script
# EXAMPLE
# log_functions=./log_functions.sh
# [[ -f $log_functions ]] || { echo "[FATAL] Missing $log_functions" >&2 ; exit 1 ;}
# source $log_functions
log_any()
{
priority=$1
shift
echo "[$priority] $@" >&2
}
log_fatal()
{
log_any FATAL "$*"
}
log_error()
{
log_any ERROR "$*"
}
log_warn()
{
log_any WARN "$*"
}
log_info()
{
log_any INFO "$*"
}
log_debug()
{
[[ -n $debug ]] && log_any DEBUG "$*"
}
deferpipe()
{
cat
echo "# <previous line> | $@"
}
autoquoteargs()
{
echo -n "$1"
shift
while [[ $# > 0 ]]
do
if [[ "$1" =~ [\ \$] ]]
then
echo -n " '$1'"
else
echo -n " $1"
fi
shift
done
echo
}
echoarray()
{
declare -a arr=("${@}")
declare -i len=${#arr[@]}
# Show passed array
for ((n = 0; n < len; n++))
do
echo -en " \"${arr[$n]}\""
done
echo
}
include_source()
{
if [[ -f $1 ]]
then
source $1
else
log_fatal "Missing $1 script"
exit 1
fi
}
verbose()
{
[[ -n $verbose ]] && log_any $verbose $@
}

View File

@@ -0,0 +1,593 @@
#!/bin/bash
# metascript to include
#
# usual way if no parameters used by outer script :
#
# source $(dirname "$0")/metascript.sh
#
# defaultmetainit $@
#
metascript_included=yes
# assume all tools are in lib/
toolsdir=$(dirname $(readlink -f $0))/lib
# all tools resources are relative to this directory
# project directory
# relative
# toolsparentdir=$(realpath --relative-to "$(pwd)" $(readlink -f $0))/
# absolute
toolsparentdir=$(realpath $(readlink -f $0))/
if [[ -z $log_functions ]]
then
log_functions=$toolsdir/log_functions.sh
[[ -f $log_functions ]] || { echo "[FATAL] Missing $log_functions" >&2 ; exit 1 ;}
source $log_functions
fi
metascript_usage()
{
cat <<EOF >&2
metascript commands :
help|usage help or usage of this {$0} tool
dryrun|show|showdoc display what should/will be done
defersource= script file defining defer() non sandard function
defer= defer function to use, default is showdoc
toolsresourcesdir= where to pick resource
default to parent of script $toolsresourcesdir
mostly used with dryrun
apply default : will actual do work without defer
EOF
}
usage()
{
echo "[WARNING} no specific usage function for {$0}, to improve by developer" >&2
echo >&2
metascript_usage
}
showinfo()
{
echo $@
}
showdoc()
{
if [[ $1 =~ ^tools/ ]]
then
# assumes it handles ENV_METASCRIPT_DEFER
$@
else
echo '```'
autoquoteargs $@
echo
echo '```'
fi
}
redirectto()
{
tofile=$1
if [[ -n $defer ]]
then
echo "Copy to $tofile"
echo '```'
cat
echo '```'
else
cat > $tofile
fi
}
execredirectfrom()
{
tofile=$1
shift
if [[ -n $defer ]]
then
echo '```'
autoquoteargs $@
echo ' < '"$tofile"
echo '```'
else
$@ < $tofile
fi
}
execredirectto()
{
tofile=$1
shift
if [[ -n $defer ]]
then
echo '```'
autoquoteargs $@
echo ' > '"$tofile"
echo '```'
else
$@ > $tofile
fi
}
pipeto()
{
if [[ -n $defer ]]
then
echo '```'
echo -n 'cat << EOF| '
autoquoteargs $@
echo
cat
echo "EOF"
echo '```'
else
cat | $@
fi
}
query_ext()
{
local prompt="$1"
local var=$2
if [[ -n $defer ]]
then
# uppercase it
eval $var=${var^^}
$defer query $prompt "$(eval echo \$$var)"
else
echo -ne $prompt
read $var
fi
}
# two arguments first prompt, second name of var
query_password()
{
local prompt="$1"
local var=$2
if [[ -n $defer ]]
then
# uppercase it
eval $var=${var^^}
$defer query_password "\"$prompt\"" "$(eval echo \$$var)"
else
read -sp "$prompt" $var
echo
fi
}
# echo yes if reply match ^[Yy]([eE][sS]|)$ or no if does not match.
query_yesno()
{
local prompt="$1"
local yesno=no
read -p "$prompt (Yes/No) " yesno
if [[ $yesno =~ ^[Yy]([eE][sS]|)$ ]]
then
echo yes
else
echo no
fi
}
# through hardcoded 'secret' variable
create_secret()
{
# global secret
# declare -g secret
# export -n secret
local -i length=$1
[[ -z $length ]] && length = 32
if (( length < 8 ))
then
log_warn "secret length $length < 8. very small"
fi
# secret=$(echo $RANDOM | md5sum | head -c $length)
secret=$(tr -dc A-Za-z0-9 </dev/urandom | head -c $length)
}
check_missing_dest_dir()
{
local dir=$1
if [[ -n $defer ]]
then
$defer "create $dir if it does not exist"
else
if [[ ! -d $dir ]]
then
echo "[ERROR] '$dir' does not exist please create it."
exit 1
fi
fi
}
sed_substitute_expr()
{
local from="$1"
shift
local to="$1"
shift
local s='/'
if [[ $from =~ [\\] ]]
then
# escape char \ should be doubled
from=${from//\\/\\\\}
fi
if [[ $from =~ $s ]]
then
# echo "[ERROR] character $s is prohibited due to sed usage" >&2
from=${from//$s/\\$s}
fi
if [[ $from =~ \[ ]]
then
from=${from//\[/\\\[}
fi
if [[ $from =~ \* ]]
then
from=${from//\*/\\\*}
fi
if [[ $from =~ ^(.*)\$$ ]]
then
from=${BASH_REMATCH[1]}'\$'
fi
if [[ $from =~ ^\^(.*)$ ]]
then
from='\^'${BASH_REMATCH[1]}
fi
if [[ $to =~ [\\] ]]
then
# escape char \ should be doubled
to=${to//\\/\\\\}
fi
if [[ $to =~ $s ]]
then
# echo "[ERROR] character $s is prohibited due to sed usage" >&2
# echo "This is a limitation of metascript.sh script, replaced by \$s" >&2
to=${to//$s/\\$s}
fi
if [[ $to =~ [\&] ]]
then
# echo "[ERROR] character & is prohibited due to sed usage" >&2
to=${to//\&/\\\&}
fi
# replace it globaly
echo "s$s$from$s$to${s}g"
}
sedreplacefromto()
{
local from="$1"
local to="$2"
shift 2
local sedexpr="$1"
execredirectto $to sed "$sedexpr" $from
shift
while [[ $# > 0 ]]
do
sedexpr="$1"
$defer sed -i "$sedexpr" $to
shift
done
}
replacefromto()
{
local from="$1"
local to="$2"
shift 2
if [[ -n $defer ]]
then
$defer "replace $@ from '$from' into '$to'"
else
local sedexpr=$(sed_substitute_expr "$1" "$2")
execredirectto $to sed "$sedexpr" $from
shift 2
while [[ $# > 0 ]]
do
sedexpr=$(sed_substitute_expr "$1" "$2")
$defer sed -i "$sedexpr" $to
shift 2
done
fi
}
sedreplacein()
{
local file=$1
shift
while [[ $# > 0 ]]
do
$defer sed -i "$1" $file
shift
done
}
replacein()
{
local infile=$1
shift
if [[ -n $defer ]]
then
$defer "replace $@ into '$infile'"
else
while [[ $# > 0 ]]
do
sedexpr=$(sed_substitute_expr "$1" "$2")
$defer sed -i "$sedexpr" $infile
shift 2
done
fi
}
parsemetaarg()
{
case $1 in
apply)
defer=
;;
defersource=*)
defersource=${1/defersource=/}
;;
defer=*)
defer=${1/defer=/}
;;
dryrun|show|showdoc)
defer=showdoc
;;
help|usage)
usage
;;
toolsresourcesdir=*)
toolsresourcesdir=${1/toolsresourcesdir=/}
;;
scl_enable=*)
scl_args=(scl enable ${1/scl_enable=/} --)
;;
*)
log_error "unrecognized argument '$1'"
usage
exit 1
;;
esac
}
enforcearg()
{
local var="$1"
local default="$2"
eval value='$'"$var"
if [[ -z $value ]]
then
log_error "{0} expect '$var' to be set ex $var=$default"
usage
exit 1
fi
}
enforcefile()
{
file="$1"
constraint="$2"
if [[ ! -f "$file" ]]
then
if [[ $constraint = exists ]]
then
log_error "[ERROR] Missing expected $file"
[[ -n $defer ]] || exit 1
fi
else
if [[ $constraint = does_not_exists ]]
then
log_error "[ERROR] '$file' already exists. Move it away"
[[ -n $defer ]] || exit 1
fi
fi
}
enforcedir()
{
dir="$1"
constraint="$2"
if [[ $constraint = does_not_exist ]]
then
if [[ -e $dir ]]
then
log_error "'$dir' already exists. Move it away"
[[ -n $defer ]] || exit 1
fi
fi
if [[ $constraint = exists ]]
then
if [[ ! -d "$dir" ]]
then
if [[ -e "$dir" ]]
then
log_error "'$dir' already exists but is not a directory as expected"
[[ -n $defer ]] || exit 1
fi
log_error "[ERROR] Missing expected directory '$dir'"
[[ -n $defer ]] || exit 1
fi
fi
}
applymetaargs()
{
if [[ -n $defer ]]
then
if [[ -n $defersource ]]
then
if [[ -f $defersource ]]
then
log_any "source $defersource"
source $defersource
else
exit_fatal "defersource $defersource provided but not a file"
fi
fi
# $showinfo "generated with $0 $allparms"
export ENV_METASCRIPT_DEFER="$defer"
export ENV_METASCRIPT_RESOURCESDIR="$toolsresourcesdir"
fi
}
defaultmetainit()
{
while [[ $# > 0 ]]
do
parsemetaarg "$1"
shift
done
applymetaargs
}
read_organisation()
{
organisation_file=$(find organisation -name '*.conf')
if [[ -f $organisation_file ]]
then
while read line
do
case $line in
name=*)
organisation_name=${line/name=/}
;;
domain=*)
organisation_domain=${line/domain=/}
;;
ldap_base=*)
organisation_ldap_base=${line/ldap_base=/}
;;
image_keyword=*)
organisation_image_keyword=${line/image_keyword=/}
;;
*)
log_warn "'$line' not recognized as an organisation parameter"
;;
esac
done < $organisation_file
fi
}
check_variable_match()
{
local var="$1"
local match="$2"
local default="$3"
local value=""
eval value='$'"$var"
if [[ -z "$value" ]]
then
echo "set $var to default value $default"
eval "$var=$default"
eval value='$'"$var"
fi
if [[ ! $value =~ $match ]]
then
log_error "$var $value should match $match"
exit 1
fi
}
check_variable_in()
{
local var="$1"
local default="$2"
shift 2
local value=""
local values=$@
eval value='$'"$var"
if [[ -z "$value" ]]
then
echo "set $var to default value $default"
eval "$var=$default"
eval value='$'"$var"
fi
while [[ $# > 0 ]]
do
if [[ "$value" = "$1" ]]
then
return
fi
shift
done
log_error "'$var' should be within $values it is '$value'"
exit 1
}
check_root()
{
if [[ -n $defer ]]
then
$defer "{$0} script to run run as root or with sudo"
else
[[ $EUID -eq 0 ]] || {
log_error "{$0} You have to be root or use sudo to run this script"
exit 1;
}
fi
}
get_timestamp_second()
{
echo "$(date +"%Y%m%d%H%M%S")"
}
if [[ -z $ENV_METASCRIPT_RESOURCESDIR ]]
then
toolsresourcesdir=$toolsparentdir
else
toolsresourcesdir=$ENV_METASCRIPT_RESOURCESDIR
fi
# quick way to give scl patches to fill scl_arg array
if [[ -f $toolsparentdir/.scl_env ]]
then
source $toolsparentdir/.scl_env
fi
# empty defer means doit
defer=$ENV_METASCRIPT_DEFER
showinfo=showinfo
allparms=$@
applymetaargs=applymetaargs

3
nextcloud_devenv/run_occ.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/bash
podman exec -u www-data -it nextcloud_local ./occ $@

68
nextcloud_devenv/runpodman.sh Executable file
View File

@@ -0,0 +1,68 @@
#!/bin/bash
source lib/metascript.sh
enforcedir polls exists
defaultmetainit $@
podman=podman
nextcloud_image=nextcloud_local
# same name than image
container_name=$nextcloud_image
rel_bind_folder=bind_folder
bind_folder=$(pwd)/$rel_bind_folder
declare -a podman_args
podman_args+=(-p 127.0.0.1:8080:80 --name=$container_name)
# container 33 www-data => current user.
current_uid=$(id -u)
current_gid=$(id -g)
container_www_data_uid=33
container_www_data_gid=33
first_subuid=100000
first_subgid=100000
mapped_root_uid=$(( first_subuid + container_www_data_uid - 1 ))
range_1=$(( container_www_data_uid - 1 ))
# does not work idmap requires CAP_SYS_ADMIN permission not set for standard user
# www_data_idmap=",idmap=uids=0-${mapped_root_uid}-1#1-${first_subuid}-${range_1}#${container_www_data_uid}-${current_uid}-1#34-100033-2000;gids=0-${mapped_root_uid}-1#1-${first_subgid}-${range_1}#${container_www_data_gid}-${current_gid}-1#34-100033-2000"
# no theme yet
for dir in nextcloud custom_apps config data
do
folder=${bind_folder}/$dir
if [[ ! -f $folder ]]
then
mkdir -p $folder
fi
idmap=""
if [[ $dir == nextcloud ]]
then
target=/var/www/html
else
target=/var/www/html/$dir
if [[ $dir == custom_apps ]]
then
# current user will map to www-data for this binding
idmap="$www_data_idmap"
fi
fi
podman_args+=(--mount type=bind,source=${folder},target=${target}${idmap})
done
# with root ...
podman_args+=(--mount type=bind,source=$(pwd)/polls,target=/root/polls)
if [[ -n $detach ]]
then
podman_args+=(-d)
fi
echo "run podman with args ${podman_args[@]}"
$defer $podman run "${podman_args[@]}" $nextcloud_image

View File

@@ -0,0 +1,29 @@
#!/bin/bash
source lib/metascript.sh
log_info "assume postgres is already installed localy"
log_info "https://docs.nextcloud.com/server/latest/admin_manual/configuration_database/linux_database_configuration.html#requirements"
query_password "database password :" password
if [[ -z $password ]]
then
log_error "Missing password"
exit 1
fi
database_name=nextcloud_dev
username=nextcloud_dev
{
cat <<EOF
CREATE USER $username WITH PASSWORD '$password' CREATEDB;
CREATE DATABASE ${database_name} TEMPLATE template0 ENCODING 'UTF8';
ALTER DATABASE ${database_name} OWNER TO $username;
GRANT ALL PRIVILEGES ON DATABASE ${database_name} TO $username;
GRANT ALL PRIVILEGES ON SCHEMA public TO $username;
EOF
} | sudo -u postgres psql -f -

10
nextcloud_devenv/setuppodman.sh Executable file
View File

@@ -0,0 +1,10 @@
#!/bin/bash
gitclone=git@github.com:nextcloud/docker.git
if [[ ! -d podman ]]
then
git clone $gitclone podman
fi
echo "Not completed see REAMDE.md hack"

6
nextcloud_devenv/sync_polls.sh Executable file
View File

@@ -0,0 +1,6 @@
#!/bin/bash
# assuming polls is bind mounted in container as /root/polls
# see runpodman.sh
podman exec -it nextcloud_local rsync --chown www-data:www-data -av /root/polls/ /var/www/html/custom_apps/polls --exclude .git