From 87d4316e62f554bdbe2eec8b309fcc4d459f9108 Mon Sep 17 00:00:00 2001 From: David Kebler Date: Tue, 27 Oct 2020 10:09:20 -0700 Subject: [PATCH] moved all scripts to scripts directory and refactored accordingly somewhat working example site with conf file --- build/.gitignore | 1 - build/build | 29 ----------------------- build/builds.txt | 2 -- build/deploy | 5 ---- build/plugins.txt | 2 +- build/update-xcaddy | 4 ---- env/AWS.secret | Bin 609 -> 0 bytes env/aws.sh.secret | Bin 628 -> 0 bytes example-web/css/default.css | 45 ++++++++++++++++++++++++++++++++++++ example-web/example.md | 13 +++++++++++ example-web/index.html | 13 ----------- example-web/index.md | 5 ++++ example-web/template.html | 15 ++++++++++++ scripts/build | 43 ++++++++++++++++++++++++++++++++++ scripts/install | 4 ++-- scripts/install-xcaddy | 5 ++++ scripts/mkuser | 12 ++++++---- scripts/newconf | 5 ++-- scripts/own | 8 ++++++- scripts/pre-commit | 5 ++++ scripts/run | 4 ++-- systemd/install | 0 systemd/log | 0 systemd/persist | 0 systemd/start | 0 systemd/stop | 0 26 files changed, 153 insertions(+), 67 deletions(-) delete mode 100644 build/.gitignore delete mode 100755 build/build delete mode 100755 build/deploy delete mode 100755 build/update-xcaddy delete mode 100644 env/AWS.secret delete mode 100644 env/aws.sh.secret create mode 100644 example-web/css/default.css create mode 100644 example-web/example.md delete mode 100644 example-web/index.html create mode 100644 example-web/index.md create mode 100644 example-web/template.html create mode 100755 scripts/build create mode 100755 scripts/install-xcaddy create mode 100644 scripts/pre-commit mode change 100755 => 100644 systemd/install mode change 100755 => 100644 systemd/log mode change 100755 => 100644 systemd/persist mode change 100755 => 100644 systemd/start mode change 100755 => 100644 systemd/stop diff --git a/build/.gitignore b/build/.gitignore deleted file mode 100644 index cace5e8..0000000 --- a/build/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/pkg/ diff --git a/build/build b/build/build deleted file mode 100755 index d74e030..0000000 --- a/build/build +++ /dev/null @@ -1,29 +0,0 @@ -#!/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 index 0284076..a6339a4 100644 --- a/build/builds.txt +++ b/build/builds.txt @@ -1,3 +1 @@ - linux arm64 -linux arm 7 diff --git a/build/deploy b/build/deploy deleted file mode 100755 index 30ce1d7..0000000 --- a/build/deploy +++ /dev/null @@ -1,5 +0,0 @@ -#!/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 index 8b13789..e70ff10 100644 --- a/build/plugins.txt +++ b/build/plugins.txt @@ -1 +1 @@ - +github.com/caddy-dns/route53 diff --git a/build/update-xcaddy b/build/update-xcaddy deleted file mode 100755 index 05a2b47..0000000 --- a/build/update-xcaddy +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -DIR="$(dirname "$(readlink -f "$0")")" -export GOPATH=$DIR -go get -u github.com/caddyserver/xcaddy/cmd/xcaddy diff --git a/env/AWS.secret b/env/AWS.secret deleted file mode 100644 index 40c1672409125448753d905bd739d03ba00512e4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 609 zcmV-n0-pVa0gMCgu7OP^x^5Ez3;rsEEnfii=I=UWLKOGE7;iaaXu6Eo0C&lX^}H{Z z()`~}x0j9?m)@eq0+$m&zkqD9vYp<`hY{%-@6X9g_C;ZFjjk`K(5Qi$IW7P522Z5f z?!v3w{VXFwHZ9`;NrRo;)tej!W;($pu<6aYHvsf4pO``u8K$xP zR_4*=Ws_7^cGT{-5Do_2YVTNgh^6e-@|;Pex*73Lsa15-GJa_{!hQ%NwGuDUR#T@f zF7LSo9fLYYhE>EFtr(3vCwdpf7b4^Br$Yy*K$_?5?7~KffG9q(1f3?r+}wfDSgDl6 zLMv(|HFQ>M4w3OreSO(=#4b^gzID#&@Xrj3Xc+H>jfHL)BSt!;{3;W^6&CRJ7jv~J zK$=iy87fBU-)=v03~XE7e~RV**DBful%v?+jjf*nP}w*U|0&)pm5|cF4*~0O6?etv z+?YtThaSZz{^no&|u^DA8^++=5VoYvnE}4 zJh)m5?8FeKj(hZQM+fmH^T6wIpI7fNx`BrQFouPKkl>w6*?x24sX|v4!o+sTJX@S}p*W^Z}Y+ zJngo1A+JK&=ZxMig10cmk{ji5QUh$>_MLHhEC#=MHzn~_^n|W6B4scW|JwBLocNBJ z`)sO^|CQmah$<1C?kfw~+^I1UF>W||*B1J^=}B8f09UuH%M0y&;dqcfOPIn|ag?%~ z;xmZh?^)sY{>d#^laQpFrNg+33;6E+kD8ag7jZLp;r>!c3m7XE+d2e2pM1hrkhVYQwfXJPPQ`_tTslJm zabqj$(1I|GLQzB|XSKG`5Mz*4dR*~@W~lIbG;)=j;zPGui7bzxo_m}-{b2>fgXmIK z!-BV3cAA&Ht!cca_YEb~6?}l72sR1H%5H&RKX9)w>w z!01`BSgWb}KydGGMDy?{0PhVBW6U>Yo@>L*r5bJBB}}$+N&yAdp>zkZ&UPi%gf`^> diff --git a/example-web/css/default.css b/example-web/css/default.css new file mode 100644 index 0000000..d628be7 --- /dev/null +++ b/example-web/css/default.css @@ -0,0 +1,45 @@ +body { + font-size: 10pt; + font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; + color: red; + background-color: blue; + line-height: 14pt; + display: block; +} + +main { + margin: 100px; + font-size: 2em; +} + + +h1 { + font: 30pt Verdana, Geneva, Arial, Helvetica, sans-serif; + font-weight: bold; + line-height: 20pt; +} + +p { + margin-bottom: 1em; + line-height: 1.2em; +} + +code { + padding: .3em; + background-color: yellow !important; + color: blue; +} + +a { + text-decoration: none; +} + + +a:link, a:visited { + color: #8094d6; +} + + +a:hover, a:active { + color: #FF9933; +} diff --git a/example-web/example.md b/example-web/example.md new file mode 100644 index 0000000..ba0e7b2 --- /dev/null +++ b/example-web/example.md @@ -0,0 +1,13 @@ +--- +title: Example +--- +# Example Rendered Markdown +This is an example markdown file rendered via a template by Caddy2 + +`some code` + + diff --git a/example-web/index.html b/example-web/index.html deleted file mode 100644 index 3cbdccc..0000000 --- a/example-web/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - -Test Web - - -
-

