88 lines
2.4 KiB
Bash
Executable File
88 lines
2.4 KiB
Bash
Executable File
#!/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
|
|
|
|
#lazzy detection base on first local ip
|
|
declare -a possible_hosts=($(ip a | grep 192.168.1 |awk '{ gsub("/24","",$2); print $2 ; }'))
|
|
hosts_n=${#possible_hosts[@]}
|
|
if (( hosts_n > 1 ))
|
|
then
|
|
log_warn "multiple hosts $hosts_n"
|
|
fi
|
|
listen_host=${possible_hosts[0]}
|
|
log_info "liston on $listen_host"
|
|
|
|
declare -a podman_args
|
|
|
|
host_free_port=8081
|
|
log_warn "[TODO] detect free port on $listen_host, use $host_free_port"
|
|
|
|
podman_args+=(-p $listen_host:$host_free_port:80 --name=$container_name --replace)
|
|
|
|
# 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
|
|
|
|
log_info 'Adjusting trusted_domains in ${bind_folder}/config/config.php'
|
|
# assumes a php is installed locally, could be changed to use a podman image or container
|
|
sudo cp ${bind_folder}/config/config.php .
|
|
php patch_config.php "$listen_host:$host_free_port" | sudo tee ${bind_folder}/config/config.php
|
|
|
|
log_info "run podman with args ${podman_args[@]}"
|
|
|
|
log_info "now you can start a browser on http://$listen_host:$host_free_port"
|
|
|
|
$defer $podman run "${podman_args[@]}" $nextcloud_image
|