Compare commits
1 Commits
6095bd26ce
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5921d27f1e |
@@ -1,6 +1,6 @@
|
|||||||
# Nextcloud Dev En
|
# Nextcloud Dev Environment for Poll
|
||||||
|
|
||||||
two options
|
Two options
|
||||||
|
|
||||||
one created manualy with a simple podman and a local database
|
one created manualy with a simple podman and a local database
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ puis
|
|||||||
./sync_poll.sh
|
./sync_poll.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
il reste encore a compiler avec les dependances composer et le build npm vuejs
|
il reste encore a compiler avec les dépendances composer et le build npm vuejs
|
||||||
|
|
||||||
```
|
```
|
||||||
./enter_www_data.sh
|
./enter_www_data.sh
|
||||||
@@ -72,7 +72,7 @@ utiliser la base de donnee postgres et non le SQLLite ?
|
|||||||
./migrate_db_sqlite2postgres.sh
|
./migrate_db_sqlite2postgres.sh
|
||||||
|
|
||||||
|
|
||||||
# NEW PLAIN nextcloud dev
|
# Option 2 : nextcloud-docker-dev
|
||||||
|
|
||||||
setup
|
setup
|
||||||
|
|
||||||
|
|||||||
@@ -5,25 +5,44 @@
|
|||||||
# [[ -f $log_functions ]] || { echo "[FATAL] Missing $log_functions" >&2 ; exit 1 ;}
|
# [[ -f $log_functions ]] || { echo "[FATAL] Missing $log_functions" >&2 ; exit 1 ;}
|
||||||
# source $log_functions
|
# source $log_functions
|
||||||
|
|
||||||
|
metalog_color_start() {
|
||||||
|
if [[ -n $metalog_color ]]
|
||||||
|
then
|
||||||
|
echo -en "${metalog_color}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
metalog_color_stop() {
|
||||||
|
if [[ -n $metalog_color ]]
|
||||||
|
then
|
||||||
|
echo -en "\033[0m"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
log_any()
|
log_any()
|
||||||
{
|
{
|
||||||
priority=$1
|
priority=$1
|
||||||
shift
|
shift
|
||||||
|
metalog_color_start
|
||||||
echo "[$priority] $@" >&2
|
echo "[$priority] $@" >&2
|
||||||
|
metalog_color_stop
|
||||||
}
|
}
|
||||||
|
|
||||||
log_fatal()
|
log_fatal()
|
||||||
{
|
{
|
||||||
|
local metalog_color=$metalog_color_error
|
||||||
log_any FATAL "$*"
|
log_any FATAL "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
log_error()
|
log_error()
|
||||||
{
|
{
|
||||||
|
local metalog_color=$metalog_color_error
|
||||||
log_any ERROR "$*"
|
log_any ERROR "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
log_warn()
|
log_warn()
|
||||||
{
|
{
|
||||||
|
local metalog_color=$metalog_color_warning
|
||||||
log_any WARN "$*"
|
log_any WARN "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,59 +51,36 @@ log_info()
|
|||||||
log_any INFO "$*"
|
log_any INFO "$*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_success()
|
||||||
|
{
|
||||||
|
local metalog_color=$metalog_color_success
|
||||||
|
log_info "$*"
|
||||||
|
}
|
||||||
|
|
||||||
log_debug()
|
log_debug()
|
||||||
{
|
{
|
||||||
|
local metalog_color=$metalog_color_info
|
||||||
[[ -n $debug ]] && log_any 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()
|
verbose()
|
||||||
{
|
{
|
||||||
[[ -n $verbose ]] && log_any $verbose $@
|
[[ -n $verbose ]] && log_any $verbose $@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
metalog_no_colors()
|
||||||
|
{
|
||||||
|
metalog_color_info=
|
||||||
|
metalog_color_success=
|
||||||
|
metalog_color_error=
|
||||||
|
metalog_color_warning=
|
||||||
|
}
|
||||||
|
|
||||||
|
# default colors
|
||||||
|
metalog_default_colors()
|
||||||
|
{
|
||||||
|
metalog_color_info="\033[38;5;79m"
|
||||||
|
metalog_color_success="\033[1;32m"
|
||||||
|
metalog_color_error="\033[1;31m"
|
||||||
|
metalog_color_warning="\033[1;34m"
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,49 +9,60 @@
|
|||||||
# ex:
|
# ex:
|
||||||
# bash lib/metascript.sh header
|
# bash lib/metascript.sh header
|
||||||
|
|
||||||
|
metascript_version=v1.1.0
|
||||||
|
|
||||||
# if called directly
|
# if called directly
|
||||||
if [[ "$0" =~ ^(.*)/metascript.sh$ ]]
|
if [[ "$0" =~ ^(.*)/metascript.sh$ ]]
|
||||||
then
|
then
|
||||||
prefix=${BASH_REMATCH[1]}
|
prefix=${BASH_REMATCH[1]}
|
||||||
if [[ $1 == header ]]
|
case $1 in
|
||||||
then
|
header)
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# SPDX-FileCopyrightText: 2025 artlog@l0g.eu
|
# SPDX-FileCopyrightText: 2025 artlog@l0g.eu
|
||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
#
|
# header generated by $0 $1
|
||||||
# sample to include this script.
|
# metascript_version=$metascript_version
|
||||||
|
|
||||||
toolsdir=$prefix
|
toolsdir=$prefix
|
||||||
pushd \$toolsdir >/dev/null
|
pushd \$toolsdir >/dev/null
|
||||||
toolsdir=\$(pwd)
|
toolsdir=\$(pwd)
|
||||||
source metascript.sh
|
source metascript.sh
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
|
|
||||||
|
metarun=metarun
|
||||||
|
# change default to sudo if needed
|
||||||
|
# metasudo=sudo
|
||||||
|
|
||||||
while [[ \$# > 0 ]]
|
while [[ \$# > 0 ]]
|
||||||
do
|
do
|
||||||
case "\$1" in
|
case "\$1" in
|
||||||
*)
|
*)
|
||||||
parsemetaarg "\$1"
|
parsemetaarg "\$1"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 0
|
usage
|
||||||
EOF
|
EOF
|
||||||
else
|
;;
|
||||||
echo "[WARNING] only header argument is supported. (prefix=$prefix)" >&2
|
version)
|
||||||
fi
|
echo $metascript_version
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "[WARNING] only header and version arguments are supported. (prefix=$prefix), this script is intended to be included not to be directly called." >&2
|
||||||
|
exit 1
|
||||||
|
esac
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$metascript_included" == "yes" ]]
|
if [[ "$metascript_included" == "yes" ]]
|
||||||
then
|
then
|
||||||
log_warn "metascript already included ($0)"
|
echo "[WARNING] metascript already included ($0)" >&2
|
||||||
else
|
else
|
||||||
|
|
||||||
metascript_included=yes
|
metascript_included=yes
|
||||||
|
|
||||||
|
|
||||||
# at this step $(pwd) should be this of metascript.sh
|
# at this step $(pwd) should be this of metascript.sh
|
||||||
# while $0 is this of caller script using metascript
|
# while $0 is this of caller script using metascript
|
||||||
@@ -75,7 +86,7 @@ metascript_usage()
|
|||||||
cat <<EOF >&2
|
cat <<EOF >&2
|
||||||
metascript commands :
|
metascript commands :
|
||||||
|
|
||||||
help|usage help or usage of this {$0} tool
|
help|usage help or usage of this {$0} tool. stop after usage display.
|
||||||
dryrun|show|showdoc display what should/will be done
|
dryrun|show|showdoc display what should/will be done
|
||||||
|
|
||||||
defersource= script file defining defer() non standard function
|
defersource= script file defining defer() non standard function
|
||||||
@@ -84,12 +95,17 @@ toolsresourcesdir= where to pick resource
|
|||||||
default to parent of script $toolsresourcesdir
|
default to parent of script $toolsresourcesdir
|
||||||
mostly used with dryrun
|
mostly used with dryrun
|
||||||
apply default : will actual do work without defer
|
apply default : will actual do work without defer
|
||||||
|
text_format=md set text format output to markdown
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
md_output_init() {
|
||||||
|
md_quote='```'
|
||||||
|
}
|
||||||
|
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
echo "[WARNING} no specific usage function for {$0}, to improve by developer" >&2
|
log_warn "no specific usage function for {$0}, to improve by developer"
|
||||||
echo >&2
|
echo >&2
|
||||||
metascript_usage
|
metascript_usage
|
||||||
}
|
}
|
||||||
@@ -102,6 +118,68 @@ showinfo()
|
|||||||
metarun()
|
metarun()
|
||||||
{
|
{
|
||||||
$defer $metasudo "$@"
|
$defer $metasudo "$@"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
metasudo_auto()
|
||||||
|
{
|
||||||
|
if [[ $EUID -eq 0 ]]
|
||||||
|
then
|
||||||
|
log_info "already effective user id as root, don't require sudo"
|
||||||
|
else
|
||||||
|
metasudo=sudo
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
autoquoteargs()
|
||||||
|
{
|
||||||
|
echo -n "$1"
|
||||||
|
shift
|
||||||
|
while [[ $# > 0 ]]
|
||||||
|
do
|
||||||
|
if [[ "$1" =~ [\ \$] ]]
|
||||||
|
then
|
||||||
|
echo -n " '$1'"
|
||||||
|
else
|
||||||
|
echo -n " $1"
|
||||||
|
fi
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
echoarray()
|
||||||
|
{
|
||||||
|
declare -a arr=("${@}")
|
||||||
|
declare -i len=${#arr[@]}
|
||||||
|
# Show passed array
|
||||||
|
for ((n = 0; n < len; n++))
|
||||||
|
do
|
||||||
|
echo -en " \"${arr[$n]}\""
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
start_quote() {
|
||||||
|
[[ -n $md_quote ]] && echo "$md_quote"
|
||||||
|
}
|
||||||
|
|
||||||
|
end_quote() {
|
||||||
|
[[ -n $md_quote ]] && echo "$md_quote"
|
||||||
|
}
|
||||||
|
|
||||||
|
deferpipe()
|
||||||
|
{
|
||||||
|
cat
|
||||||
|
echo "# <previous line> | $@"
|
||||||
|
}
|
||||||
|
|
||||||
|
include_source()
|
||||||
|
{
|
||||||
|
local script="$1"
|
||||||
|
|
||||||
|
enforce var script
|
||||||
|
|
||||||
|
source "$script"
|
||||||
}
|
}
|
||||||
|
|
||||||
showdoc()
|
showdoc()
|
||||||
@@ -111,10 +189,10 @@ showdoc()
|
|||||||
# assumes it handles ENV_METASCRIPT_DEFER
|
# assumes it handles ENV_METASCRIPT_DEFER
|
||||||
"$@"
|
"$@"
|
||||||
else
|
else
|
||||||
echo '```'
|
start_quote
|
||||||
autoquoteargs "$@"
|
autoquoteargs "$@"
|
||||||
echo
|
echo
|
||||||
echo '```'
|
end_quote
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,70 +202,147 @@ redirectto()
|
|||||||
if [[ -n $defer ]]
|
if [[ -n $defer ]]
|
||||||
then
|
then
|
||||||
echo "Copy to $tofile"
|
echo "Copy to $tofile"
|
||||||
echo '```'
|
start_quote
|
||||||
cat
|
cat
|
||||||
echo '```'
|
end_quote
|
||||||
else
|
else
|
||||||
cat > $tofile
|
cat > $tofile
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
execredirectfrom()
|
redirectappendto()
|
||||||
{
|
{
|
||||||
tofile=$1
|
tofile=$1
|
||||||
shift
|
|
||||||
if [[ -n $defer ]]
|
if [[ -n $defer ]]
|
||||||
then
|
then
|
||||||
echo '```'
|
echo "Append to $tofile"
|
||||||
autoquoteargs "$@"
|
start_quote
|
||||||
echo ' < '"$tofile"
|
cat
|
||||||
echo '```'
|
end_quote
|
||||||
else
|
else
|
||||||
"$@" < $tofile
|
cat >> $tofile
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
execredirectfrom()
|
||||||
|
{
|
||||||
|
fromfile="$1"
|
||||||
|
shift
|
||||||
|
enforcefile "$fromfile" exists
|
||||||
|
if [[ -n $defer ]]
|
||||||
|
then
|
||||||
|
start_quote
|
||||||
|
autoquoteargs "$@"
|
||||||
|
echo ' < '"$fromfile"
|
||||||
|
end_quote
|
||||||
|
else
|
||||||
|
"$@" < $fromfile
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
execredirectto()
|
execredirectto()
|
||||||
{
|
{
|
||||||
tofile=$1
|
tofile="$1"
|
||||||
shift
|
shift
|
||||||
if [[ -n $defer ]]
|
if [[ -n $defer ]]
|
||||||
then
|
then
|
||||||
echo '```'
|
start_quote
|
||||||
autoquoteargs "$@"
|
autoquoteargs "$@"
|
||||||
echo ' > '"$tofile"
|
echo ' > '"$tofile"
|
||||||
echo '```'
|
end_quote
|
||||||
else
|
else
|
||||||
$@ > $tofile
|
"$@" > $tofile
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
defer_exec_set_var()
|
||||||
|
{
|
||||||
|
tovar="$1"
|
||||||
|
shift
|
||||||
|
cat <<EOF
|
||||||
|
$md_quote
|
||||||
|
$tovar=\$($(autoquoteargs "$@"))
|
||||||
|
$md_quote
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
execredirecttoroot()
|
execredirecttoroot()
|
||||||
{
|
{
|
||||||
tofile=$1
|
tofile="$1"
|
||||||
shift
|
shift
|
||||||
if [[ -n $defer ]]
|
if [[ -n $defer ]]
|
||||||
then
|
then
|
||||||
echo '```'
|
start_quote
|
||||||
autoquoteargs "$@"
|
autoquoteargs "$@"
|
||||||
echo ' | sudo tee '"$tofile"
|
echo ' | sudo tee '"$tofile"' >/dev/null'
|
||||||
echo '```'
|
end_quote
|
||||||
else
|
else
|
||||||
"$@" | sudo tee $tofile
|
"$@" | sudo tee $tofile >/dev/null
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
execredirectas_to()
|
||||||
|
{
|
||||||
|
while [[ $# > 0 ]]
|
||||||
|
do
|
||||||
|
case $1 in
|
||||||
|
user=*)
|
||||||
|
if [[ "$1" =~ ^user=([a-z]+[-_a-z0-9]*)$ ]]
|
||||||
|
then
|
||||||
|
asuser=${BASH_REMATCH[1]}
|
||||||
|
else
|
||||||
|
log_fatal "execredirecttouser missing user= in '$@'"
|
||||||
|
[[ -n $defer ]] || exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
chroot=*)
|
||||||
|
aschroot=${1/chroot=}
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
tofile=$1
|
||||||
|
shift
|
||||||
|
break
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
local command=()
|
||||||
|
if [[ -n $aschroot ]]
|
||||||
|
then
|
||||||
|
command=(sudo chroot)
|
||||||
|
if [[ -n $asuser ]]
|
||||||
|
then
|
||||||
|
# no group yet
|
||||||
|
command+=(--userspec=$asuser:$asuser)
|
||||||
|
fi
|
||||||
|
command+=($aschroot)
|
||||||
|
elif [[ -n $asuser ]]
|
||||||
|
then
|
||||||
|
command=(sudo -u $asuser)
|
||||||
|
fi
|
||||||
|
command+=(tee $tofile)
|
||||||
|
if [[ -n $defer ]]
|
||||||
|
then
|
||||||
|
start_quote
|
||||||
|
autoquoteargs "$@"
|
||||||
|
echo ' | '"${command[@]}"' >/dev/null'
|
||||||
|
end_quote
|
||||||
|
else
|
||||||
|
"$@" | "${command[@]}" >/dev/null
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
pipeto()
|
pipeto()
|
||||||
{
|
{
|
||||||
if [[ -n $defer ]]
|
if [[ -n $defer ]]
|
||||||
then
|
then
|
||||||
echo '```'
|
echo "$md_quote"
|
||||||
echo -n 'cat << EOF| '
|
echo -n 'cat << EOF| '
|
||||||
autoquoteargs "$@"
|
autoquoteargs "$@"
|
||||||
echo
|
echo
|
||||||
cat
|
cat
|
||||||
echo "EOF"
|
echo "EOF"
|
||||||
echo '```'
|
echo "$md_quote"
|
||||||
else
|
else
|
||||||
cat | "$@"
|
cat | "$@"
|
||||||
fi
|
fi
|
||||||
@@ -279,129 +434,6 @@ check_missing_dest_dir()
|
|||||||
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()
|
parsemetaarg()
|
||||||
{
|
{
|
||||||
case $1 in
|
case $1 in
|
||||||
@@ -417,11 +449,15 @@ parsemetaarg()
|
|||||||
dryrun|show|showdoc)
|
dryrun|show|showdoc)
|
||||||
defer=showdoc
|
defer=showdoc
|
||||||
;;
|
;;
|
||||||
|
debug)
|
||||||
|
set -ex
|
||||||
|
;;
|
||||||
metasudo=*)
|
metasudo=*)
|
||||||
metasudo=${1/metasudo=}
|
metasudo=${1/metasudo=}
|
||||||
;;
|
;;
|
||||||
help|usage)
|
help|usage)
|
||||||
usage
|
usage
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
toolsresourcesdir=*)
|
toolsresourcesdir=*)
|
||||||
toolsresourcesdir=${1/toolsresourcesdir=/}
|
toolsresourcesdir=${1/toolsresourcesdir=/}
|
||||||
@@ -429,6 +465,9 @@ parsemetaarg()
|
|||||||
scl_enable=*)
|
scl_enable=*)
|
||||||
scl_args=(scl enable ${1/scl_enable=/} --)
|
scl_args=(scl enable ${1/scl_enable=/} --)
|
||||||
;;
|
;;
|
||||||
|
text_format=md)
|
||||||
|
md_output_init
|
||||||
|
;;
|
||||||
*)
|
*)
|
||||||
log_error "unrecognized argument '$1'"
|
log_error "unrecognized argument '$1'"
|
||||||
usage
|
usage
|
||||||
@@ -445,28 +484,82 @@ enforcearg()
|
|||||||
|
|
||||||
if [[ -z $value ]]
|
if [[ -z $value ]]
|
||||||
then
|
then
|
||||||
log_error "{0} expect '$var' to be set ex $var=$default"
|
log_error "{$0} expect '$var' to be set ex $var=$default"
|
||||||
usage
|
if [[ -n $defer ]]
|
||||||
exit 1
|
then
|
||||||
|
[[ -z $default ]] && default="DEFAULT"
|
||||||
|
log_warn "in defer/dryrun force $var=$default"
|
||||||
|
eval "$var=$default"
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enforce()
|
||||||
|
{
|
||||||
|
objecttype=$1
|
||||||
|
shift
|
||||||
|
case $objecttype in
|
||||||
|
file|dir)
|
||||||
|
object=$1
|
||||||
|
shift
|
||||||
|
constraint=$1
|
||||||
|
case $constraint in
|
||||||
|
exists|does_not_exist|create_if_needed|well_named)
|
||||||
|
enforce${objecttype} "$object" "$@"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
log_error "enforce $objecttype '$object' $@"
|
||||||
|
log_fatal "constraint '$constraint' unsupported. currently known (exists|does_not_exist|create_if_needed) Please fix the code."
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
var|arg)
|
||||||
|
enforcearg "$@"
|
||||||
|
;;
|
||||||
|
user)
|
||||||
|
enforceuser "$@"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
log_error "enforce $objecttype $@"
|
||||||
|
log_fatal "objectttype $objecttype unsupported"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
enforcefile()
|
enforcefile()
|
||||||
{
|
{
|
||||||
file="$1"
|
local file="$1"
|
||||||
constraint="$2"
|
local constraint="$2"
|
||||||
|
|
||||||
|
if [[ $constraint == well_named ]]
|
||||||
|
then
|
||||||
|
if [[ "$file" =~ /$ ]]
|
||||||
|
then
|
||||||
|
log_error "'$file' as a file should not end with a '/'"
|
||||||
|
[[ -n $defer ]] || exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ ! -f "$file" ]]
|
if [[ ! -f "$file" ]]
|
||||||
then
|
then
|
||||||
if [[ $constraint = exists ]]
|
case $constraint in
|
||||||
then
|
exists)
|
||||||
log_error "[ERROR] Missing expected $file"
|
log_error "Missing expected $file"
|
||||||
[[ -n $defer ]] || exit 1
|
[[ -n $defer ]] || exit 1
|
||||||
fi
|
;;
|
||||||
|
create_if_needed)
|
||||||
|
$metarun touch $file
|
||||||
|
;;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
if [[ $constraint = does_not_exists ]]
|
if [[ $constraint = does_not_exist ]]
|
||||||
then
|
then
|
||||||
log_error "[ERROR] '$file' already exists. Move it away"
|
log_error "'$file' already exists. Move it away"
|
||||||
[[ -n $defer ]] || exit 1
|
[[ -n $defer ]] || exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -474,33 +567,53 @@ enforcefile()
|
|||||||
|
|
||||||
enforcedir()
|
enforcedir()
|
||||||
{
|
{
|
||||||
dir="$1"
|
local dir="$1"
|
||||||
constraint="$2"
|
local constraint="$2"
|
||||||
|
|
||||||
if [[ $constraint = does_not_exist ]]
|
if [[ $constraint == well_named ]]
|
||||||
then
|
then
|
||||||
if [[ -e $dir ]]
|
if [[ ! "$dir" =~ /$ ]]
|
||||||
then
|
then
|
||||||
log_error "'$dir' already exists. Move it away"
|
log_error "'$dir' should end with a '/'"
|
||||||
[[ -n $defer ]] || exit 1
|
[[ -n $defer ]] || exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $constraint = exists ]]
|
if [[ -e $dir ]]
|
||||||
then
|
then
|
||||||
if [[ ! -d "$dir" ]]
|
case $constraint in
|
||||||
then
|
does_not_exist)
|
||||||
if [[ -e "$dir" ]]
|
if [[ -d "$dir" ]]
|
||||||
then
|
then
|
||||||
log_error "'$dir' already exists but is not a directory as expected"
|
log_error "'$dir' already exists"
|
||||||
[[ -n $defer ]] || exit 1
|
[[ -n $defer ]] || exit 1
|
||||||
fi
|
else
|
||||||
log_error "[ERROR] Missing expected directory '$dir'"
|
log_error "'$dir' already exists and is not a directory as expected"
|
||||||
[[ -n $defer ]] || exit 1
|
[[ -n $defer ]] || exit 1
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
create_if_needed|exists)
|
||||||
|
if [[ ! -d "$dir" ]]
|
||||||
|
then
|
||||||
|
log_error "'$dir' already exists and is not a directory as expected"
|
||||||
|
[[ -n $defer ]] || exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
case $constraint in
|
||||||
|
exists)
|
||||||
|
log_error "Missing expected directory $dir"
|
||||||
|
[[ -n $defer ]] || exit 1
|
||||||
|
;;
|
||||||
|
create_if_needed)
|
||||||
|
if [[ ! -d "$dir" ]]
|
||||||
|
then
|
||||||
|
$metarun mkdir -p "$dir"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
fi
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applymetaargs()
|
applymetaargs()
|
||||||
@@ -654,7 +767,7 @@ get_resource_var() {
|
|||||||
echo "# $varname=<MISSING>" >>$collect_context
|
echo "# $varname=<MISSING>" >>$collect_context
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
log_warn "($0) Using default value '$varname'='$default_value' HARDCODED in script : should be fixed with proper default file .resources.var, see traces in $collect_context"
|
log_warn "($0) Using default value '$varname'='$default_value' HARDCODED in script : should be fixed with proper default file resources.var, see traces in $collect_context"
|
||||||
read "$varname" <<<"$default_value"
|
read "$varname" <<<"$default_value"
|
||||||
echo "$varname=$default_value" >>$collect_context
|
echo "$varname=$default_value" >>$collect_context
|
||||||
fi
|
fi
|
||||||
@@ -664,29 +777,56 @@ setup_resources_var()
|
|||||||
{
|
{
|
||||||
local resource_var="$1"
|
local resource_var="$1"
|
||||||
enforcefile "$resource_var" exists
|
enforcefile "$resource_var" exists
|
||||||
while read line
|
if [[ -f $resource_var ]]
|
||||||
do
|
then
|
||||||
if [[ $line =~ ^([a-zA-Z0-9_]+)=(.+)$ ]]
|
while read line
|
||||||
then
|
do
|
||||||
varname=${BASH_REMATCH[1]}
|
if [[ $line =~ ^([a-zA-Z0-9_]+)=(.+)$ ]]
|
||||||
value=${BASH_REMATCH[2]}
|
then
|
||||||
read "$varname" <<<"$value"
|
varname=${BASH_REMATCH[1]}
|
||||||
elif [[ $line =~ ^# ]]
|
value=${BASH_REMATCH[2]}
|
||||||
then
|
read "$varname" <<<"$value"
|
||||||
echo "$line"
|
elif [[ $line =~ ^# ]]
|
||||||
else
|
then
|
||||||
log_warn "Invalid syntax in $resource_var '$line' does not match any expected expression"
|
if [[ -n $defer ]]
|
||||||
fi
|
then
|
||||||
done <"$resource_var"
|
$defer : "$line"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
log_warn "Invalid syntax in $resource_var '$line' does not match any expected expression"
|
||||||
|
fi
|
||||||
|
done <"$resource_var"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# allow to check mounted points
|
# allow to check mounted points
|
||||||
mountpoint_get_device()
|
mountpoint_get_device()
|
||||||
{
|
{
|
||||||
local mount_point="$1"
|
local mount_point="$1"
|
||||||
|
mount_point=$(readlink -f "$mount_point")
|
||||||
$defer awk "{ if (\$2 == \""$mount_point"\") print \$1 ;}" /proc/mounts
|
$defer awk "{ if (\$2 == \""$mount_point"\") print \$1 ;}" /proc/mounts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enforce_device() {
|
||||||
|
local device=$1
|
||||||
|
local constraint=$2
|
||||||
|
if [[ -n $defer ]]
|
||||||
|
then
|
||||||
|
$defer "mountpoint=$(device_get_mountpoints $device)"
|
||||||
|
else
|
||||||
|
mountpoint=$(device_get_mountpoints $device)
|
||||||
|
fi
|
||||||
|
if [[ -n $mountpoint ]] && [[ $constraint == "unmounted" ]]
|
||||||
|
then
|
||||||
|
log_error "$device seen as mounted on $mountpoint"
|
||||||
|
$defer exit 1
|
||||||
|
elif [[ -z $mountpoint ]] && [[ $constraint == "mounted" ]]
|
||||||
|
then
|
||||||
|
log_error "$device not seen as mounted"
|
||||||
|
$defer exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
device_get_mountpoints()
|
device_get_mountpoints()
|
||||||
{
|
{
|
||||||
local device="$1"
|
local device="$1"
|
||||||
@@ -695,10 +835,15 @@ device_get_mountpoints()
|
|||||||
|
|
||||||
mount_if_needed()
|
mount_if_needed()
|
||||||
{
|
{
|
||||||
local mountpoint="$1"
|
local mountdevice="$1"
|
||||||
local mountdevice="$2"
|
local mountpoint="$2"
|
||||||
local param="$3"
|
local param="$3"
|
||||||
device=$(mountpoint_get_device "$mountpoint")
|
if [[ -n $defer ]]
|
||||||
|
then
|
||||||
|
$defer 'device=$(mountpoint_get_device '"$mountpoint"')'
|
||||||
|
else
|
||||||
|
device=$(mountpoint_get_device "$mountpoint")
|
||||||
|
fi
|
||||||
|
|
||||||
enforcedir "$mountpoint" exists
|
enforcedir "$mountpoint" exists
|
||||||
# device is a device ...
|
# device is a device ...
|
||||||
@@ -706,28 +851,70 @@ mount_if_needed()
|
|||||||
|
|
||||||
if [[ -z $device ]]
|
if [[ -z $device ]]
|
||||||
then
|
then
|
||||||
$metarun mount $param "$mountdevice" "$device"
|
$metarun mount $param "$mountdevice" "$mountpoint"
|
||||||
elif [[ "$device" == "$mountdevice" ]]
|
elif [[ "$device" == "$mountdevice" ]]
|
||||||
then
|
then
|
||||||
log_info "$device already mounted on $mountdevice"
|
log_info "$device already mounted on $mountdevice"
|
||||||
else
|
else
|
||||||
log_warn "Another device $device is mounted on $mountdevice, not $mountdevice"
|
log_warn "Another device $device is mounted on $mountpoint, not $mountdevice"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
umount_if_needed()
|
umount_if_needed()
|
||||||
{
|
{
|
||||||
local mountpoint="$1"
|
local mountdevice="$1"
|
||||||
local mountdevice="$2"
|
local mountpoint="$2"
|
||||||
|
local param="$3"
|
||||||
device=$(mountpoint_get_device "$mountpoint")
|
device=$(mountpoint_get_device "$mountpoint")
|
||||||
if [[ -n "$device" ]]
|
if [[ -n "$device" ]]
|
||||||
then
|
then
|
||||||
if [[ "$device" == "$mountpoint" ]]
|
if [[ "$device" == "$mountdevice" ]]
|
||||||
then
|
then
|
||||||
$metarun umount "$mountpoint"
|
$metarun umount "$mountpoint"
|
||||||
else
|
else
|
||||||
log_warn "Another device $device is mounted on $mountdevice, not $mountdevice"
|
log_warn "Another device $device is mounted on $mountpoint, not $mountdevice"
|
||||||
|
if [[ $param == '--bind' ]]
|
||||||
|
then
|
||||||
|
log_warn "Unmouning ANYWAY ( mount --bind show root device, not mounted directory )"
|
||||||
|
$metarun umount "$mountpoint"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
log_warn "no device found mounted for umount_if_needed $@"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
exec_bg()
|
||||||
|
{
|
||||||
|
if [[ -z $defer ]]
|
||||||
|
then
|
||||||
|
"$@" &
|
||||||
|
else
|
||||||
|
$defer "$@" '&'
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
notice()
|
||||||
|
{
|
||||||
|
case "$1" in
|
||||||
|
git_commit)
|
||||||
|
log_warn "$1 should be $2"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
log_fatal "unrecognized notice '$1'"
|
||||||
|
exit 2
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
enforceuser()
|
||||||
|
{
|
||||||
|
local expecteduser="$1"
|
||||||
|
|
||||||
|
if [[ "$USER" != "$expecteduser" ]]
|
||||||
|
then
|
||||||
|
log_error "expected user $expecteduser is not current user $USER"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -739,9 +926,9 @@ if [[ -z $toolsresourcesdir ]]
|
|||||||
then
|
then
|
||||||
# project directory
|
# project directory
|
||||||
|
|
||||||
# from current $(pwd) will follow parent dir hierarchy to find .resources.var
|
# from current $(pwd) will follow parent dir hierarchy to find resources.var
|
||||||
dir="$(pwd)"
|
dir="$(pwd)"
|
||||||
while [[ -n $dir ]] && [[ -d $dir ]] && [[ ! -f $dir/.resources.var ]]
|
while [[ -n $dir ]] && [[ -d $dir ]] && [[ ! -f $dir/resources.var ]]
|
||||||
do
|
do
|
||||||
new_dir=$(dirname "$dir")
|
new_dir=$(dirname "$dir")
|
||||||
if [[ $new_dir == $dir ]]
|
if [[ $new_dir == $dir ]]
|
||||||
@@ -751,7 +938,7 @@ then
|
|||||||
fi
|
fi
|
||||||
dir="$new_dir"
|
dir="$new_dir"
|
||||||
done
|
done
|
||||||
if [[ -f $dir/.resources.var ]]
|
if [[ -f $dir/resources.var ]]
|
||||||
then
|
then
|
||||||
toolsresourcesdir=$dir
|
toolsresourcesdir=$dir
|
||||||
else
|
else
|
||||||
@@ -764,7 +951,7 @@ then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
resources_var=$toolsresourcesdir/.resources.var
|
resources_var=$toolsresourcesdir/resources.var
|
||||||
if [[ -f $resources_var ]]
|
if [[ -f $resources_var ]]
|
||||||
then
|
then
|
||||||
setup_resources_var "$resources_var"
|
setup_resources_var "$resources_var"
|
||||||
|
|||||||
7
nextcloud_devenv/runit.README.md
Normal file
7
nextcloud_devenv/runit.README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
|
||||||
|
See README.md Option 2
|
||||||
|
|
||||||
|
./runit.sh dryrun up
|
||||||
|
./runit.sh dryrun down
|
||||||
|
|
||||||
|
Please remove dryrun to actualy do it.
|
||||||
@@ -8,6 +8,10 @@ toolsdir=$(pwd)
|
|||||||
source metascript.sh
|
source metascript.sh
|
||||||
popd >/dev/null
|
popd >/dev/null
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
cat runit.README.md
|
||||||
|
}
|
||||||
|
|
||||||
while [[ $# > 0 ]]
|
while [[ $# > 0 ]]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@@ -21,6 +25,13 @@ do
|
|||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
|
if [[ -z $action ]]
|
||||||
|
then
|
||||||
|
log_warn "Missing arguments"
|
||||||
|
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
metarun=metarun
|
metarun=metarun
|
||||||
metasudo=sudo
|
metasudo=sudo
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user