diff --git a/.gitignore b/.gitignore index 1fcb152..01246f4 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -out +linkserv diff --git a/LICENSE b/LICENSE index 29bcfaa..0cdd7e4 100644 --- a/LICENSE +++ b/LICENSE @@ -630,7 +630,7 @@ state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. A URL Shortener called Link. - Copyright (C) 2021 i@fsh.ee + Copyright (C) 2021 swurl@swurl.xyz This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by diff --git a/doc/link.conf b/doc/link.conf new file mode 100644 index 0000000..2a9a4dd --- /dev/null +++ b/doc/link.conf @@ -0,0 +1,6 @@ +BIN="BINDIR/BINNAME" # replace this with the path to link (usually /usr/local/bin/linkserv by default) +COPY="2021 you@your.doma.in" +DB="/srv/link/link.db" +PORT=8080 +SEED="secret" +URL="https://your.doma.in" diff --git a/doc/link.service b/doc/link.service index 8fa044d..22576d9 100644 --- a/doc/link.service +++ b/doc/link.service @@ -3,7 +3,8 @@ Description=serve link instance After=network.target [Service] -ExecStart=/usr/local/bin/linkserv -url https://your.doma.in -db /srv/link/link.db -seed "secret" +EnvironmentFile=/etc/link.conf +ExecStart=/bin/sh -c '"${BIN}" -copy "${COPY}" -db "${DB}" -port ${PORT} -seed "${SEED}" -url "${URL}"' [Install] WantedBy=multi-user.target diff --git a/go.mod b/go.mod index 96be31f..0e543fc 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,9 @@ -module git.fsh.ee/i/link +module git.swurl.xyz/swirl/link go 1.16 require ( + golang.org/dl v0.0.0-20210805175753-70f86bf65abd // indirect gorm.io/driver/sqlite v1.1.4 gorm.io/gorm v1.21.9 ) diff --git a/go.sum b/go.sum index 48ccbf2..1231ce5 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/jinzhu/now v1.1.2 h1:eVKgfIdy9b6zbWBMgFpfDPoAMifwSZagU9HmEU6zgiI= github.com/jinzhu/now v1.1.2/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/mattn/go-sqlite3 v1.14.5 h1:1IdxlwTNazvbKJQSxoJ5/9ECbEeaTTyeU7sEAZ5KKTQ= github.com/mattn/go-sqlite3 v1.14.5/go.mod h1:WVKg1VTActs4Qso6iwGbiFih2UIHo0ENGwNd0Lj+XmI= +golang.org/dl v0.0.0-20210805175753-70f86bf65abd h1:zTi7rOU7NMmBInGr/IFQrDXBgYZ2VCO7BlylmxGpQTs= +golang.org/dl v0.0.0-20210805175753-70f86bf65abd/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ= gorm.io/driver/sqlite v1.1.4 h1:PDzwYE+sI6De2+mxAneV9Xs11+ZyKV6oxD3wDGkaNvM= gorm.io/driver/sqlite v1.1.4/go.mod h1:mJCeTFr7+crvS+TRnWc5Z3UvwxUN1BGBLMrf5LA9DYw= gorm.io/gorm v1.20.7/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw= diff --git a/index.html b/index.html index 65aab04..c93ce1b 100644 --- a/index.html +++ b/index.html @@ -87,32 +87,21 @@ to do (one of the design goals). Below are instructions detailing how. | # emerge --ask dev-lang/go dev-vcs/git | # apt install go git | -| 2. Fetch and compile the source code -| # env GO111MODULE=off go get git.swurl.xyz/swirl/link +| 2. Clone the source code +| # git clone https://git.swurl.xyz/swirl/link | -| 3. Copy the binary to your binary directory -| # cp $GOPATH/bin/link /usr/local/bin/linkserv -| # # Named linkserv to prevent conflicts with GNU link +| 3. Compile +| # cd link && make | -| 4. Create a directory to store your database -| # mkdir -p /srv/link +| 4. Install +| # make install | -| 5. (optional) Copy the example systemd service -| # cp doc/link.service /etc/systemd/system/ -| * You can also create an equivalent for openrc, runit, etc. +| 5. Change the configuration to reflect your desired options +| # vim /etc/link.conf | -| 6. Change the domain to reflect your setup -| # sed -i 's/your.doma.in/[DOMAIN HERE]/g' /etc/systemd/system/link.service -| -| 7. Change the seed to something secure -| # sed -i 's/secret/SecretPasswordHere/g' /etc/systemd/system/link.service -| -| 8. Enable and start the service +| 6. Enable and start the service | # systemctl enable --now link | -| 9. Or, run it manually -| # linkserv -url http://your.doma.in -db /srv/link/link.db -seed "secret" -| | * The server is now running on localhost at port 8080. | * If the SQLite database does not exist, it will be created. | * All logging will be printed to standard error and standard output. @@ -129,8 +118,8 @@ to do (one of the design goals). Below are instructions detailing how. | # emerge --ask www-servers/nginx app-crypt/certbot-nginx | # apt install nginx python-certbot-nginx | -| 2. Copy the example site file -| # cp doc/link.nginx.conf /etc/nginx/sites-available/link +| 2. Install if you haven't already +| # make install | | 3. Change the domain to reflect your setup | # sed -i 's/your.doma.in/[DOMAIN HERE]/g' /etc/nginx/sites-available/link @@ -156,7 +145,7 @@ location /shortener { diff --git a/main.go b/main.go index 5568f3e..3841d30 100644 --- a/main.go +++ b/main.go @@ -1,5 +1,5 @@ // A URL Shortener called Link. -// Copyright (C) 2021 i@fsh.ee +// Copyright (C) 2021 swurl@swurl.xyz // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as published by diff --git a/makefile b/makefile index b57cb7e..d5c5cbd 100644 --- a/makefile +++ b/makefile @@ -1,12 +1,13 @@ -BIN=out -CC=go1.17beta1 +BIN=linkserv +CC=go -all: setup vendor gen build +prefix=/usr/local +confdir=/etc +systemd_dir=${DESTDIR}${confdir}/systemd/system +nginx_dir=${DESTDIR}${confdir}/nginx +bindir=${DESTDIR}${prefix}/bin -setup: - @env GOOD=off go get golang.org/dl/$(CC) - @env GOOD=off $(CC) download - #@env GO111MODULE=off $(CC) get github.com/golangci/golangci-lint/cmd/golangci-lint +all: vendor gen build vendor: go.mod go.sum @$(CC) mod tidy @@ -15,18 +16,30 @@ vendor: go.mod go.sum build: @$(CC) build -ldflags='-s -w' -o $(BIN) -gen: +gen: @$(CC) generate ./... -test: +test: @env $(ENV) $(CC) test ./... -cover -count 1 run: lint build @clear - @env $(ENV) ./$(BIN) -v -demo -copy "2021 i@fsh.ee" -url https://dev.fsh.ee -port 8080 -db /tmp/link_test_db_1.sql -seed secret + @env $(ENV) ./$(BIN) -v -demo -copy "2021 swurl@swurl.xyz" -url https://short.swurl.xyz -port 8080 -db /tmp/link.db -seed "secret" dev: @find . -type f | grep -E '(.*)\.(go|html)' | entr -cr make run -lint: +lint: @golangci-lint run ./... + +install-nginx: + @install -Dm644 doc/link.nginx.conf ${nginx_dir}/sites-available/link + +install-systemd: + @install -Dm644 doc/link.service ${systemd_dir}/link.service + @install -Dm644 doc/link.conf ${DESTDIR}/${confdir}/link.conf + +install-bin: + @install -Dm755 ${BIN} ${bindir}/${BIN} + +install: build install-bin install-nginx install-systemd diff --git a/vendor/modules.txt b/vendor/modules.txt index 3d7e8d2..a703dbb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -4,6 +4,8 @@ github.com/jinzhu/inflection github.com/jinzhu/now # github.com/mattn/go-sqlite3 v1.14.5 github.com/mattn/go-sqlite3 +# golang.org/dl v0.0.0-20210805175753-70f86bf65abd +## explicit # gorm.io/driver/sqlite v1.1.4 ## explicit gorm.io/driver/sqlite