moved all scripts to scripts directory and refactored accordingly

somewhat working example site with conf file
giskard
David Kebler 2020-10-27 10:09:20 -07:00
parent da5d968a3a
commit 87d4316e62
26 changed files with 153 additions and 67 deletions

1
build/.gitignore vendored
View File

@ -1 +0,0 @@
/pkg/

View File

@ -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

View File

@ -1,3 +1 @@
linux arm64 linux arm64
linux arm 7

View File

@ -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

View File

@ -1 +1 @@
github.com/caddy-dns/route53

View File

@ -1,4 +0,0 @@
#!/bin/bash
DIR="$(dirname "$(readlink -f "$0")")"
export GOPATH=$DIR
go get -u github.com/caddyserver/xcaddy/cmd/xcaddy

BIN
env/AWS.secret vendored

Binary file not shown.

BIN
env/aws.sh.secret vendored

Binary file not shown.

View File

@ -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;
}

13
example-web/example.md Normal file
View File

@ -0,0 +1,13 @@
---
title: Example
---
# Example Rendered Markdown
This is an example markdown file rendered via a template by Caddy2
`some code`
<!-- ```
Fenced Code Block
``` -->

View File

@ -1,13 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title>Test Web</title>
</head>
<body>
<div>
<h1>Test Web</h1>
</div>
</body>
</html>

5
example-web/index.md Normal file
View File

@ -0,0 +1,5 @@
---
title: Index File
---
# Default Index File
[See Example Markdown File](./example.md)

15
example-web/template.html Normal file
View File

@ -0,0 +1,15 @@
{{$markdownFilePath := printf .OriginalReq.URL.Path}}
{{$markdownFile := (include $markdownFilePath | splitFrontMatter)}}
{{$meta := $markdownFile.Meta }}
<!DOCTYPE html>
<html>
<head>
<title>{{ $meta.title }}</title>
<link rel="stylesheet" href="/css/default.css">
</head>
<body>
<main>
{{markdown $markdownFile.Body }}
</main>
</body>
</html>

43
scripts/build Executable file
View File

@ -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

View File

@ -100,7 +100,7 @@ REPO_DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit
BIN_DIR="$REPO_DIR/bin" BIN_DIR="$REPO_DIR/bin"
BIN_NAME=${BIN_NAME:-caddy} BIN_NAME=${BIN_NAME:-caddy}
[ "$OS" == windows ] && BIN_NAME=$BIN_NAME.exe [ "$OS" == windows ] && BIN_NAME=$BIN_NAME.exe
BIN_PATH="$BIN_DIR/$BIN_NAME" BIN_PATH="$REPO_DIR/$BIN_NAME"
echo $BIN_PATH echo $BIN_PATH
@ -156,7 +156,7 @@ if [ $URL ]; then
echo "Downloading Archive $URL" 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) ARC=$(basename $URL)
echo Extracting Caddy from Archive, $ARC echo Extracting Caddy from Archive, $ARC

5
scripts/install-xcaddy Executable file
View File

@ -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

View File

@ -1,21 +1,23 @@
#!/bin/bash #!/bin/bash
DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit
UID=${1:-937}
sudo userdel caddy sudo userdel caddy
sudo groupadd 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 \ sudo useradd --system \
-m \ -m \
--uid 937 \ --uid 937 \
--gid caddy \ --gid caddy \
--create-home \ --create-home \
--home-dir "$DIR" \ --home-dir "$DIR/user" \
--shell /bin/bash \ --shell /bin/bash \
--comment "Caddy web server" \ --comment "Caddy web server user" \
caddy caddy
sudo passwd caddy sudo passwd caddy
# add current user to caddy group for rw access
sudo usermod -a -G caddy $USER 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 caddy
cat /etc/passwd | grep sysadmin cat /etc/passwd | grep sysadmin
$DIR/scripts/own $DIR/scripts/own

View File

@ -1,4 +1,5 @@
#!/bin/bash #!/bin/bash
DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit
touch $DIR/conf/$1.conf CONF=${1:-caddy}
sudo chown caddy:caddy $DIR/conf/$1.conf touch $DIR/conf/$CONF.conf
sudo chown caddy:caddy $DIR/conf/$CONF.conf

View File

@ -1,5 +1,11 @@
#!/bin/bash #!/bin/bash
# reset ownership if need be. User must be in caddy group # reset ownership if need be. User must be in caddy group
DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit
echo setting ownership and mode on $DIR
sudo chown -R caddy:caddy $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

5
scripts/pre-commit Normal file
View File

@ -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

View File

@ -2,6 +2,6 @@
# one off run command for testing without systemd # one off run command for testing without systemd
DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit DIR=$(dirname "$(dirname "$(readlink -f "$0")")") || exit
CONF=${1:-caddy} CONF=${1:-caddy}
$DIR/env/aws.sh $DIR/env/AWS.env
sudo -E /usr/bin/env | grep AWS 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

0
systemd/install Executable file → Normal file
View File

0
systemd/log Executable file → Normal file
View File

0
systemd/persist Executable file → Normal file
View File

0
systemd/start Executable file → Normal file
View File

0
systemd/stop Executable file → Normal file
View File