Test Web

-
- - diff --git a/example-web/index.md b/example-web/index.md new file mode 100644 index 0000000..3df60f4 --- /dev/null +++ b/example-web/index.md @@ -0,0 +1,5 @@ +--- +title: Index File +--- +# Default Index File +[See Example Markdown File](./example.md) diff --git a/example-web/template.html b/example-web/template.html new file mode 100644 index 0000000..685d932 --- /dev/null +++ b/example-web/template.html @@ -0,0 +1,15 @@ +{{$markdownFilePath := printf .OriginalReq.URL.Path}} +{{$markdownFile := (include $markdownFilePath | splitFrontMatter)}} +{{$meta := $markdownFile.Meta }} + + + + {{ $meta.title }} + + + +
+ {{markdown $markdownFile.Body }} +
+ + diff --git a/scripts/build b/scripts/build new file mode 100755 index 0000000..ce0e586 --- /dev/null +++ b/scripts/build @@ -0,0 +1,43 @@ +#!/bin/bash +DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit +BUILD_DIR=$DIR/build +export GOPATH=$BUILD_DIR +# set a specific release +REL=$1 +PLUGINS='' +while IFS= read -r line; do + [ $line ] && echo Using Plugin: $line + PLUGINS=`[ $line ] && echo $PLUGINS' --with '$line` +done < $BUILD_DIR/plugins.txt +# reading builds file +cat $BUILD_DIR/builds.txt | while read GOOS GOARCH GOARM; +do +GOOS=${GOOS:-linux} +GOARCH=${GOARCH:-amd64} +BIN_NAME=$GOOS-$GOARCH`[ $GOARM ] && echo -$GOARM` +BIN_PATH=$DIR/bin/$BIN_NAME +echo deleting any old executable $BIN_NAME +[ -f $BIN_PATH ] && rm $BIN_PATH +echo Building binary $BIN_PATH +export GOOS=$GOOS +export GOARCH=$GOARCH +export CGO_ENABLED=1 +[ $GOARM ] && export GOARM=$GOARM +echo GO environment before running xcaddy +go env +echo building with +CMD=" + ${BUILD_DIR}/bin/xcaddy + build + ${REL} + --output ${BIN_PATH} + ${PLUGINS} + " +echo ${CMD} +echo "$(eval ${CMD})" +echo ...done building +if [ -f $BIN_PATH ]; then +echo build successful at $BIN_PATH +echo run install script with -l option to use this binary +fi +done diff --git a/scripts/install b/scripts/install index fff59c5..a7f1c96 100755 --- a/scripts/install +++ b/scripts/install @@ -100,7 +100,7 @@ REPO_DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit BIN_DIR="$REPO_DIR/bin" BIN_NAME=${BIN_NAME:-caddy} [ "$OS" == windows ] && BIN_NAME=$BIN_NAME.exe -BIN_PATH="$BIN_DIR/$BIN_NAME" +BIN_PATH="$REPO_DIR/$BIN_NAME" echo $BIN_PATH @@ -156,7 +156,7 @@ if [ $URL ]; then echo "Downloading Archive $URL" -wget --user=-u $GITHUB_USER --password=$GITHUB_TOKEN -q $URL +wget --user=-u $GITHUB_USER --password=$GITHUB_TOKEN -q $URL -P $BIN_DIR ARC=$(basename $URL) echo Extracting Caddy from Archive, $ARC diff --git a/scripts/install-xcaddy b/scripts/install-xcaddy new file mode 100755 index 0000000..a97332f --- /dev/null +++ b/scripts/install-xcaddy @@ -0,0 +1,5 @@ +#!/bin/bash +DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit +BUILD_DIR=$DIR/build +export GOPATH=$BUILD_DIR +go get -u github.com/caddyserver/xcaddy/cmd/xcaddy diff --git a/scripts/mkuser b/scripts/mkuser index c5f32e5..5bdf7ed 100755 --- a/scripts/mkuser +++ b/scripts/mkuser @@ -1,21 +1,23 @@ #!/bin/bash DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit +UID=${1:-937} sudo userdel caddy sudo groupadd caddy -sudo groupmod --gid 937 caddy +# change uid to your liking. Best if same on all instances +sudo groupmod --gid $UID caddy +sudo mkdir -p $DIR/user sudo useradd --system \ -m \ --uid 937 \ --gid caddy \ --create-home \ - --home-dir "$DIR" \ + --home-dir "$DIR/user" \ --shell /bin/bash \ - --comment "Caddy web server" \ + --comment "Caddy web server user" \ caddy sudo passwd caddy +# add current user to caddy group for rw access sudo usermod -a -G caddy $USER -sudo chown -R caddy:caddy "$DIR" -sudo chmod g+rw -R "$DIR" cat /etc/passwd | grep caddy cat /etc/passwd | grep sysadmin $DIR/scripts/own diff --git a/scripts/newconf b/scripts/newconf index 1a00ca1..57b66ca 100755 --- a/scripts/newconf +++ b/scripts/newconf @@ -1,4 +1,5 @@ #!/bin/bash DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit -touch $DIR/conf/$1.conf -sudo chown caddy:caddy $DIR/conf/$1.conf +CONF=${1:-caddy} +touch $DIR/conf/$CONF.conf +sudo chown caddy:caddy $DIR/conf/$CONF.conf diff --git a/scripts/own b/scripts/own index c86472d..a6ed8d3 100755 --- a/scripts/own +++ b/scripts/own @@ -1,5 +1,11 @@ #!/bin/bash # reset ownership if need be. User must be in caddy group DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit +echo setting ownership and mode on $DIR sudo chown -R caddy:caddy $DIR -sudo chmod g+rwx -R $DIR +sudo chmod -R ug=rw,o=r,a+X $DIR +sudo chmod ug+x -R $DIR/scripts +sudo chmod ug+x -R $DIR/env +sudo chmod ug+x -R $DIR/caddy +sudo chmod ug+x -R $DIR/bin +sudo chmod ug+x -R $DIR/build/bin diff --git a/scripts/pre-commit b/scripts/pre-commit new file mode 100644 index 0000000..5bc097a --- /dev/null +++ b/scripts/pre-commit @@ -0,0 +1,5 @@ +#!/bin/sh +echo "encrypting files and adding to commit" +git secret hide +git add .gitsecret/paths/mapping.cfg +git add *.secret diff --git a/scripts/run b/scripts/run index a2f4f91..a666b13 100755 --- a/scripts/run +++ b/scripts/run @@ -2,6 +2,6 @@ # one off run command for testing without systemd DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit CONF=${1:-caddy} -$DIR/env/aws.sh +$DIR/env/AWS.env sudo -E /usr/bin/env | grep AWS -sudo -E $DIR/bin/caddy run --config $DIR/conf/$CONF.conf --adapter caddyfile +sudo -E $DIR/caddy run --config $DIR/conf/$CONF.conf --adapter caddyfile diff --git a/systemd/install b/systemd/install old mode 100755 new mode 100644 diff --git a/systemd/log b/systemd/log old mode 100755 new mode 100644 diff --git a/systemd/persist b/systemd/persist old mode 100755 new mode 100644 diff --git a/systemd/start b/systemd/start old mode 100755 new mode 100644 diff --git a/systemd/stop b/systemd/stop old mode 100755 new mode 100644