diff --git a/containers/caddy.inst b/containers/caddy.inst new file mode 100755 index 0000000..278e5ef --- /dev/null +++ b/containers/caddy.inst @@ -0,0 +1,22 @@ + +caddy_install () { + + local target + local dir="$(dirname $(realpath "${BASH_SOURCE:-$0}"))" + target=${1:-/opt/caddy} + [[ -d $target ]] || mkdir -p $target + echo installing caddy to $target + if /bin/cp -r -f $dir/caddy/* $target; then + pushd $target || return + echo CADDY_DIR=$target >> .env + source .env + cp conf/example.conf conf/$CONF + ./config + else + echo unable to copy caddy files to $target, install aborted + fi + popd || return +} + +# if script was executed then call the function +(return 0 2>/dev/null) || caddy_install $@ diff --git a/containers/caddy/.env b/containers/caddy/.env new file mode 100644 index 0000000..bfa3cd7 --- /dev/null +++ b/containers/caddy/.env @@ -0,0 +1,9 @@ +# copy to .env and edit to suit +COMPOSE_PROJECT_NAME=caddy +# default NAME is caddy +NAME=${COMPOSE_PROJECT_NAME} +IMAGE=ucommandit/caddy-r53 +CREDENTIALS=${DNS_CHALLENGE_CREDENTIALS:-$PWD/credentials.env} +# will use Caddyfile unless CONF is set +# this file should be in /conf on your host (e.g. my.conf) +CONF=$(hostnamectl hostname) diff --git a/containers/caddy/conf/example.conf b/containers/caddy/conf/example.conf new file mode 100644 index 0000000..90875c0 --- /dev/null +++ b/containers/caddy/conf/example.conf @@ -0,0 +1,23 @@ +#!/bin/bash + +# example using wildcart +*.domain.net *.subdomain.domain.net { + + tls domain.net@gmail.com { + dns route53 { + max_retries 10 + } + } + + # example simple files server + # @files host files.domain.net + # handle @files { + # root * + # file_server browse + # } + + @portainer host docker.domain.net + handle @portainer { + reverse_proxy subdomain.domain.net:9000 + } +} \ No newline at end of file diff --git a/containers/caddy/config b/containers/caddy/config new file mode 100755 index 0000000..4e03727 --- /dev/null +++ b/containers/caddy/config @@ -0,0 +1,2 @@ +#!/bin/bash +docker-compose config \ No newline at end of file diff --git a/containers/caddy/docker-compose.yaml b/containers/caddy/docker-compose.yaml new file mode 100644 index 0000000..1563794 --- /dev/null +++ b/containers/caddy/docker-compose.yaml @@ -0,0 +1,38 @@ +services: + caddy: + container_name: ${NAME:-caddy} + image: ${IMAGE:-caddy} + # if no $CONF is given then Caddyfile in ${PWD}/conf:/opt/caddy/conf will be used + command: caddy run ${CONF} + hostname: ${NAME:-caddy} + env_file: + - $CREDENTIALS + volumes: + - data:/opt/caddy/data + - settings:/opt/caddy/settings + - conf:/opt/caddy/conf + # - files:/opt/caddy/files + restart: unless-stopped + ports: + - 80:80 + - 443:443 +# port 2019 is for API, not required +# - 2019:2019 +# binding data and settings are not required +# But if there volumes are deleted caddy will need to redo all the certs +volumes: + data: + # driver_opts: + # type: none + # device: ${PWD}/data + # o: bind + settings: + # driver_opts: + # type: none + # device: ${PWD}/config + # o: bind + conf: + driver_opts: + type: none + device: ${PWD}/conf + o: bind diff --git a/containers/caddy/logs b/containers/caddy/logs new file mode 100755 index 0000000..133af74 --- /dev/null +++ b/containers/caddy/logs @@ -0,0 +1,3 @@ +[[ $1 ]] && opt="-n $1" +[[ $1 == "f" ]] && opt="-f" +docker-compose logs $opt \ No newline at end of file diff --git a/containers/caddy/readme.md b/containers/caddy/readme.md new file mode 100644 index 0000000..b94e825 --- /dev/null +++ b/containers/caddy/readme.md @@ -0,0 +1,9 @@ +# UCI Caddy Container + +use caddy.inst to install on your host + +by default install script will create file .conf in /opt/caddy/conf + +/opt/caddy/conf by default will be mounted in container + +now create your (route53) dns challenge credentails file, by defualt with be /opt/caddy/credentials.env \ No newline at end of file diff --git a/containers/caddy/restart b/containers/caddy/restart new file mode 100755 index 0000000..c73f489 --- /dev/null +++ b/containers/caddy/restart @@ -0,0 +1,3 @@ +#!/bin/bash +./stop +./start diff --git a/containers/caddy/run b/containers/caddy/run new file mode 100755 index 0000000..83ed0d0 --- /dev/null +++ b/containers/caddy/run @@ -0,0 +1 @@ +docker-compose up diff --git a/containers/caddy/scrub b/containers/caddy/scrub new file mode 100755 index 0000000..9e84b2c --- /dev/null +++ b/containers/caddy/scrub @@ -0,0 +1 @@ +docker-compose down -v diff --git a/containers/caddy/start b/containers/caddy/start new file mode 100755 index 0000000..9cd5f1c --- /dev/null +++ b/containers/caddy/start @@ -0,0 +1,5 @@ +echo upping the max size of the host buffer +echo net.core.rmem_max=2500000 | sudo tee -a /etc/sysctl.conf +# confirm +sudo sysctl -p | grep rmem_max +docker-compose up -d diff --git a/containers/caddy/stop b/containers/caddy/stop new file mode 100755 index 0000000..685cc77 --- /dev/null +++ b/containers/caddy/stop @@ -0,0 +1 @@ +docker-compose down diff --git a/containers/caddy/term b/containers/caddy/term new file mode 100755 index 0000000..08282d3 --- /dev/null +++ b/containers/caddy/term @@ -0,0 +1,3 @@ +#!/bin/bash +source .env +docker exec -it ${NAME:-caddy} bash -l \ No newline at end of file diff --git a/containers/caddy/upgrade b/containers/caddy/upgrade new file mode 100755 index 0000000..34323fd --- /dev/null +++ b/containers/caddy/upgrade @@ -0,0 +1,4 @@ +#!/bin/bash +./stop +docker-compose pull +./start diff --git a/modules/copyrootfs.func b/modules/copyrootfs.func deleted file mode 100644 index 8e2ee45..0000000 --- a/modules/copyrootfs.func +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -module_load filesystem -module_load confirm - -copy_rootfs () { -local dr="" -# local de=--delete-excluded -[[ ! $(mounted $1) ]] && echo $1 is not a mountpoint exiting && return 2 -cmd=$(echo sudo rsync $dr $de --progress -aAXv --exclude={\ -"/dev/*",\ -"/proc/*",\ -"/sys/*",\ -"tmp/*",\ -"/run/*",\ -"/mnt/*",\ -"/media/*",\ -"/lost+found",\ -"/data/*",\ -"/backup/*",\ -"/snapshots/*",\ -"/remotes/*",\ -"*[Cc]ache*",\ -"*/[Ll]og/*",\ -"*/[Ll]ogs/*",\ -"*.[Ll]og",\ -"/etc/fstab*",\ -"/boot/refind_linux.conf"\ -}\ - / $1 - ) -echo $cmd -if confirm run this copy command; then -$cmd -fi - -} \ No newline at end of file diff --git a/osxfer/osxfer b/osxfer/osxfer new file mode 100644 index 0000000..05b260e --- /dev/null +++ b/osxfer/osxfer @@ -0,0 +1,108 @@ +#!/bin/bash + +scripts_dir="$(dirname $(realpath "${BASH_SOURCE:-$0}"))" + +clone_snaps () { + local snap; local bsnap + if ! sudo mkdir -p $TDIR/$TNAME &>/dev/null; then + echo ERROR unable to make directory $TDIR/$TNAME + return 1 + fi + echo cloning transfered read only snapshots at $TSNAPS + ls -la $TSNAPS + echo to $TDIR/$TNAME + echo "################" + echo cdir: $CDIR, tname: $TNAME + latest=$(sudo btrbk -c "$CDIR/$TNAME.conf" list --format col:h:target_subvolume | xargs -I % sh -c 'basename %' | sed '$!N; /^\(.*\)\n\1$/!P; D') + echo $latest + if [[ $latest ]]; then + for snap in $latest; do + # dests+=" $(btrbk -c $file list target --format col:h:target_path)" + bsnap=$(basename "${snap%.*}") + echo cloning $TSNAPS/$snap to $TDIR/$TNAME/$bsnap + if [[ -d $TDIR/$TNAME/$bsnap ]]; then + echo snapshot $TDIR/$TNAME/$bsnap already exists you must manually remove it if you want to overwrite + echo "'sudo btrfs sub del $TDIR/$TNAME/$bsnap' or 'sudo btrfs sub del $TDIR/$TNAME/*'" + else + sudo btrfs sub snap $TSNAPS/$snap $TDIR/$TNAME/$bsnap + echo $TDIR/$TNAME/$bsnap + ls -la $TDIR/$TNAME/$bsnap + fi + done + echo $TDIR/$TNAME + ls -la $TDIR/$TNAME + else + echo no transfered snapshots, nothing to clone + fi +} + +osxfer () { + + local TDIR; local TSNAPS; local SDIR; local CDIR + + efile=$1.env + if [[ -f $efile ]]; then + module_load confirm + echo "#### sourcing $efile ########" + source $efile + TDIR=${TDIR:-/snapshots/transfer/target} + TSNAPS=${TDIR:-/snapshots/transfer/target}/${TSNAPS:-tmp/tsnaps} + SDIR=${SDIR:-/snapshots/transfer/source} + CDIR=${CDIR:-/snapshots/conf} + echo tsnaps: $TSNAPS + # TODO make sure minimal environment is set + source <( + source $efile + bash $(module_find btpl) $scripts_dir/os.conf.tmpl + ) >$CDIR/$TNAME.conf + # echo "######### btrbk file: $TNAME.conf ##############" + echo "$CDIR/$TNAME.conf" + # echo "#######################" + # if ! confirm "conf file is ok?"; then exit; fi + module_load btrbk btrfs + mkdir -p $TDIR &>/dev/null + mkdir -p $SDIR &>/dev/null + # echo $SDIR + # ls -la /snapshots/transfer + [[ $TLABEL ]] && sudo mount -L $TLABEL $TDIR + [[ $TUUID ]] && sudo mount --UUID=$TUUID $TDIR + [[ $TDEV ]] && sudo mount /dev/$TDEV $TDIR + if mountpoint $TDIR &>/dev/null; then + sudo mkdir -p $TSNAPS + echo able to mount $TLABEL $TUUID $TDEV at $TDIR... continuing transfer + if ls $TSNAPS/@root.* &>/dev/null; then + echo exists + if ! confirm a set of transfer snapshots exist at destination, resend?; then + clone_snaps + return + fi + fi + if btrbk_run $2 "$CDIR/$TNAME.conf"; then + echo successful transfer from $SMP/$SNAME to $TLABEL $TUUID $TDEV - $TSNAPS + sudo btrbk -c "$CDIR/$TNAME.conf" list latest + echo "########################" + clone_snaps + else + echo ERROR: snapshot transfer to $TLABEL $TUUID $TDEV - $TSNAPS failed + fi + echo deleting temporary transfer snapshots at $SDIR + sudo btrfs sub del $SDIR/* + sudo rm -rf $SDIR + # echo deleting temporary transfer snapshots at $TSNAPS + # sudo btrfs sub del $TSNAPS/* + # sudo rm -rf $TSNAPS + echo unmounting $TDIR + if sudo umount -R $TDIR; then + if ! confirm "remove local mount directory $TDIR?"; then exit; fi + sudo rm -f $TDIR + else + echo WARNING: not able to unmount $TDIR + fi + else + echo unable to mount $TLABEL $TUUID $TDEV at $TDIR + fi + else + echo environment file $efile does not exisit + fi + +}