#!/bin/bash source lib/metascript.sh enforcedir polls exists log_warn "No check is done to verify if container is already started" 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 # if wanting to expose nextcloud on host address detect_expose_address() { #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]} } # detect_expose_address listen_host=127.0.0.1 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) # network bridge slirp4netns (not pasta) and allow_host_loopback) # podman_args+=(--network=slirp4netns:allow_host_loopback=true) # pasta podman_args+=(--network=pasta:--map-host-loopback=10.1.1.13) 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 config_php=${bind_folder}/config/config.php if [[ -f $config_php ]] then sudo cp $config_php config.php sudo chown $(id -u):$(id -g) config.php php patch_config.php "$listen_host:$host_free_port" | sudo tee ${bind_folder}/config/config.php >/dev/null else log_info "no config/php, first install ?" fi 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