diff --git a/bin/amd64/caddy b/bin/amd64/caddy deleted file mode 100755 index 6ae8017..0000000 Binary files a/bin/amd64/caddy and /dev/null differ diff --git a/bin/arm64/caddy b/bin/arm64/caddy deleted file mode 100755 index 546d9b5..0000000 Binary files a/bin/arm64/caddy and /dev/null differ diff --git a/bin/install b/bin/install new file mode 100755 index 0000000..74b760a --- /dev/null +++ b/bin/install @@ -0,0 +1,185 @@ +#!/bin/bash +# dependencies, jq +# if you have run into github api anonymous access limits which happens during debugging/dev then add user and token here or sourced from a separate file +# . ~/githubapitoken +#GITHUB_USER="" +#GITHUB_TOKEN="" + +function showver { +if [ -f "$1" ]; then + CUR_VER=$("$1" version) + if [ "$CUR_VER" ]; then + echo Installed Version for $1 is $CUR_VER + else + echo WARNING unable to determine version for $1. Maybe wrong os/arch binary was installed + fi +else + echo No executable file at $1, unable to check version +fi +} + +REPO=caddyserver/caddy + +if [ "$GITHUB_TOKEN" != "" ]; then +echo using access token with script +echo $GITHUB_USER $GITHUB_TOKEN +fi + +LOCAL=false +SAVE=false +FORCE=false + +while getopts 'fslb:a:o:' OPTION; do + case "$OPTION" in + f) + FORCE=true + ;; + s) + SAVE=true + ;; + l) + LOCAL=true + ;; + o) + OS=$OPTARG + echo setting os to $OS + ;; + b) + BIN_NAME=$OPTARG + echo using binary name $BIN_NAME + ;; + a) + ARCH=$OPTARG + echo setting architecture to $ARCH + ;; + esac +done + +shift $(( OPTIND - 1 )) + +if [ ! $OS ]; then + echo determining operating system + case "$OSTYPE" in + darwin*) OS=mac ;; + linux*) OS=linux ;; + bsd*) OS=freebsd ;; + msys*) OS=windows ;; + *) + echo "no release for : $OSTYPE" + exit 0 + ;; + esac +fi + +if [ ! $OS ]; then + echo No Operating System Specified, $OS + exit 0 +fi + + +if [ ! $ARCH ]; then + echo determining system architecture +declare -A ARCHES +ARCHES=( ["arm64"]="arm64" ["aarch64"]="arm64" ["x86_64"]="amd64" ["armv61"]="armv6" ["armv71"]="armv7" ["arm32"]="armv7" ["armhf"]="armv7" ) +ARCH=${ARCHES[$(uname -m)]} + if [ ! $ARCH ]; then + echo Your machine kernel architecture $(uname -m) has no caddy release + echo see https://github.com/caddyserver/caddy/releases + exit 1 + fi +fi + +ARCHIVE=tar.gz +[ "$OS" == "windows" ] && ARCHIVE=zip + +echo Operating System $OS +echo Architecture $ARCH +echo Archive Type $ARCHIVE + +BIN_DIR="$(dirname "$(readlink -f "$0")")" +BIN_NAME=${BIN_NAME:-caddy} +[ "$OS" == windows ] && BIN_NAME=$BIN_NAME.exe +BIN_PATH="$BIN_DIR/$BIN_NAME" + +if [ $LOCAL == true ]; then + echo "Using Local Binary <$BIN_DIR/$OS-$ARCH> if Available" + if [ -f "$BIN_DIR/$OS-$ARCH" ]; then + \cp -f "$BIN_DIR/$OS-$ARCH" "$BIN_PATH" + echo copying $BIN_DIR/$OS-$ARCH to $BIN_PATH + showver $BIN_PATH + exit 0 + else + echo $BIN_DIR/$OS-$ARCH not available caddy binary not set + exit 0 + fi +fi + +RECORD=$(curl -u $GITHUB_USER:$GITHUB_TOKEN -s https://api.github.com/repos/$REPO/releases/latest) +NEW_VER=$(echo $RECORD | jq -r '.tag_name') +[ "$NEW_VER" ] && echo $NEW_VER is latest version available from https://github.com/caddyserver/caddy/releases +if [ -f "$BIN_PATH" ] && [ "$SAVE" == false ]; then +echo checking current installed version +VER=$("$BIN_PATH" version) + if [ "$VER" ] && [ "$NEW_VER" ]; then + if [[ "$VER" == *"$NEW_VER"* ]]; then + echo $BIN_PATH is current, "$NEW_VER" + if [ "$FORCE" == true ]; then + echo "forcing download/overwrite" + else + exit 0 + fi + else + echo updating $VER to $NEW_VER + fi + else + echo unable to determine version for "$BIN_PATH" overwriting with $NEW_VER, $OS $ARCH + fi +else + echo "$BIN_PATH" does not exist, installing $NEW_VER +fi + +URL=$(echo $RECORD | \ + jq -r \ + --arg os $OS \ + --arg arch $ARCH \ + --arg archive $ARCHIVE \ + '.assets[] | select( .name | contains($os)) | + select (.name | contains($arch)) | + select (.name | contains($archive)) | + .browser_download_url' \ + ) + +if [ $URL ]; then + +echo "Downloading Archive $URL" + +wget --user=-u $GITHUB_USER --password=$GITHUB_TOKEN -q $URL + +ARC=$(basename $URL) +echo Extracting Caddy from Archive, $ARC +if [ $OS == windows ]; then + unzip $BIN_DIR/$ARC caddy.exe + if [ "$SAVE" == true ]; then + mv caddy.exe -f "$BIN_DIR/$OS-$ARCH" + fi +else + tar -xzf $BIN_DIR/$ARC caddy + chmod +x caddy + if [ "$SAVE" == true ]; then + mv caddy -f "$BIN_DIR/$OS-$ARCH" + fi +fi + +rm $BIN_DIR/$ARC + + + +else + echo no such release for $OS $ARCH +fi + +if [ "$SAVE" == true ]; then +showver "$BIN_DIR/$OS-$ARCH" +else + showver "$BIN_PATH" +fi diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..cace5e8 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1 @@ +/pkg/ diff --git a/build/build b/build/build new file mode 100755 index 0000000..d74e030 --- /dev/null +++ b/build/build @@ -0,0 +1,29 @@ +#!/bin/bash +DIR="$(dirname "$(readlink -f "$0")")" +export GOPATH=$DIR +# set a specific release +# REL=v2.0.0 +PLUGINS='' +while IFS= read -r line; do + [ $line ] && echo Using Plugin: $line + PLUGINS=`[ $line ] && echo $PLUGINS' --with '$line` +done < $DIR/plugins.txt +# reading builds file +cat $DIR/builds.txt | while read GOOS GOARCH GOARM; +do +GOOS=${GOOS:-linux} +GOARCH=${GOARCH:-amd64} +BIN_NAME=$GOOS-$GOARCH`[ $GOARM ] && echo -$GOARM` +echo deleting any old executable $BIN_NAME +[ -f $DIR/bin/$BIN_NAME ] && rm $DIR/bin/$BIN_NAME +echo Building binary $BIN_NAME +export GOOS=$GOOS +export GOARCH=$GOARCH +[ $GOARM ] && export GOARM=$GOARM +env | grep GO +$DIR/bin/xcaddy build $REL \ + --output $DIR/bin/$BIN_NAME \ + $PLUGINS +echo ...done building +[ -f $DIR/BIN/$ARCH ] && $DIR/bin/$ARCH version +done diff --git a/build/builds.txt b/build/builds.txt new file mode 100644 index 0000000..0284076 --- /dev/null +++ b/build/builds.txt @@ -0,0 +1,3 @@ + +linux arm64 +linux arm 7 diff --git a/build/deploy b/build/deploy new file mode 100755 index 0000000..30ce1d7 --- /dev/null +++ b/build/deploy @@ -0,0 +1,5 @@ +#!/bin/bash +# NEEDS WORK! +DIR="$(dirname "$(readlink -f "$0")")" +ARCH=${1:-amd64} +\cp --verbose -rf $DIR/BIN/$ARCH /opt/caddy/bin/caddy diff --git a/build/plugins.txt b/build/plugins.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/build/plugins.txt @@ -0,0 +1 @@ + diff --git a/build/readme.md b/build/readme.md new file mode 100644 index 0000000..890a748 --- /dev/null +++ b/build/readme.md @@ -0,0 +1,27 @@ +# Build A Caddy Binary + +## Setup go and go get + + + +## Update xcaddy + +run `update-xcaddy` script + +xcaddy is used to build a caddy binary for a particular architecture and with particular plugins. + +Edit the build script add/remove plugins to be including with the build. + +those will be the `--with` lines +commented lines will ignore that plugin. All plugins will be collected from some url + +``` + --with github.com/iamd3vil/caddy_yaml_adapter \ + --with github.com/caddy-dns/route53 # for route53 dns chanlled +``` + +so simply `./build` will build the `amd64` version. +use `./build arm64` for arm64 build + +when sucessfully deploy the binary to the caddy deployment repo with `./deploy ` +then in the caddy deployment repo commit that change and push. Then pull on installations for which the new binary is desired. diff --git a/build/update-xcaddy b/build/update-xcaddy new file mode 100755 index 0000000..05a2b47 --- /dev/null +++ b/build/update-xcaddy @@ -0,0 +1,4 @@ +#!/bin/bash +DIR="$(dirname "$(readlink -f "$0")")" +export GOPATH=$DIR +go get -u github.com/caddyserver/xcaddy/cmd/xcaddy diff --git a/caddy-service.md b/systemd/caddy-service.md similarity index 100% rename from caddy-service.md rename to systemd/caddy-service.md