1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-01 22:26:24 -07:00

Replace that clunky build.sh with a slightly less clunky Makefile

This commit is contained in:
Eggbertx 2020-03-20 11:04:39 -07:00
parent 48aaad4e6d
commit 13fffdb4c9
5 changed files with 129 additions and 354 deletions

121
Makefile Normal file
View file

@ -0,0 +1,121 @@
BIN=gochan
BINEXE=$(BIN)$(shell go env GOEXE)
GCOS=$(shell go env GOOS)
GCOS_NAME=${GCOS}
ifeq (${GCOS_NAME},darwin)
GCOS_NAME=macos
endif
DOCUMENT_ROOT=/srv/gochan
RELEASE_NAME=${BIN}-v${VERSION}_${GCOS_NAME}
RELEASE_DIR=releases/${RELEASE_NAME}
PREFIX=/usr/local
VERSION=$(shell cat version)
GCFLAGS=-trimpath=${PWD}
ASMFLAGS=-trimpath=${PWD}
LDFLAGS=-X main.versionStr=${VERSION} -w -s
MINGW_PREFIX=GOARCH=amd64 CC='x86_64-w64-mingw32-gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -lssp
DOCUMENT_ROOT_FILES= \
css \
error \
javascript \
banned.jpg \
notbanned.png \
permabanned.jpg \
favicon* \
firstrun.html \
hittheroad*
build:
GOOS=${GCOS} go build -v -gcflags=${GCFLAGS} -asmflags=${ASMFLAGS} -ldflags="${LDFLAGS}" -o ${BINEXE} ./src
clean:
rm -f ${BIN}*
rm -rf releases/
dependencies:
go get -v \
github.com/disintegration/imaging \
github.com/nranchev/go-libGeoIP \
github.com/go-sql-driver/mysql \
github.com/lib/pq \
golang.org/x/net/html \
github.com/aquilax/tripcode \
golang.org/x/crypto/bcrypt \
github.com/frustra/bbcode \
github.com/mattn/go-sqlite3 \
github.com/tdewolff/minify \
gopkg.in/mojocn/base64Captcha.v1
docker-image:
$(error Docker image creation not yet implemented)
docker build . -t="eggbertx/gochan"
install:
mkdir -p \
${PREFIX}/share/gochan \
${DOCUMENT_ROOT}/html \
/etc/gochan \
/var/log/gochan
cp ${DO_SYMLINKS} -f ./gochan ${PREFIX}/bin/${BINEXE}
cp ${DO_SYMLINKS} -f ./*.sql ${PREFIX}/share/gochan/
cp ${DO_SYMLINKS} -rf ./templates ${PREFIX}/share/gochan/
cd html && cp -rft ${DOCUMENT_ROOT} $(foreach file,${DOCUMENT_ROOT_FILES},${file})
$(info gochan successfully installed. If you haven't already, you should run)
$(info cp sample-configs/gochan.example.json /etc/gochan/gochan.json)
ifeq (${GCOS_NAME},linux)
$(info If your distro has systemd, you will also need to run the following commands)
$(info cp sample-configs/gochan-[mysql|postgresql|sqlite3].service /lib/systemd/system/gochan.service)
$(info systemctl daemon-reload)
$(info systemctl enable gochan.service)
$(info systemctl start gochan.service)
endif
install-symlinks:
DO_SYMLINKS=-s make install
js:
$(error Frontend transpilation coming soon)
release-all:
GOOS=darwin make release
GOOS=linux make release
GOOS=windows make release
release:
mkdir -p \
${RELEASE_DIR}/html \
${RELEASE_DIR}/log \
${RELEASE_DIR}/sample-configs
cp LICENSE ${RELEASE_DIR}/
cp README.md ${RELEASE_DIR}/
cp -rt ${RELEASE_DIR}/html/ $(foreach file,${DOCUMENT_ROOT_FILES},html/${file})
cp -r templates ${RELEASE_DIR}/
cp initdb_*.sql ${RELEASE_DIR}/
cp sample-configs/*.nginx ${RELEASE_DIR}/sample-configs/
cp sample-configs/gochan.example.json ${RELEASE_DIR}/sample-configs/
make build
make sass-minified
mv ${BINEXE} ${RELEASE_DIR}/
ifeq (${GCOS_NAME},macos)
cd releases && zip -r ${RELEASE_NAME}.zip ${RELEASE_NAME}
else ifeq (${GCOS_NAME},windows)
cd releases && zip -r ${RELEASE_NAME}.zip ${RELEASE_NAME}
else
cp sample-configs/gochan-mysql.service ${RELEASE_DIR}/sample-configs/
cp sample-configs/gochan-postgresql.service ${RELEASE_DIR}/sample-configs/
cp sample-configs/gochan-sqlite3.service ${RELEASE_DIR}/sample-configs/
tar -C releases -zcvf ${RELEASE_DIR}.tar.gz ${RELEASE_NAME}
endif
.PHONY: sass
sass:
sass --no-source-map sass:html/css
sass-minified:
sass --style compressed --no-source-map sass:html/css
test:
go test -v ./src

View file

@ -6,8 +6,6 @@ Gochan works in a manner similar to Kusaba X, Tinyboard and others. As such, Goc
Demo installation: https://gochan.org
**Note:** Cross-compilation to macOS has been temporarily disabled. If you need macOS support, build gochan from a macOS system.
# Installation
## Basic installation (from a release)

348
build.sh
View file

@ -1,348 +0,0 @@
#!/bin/bash
set -eo pipefail
if [ -e "version" ]; then version="v`cat version` "; fi
echo -e "Gochan ${version}build script\n"
BIN=gochan
VERSION=`cat version`
BUILDTIME=`date +%y%m%d.%H%M`
GCFLAGS=-trimpath=$PWD
ASMFLAGS=-trimpath=$PWD
LDFLAGS="-X main.versionStr=$VERSION -w -s"
export CGO_ENABLED=1
function usage {
if [ -z "$2" ]; then
cat - << EOF
Usage:
$0 [command or valid GOOS] [command arguments]
Commands:
clean remove any built binaries and releases
dependencies install necessary gochan dependencies
docker-image create Docker image (not yet implemented)
help show this help message
install install gochan to the system or specified location
release create release archives for deployment
sass use Sass to transpile the sass source files
Any other "command" will be treated as a GOOS to build gochan. If no commands
are given, gochan will be built for the current OS
EOF
exit
fi
case "$2" in
clean)
cat - <<- EOF
Usage: $0 clean
remove any built binaries and releases
EOF
;;
dependencies)
cat - <<- EOF
Usage: $0 dependencies
install necessary gochan dependencies
EOF
;;
docker-image)
cat - <<- EOF
Usage: $0 docker-image
create a Docker image (not yet implemented)
EOF
;;
help)
cat - <<- EOF
Usage: $0 help
show the help message and quits
EOF
;;
install)
cat - << EOF
Usage:
$0 install [--document-root /path/to/html] [--symlinks] [destination]
Installs gochan on the current system
Arguments:
--document-root|--html /path/to/html
install document root resources to specified path, otherwise
they are installed to ./html/
--symlinks|-s
create symbolic links instead of copying, useful for testing
Install locations if no destination is provided:
./gochan => /usr/local/bin/gochan
./gochan[.example].json => /etc/gochan/gochan.json
./templates/ => /usr/share/gochan/templates/
./log => => /var/log/gochan/
/etc/gochan/gochan.json will only be created if it doesn't already exist
EOF
;;
release)
cat - <<- EOF
Usage: $0 release [GOOS]
create release archives for Linux, macOS, and Windows or the specified platform
for deployment
EOF
;;
sass)
cat - <<- EOF
Usage: $0 sass [/path/to/html]
use sass to transpile the sass source files to ./html/css or the specified
document root
EOF
;;
*)
echo "Invalid command"
;;
esac
exit
}
function build {
if [ -z "$GOPATH" ]; then
echo "GOPATH not set. Please run 'export GOPATH=$PWD/lib' (or wherever you prefer) and run this again."
exit 1
fi
GCOS=$GOOS
if [ -n "$1" ]; then
if [ "$1" = "macos" ]; then GCOS="darwin"; else GCOS=$1; fi
fi
if [ "$GCOS" = "windows" ]; then
BIN=$BIN.exe
fi
NATIVE_GOOS=`go env GOOS`
if [ "$GCOS" = "darwin" ] && [ "$NATIVE_GOOS" != "darwin" ]; then
echo "Cross-compilation to macOS has been temporarily disabled because of a cgo issue."
echo "If you really need macOS support, build gochan from a macOS system."
exit 1
fi
if [ -z "$GCOS" ]; then
GCOS=$NATIVE_GOOS
fi
buildCmd="GOOS=$GCOS go build -v -gcflags=$GCFLAGS -asmflags=$ASMFLAGS -ldflags \"$LDFLAGS\" -o $BIN ./src"
if [ "$GCOS" = "windows" ]; then
buildCmd="GOARCH=amd64 CC='x86_64-w64-mingw32-gcc -fno-stack-protector -D_FORTIFY_SOURCE=0 -lssp' $buildCmd"
fi
if [ -n "$GCOS" ]; then
echo "Building gochan for '$GCOS'"
else
echo "Building gochan for native system"
fi
bash -c "$buildCmd"
}
function release {
GCOS=$GOOS
if [ -n "$1" ]; then
if [ "$1" = "darwin" ]; then GCOS="macos"; else GCOS=$1; fi
fi
DIRNAME=releases/gochan-v${VERSION}_${GCOS}64/
mkdir -p $DIRNAME
build $1
if [ "$GCOS" = "darwin" ]; then GCOS="macos"; fi
cp $BIN $DIRNAME
mkdir -p $DIRNAME/sample-configs
if [ "$GCOS" = "linux" ]; then
strip $DIRNAME/$BIN
cp sample-configs/gochan-mysql.service $DIRNAME/sample-configs
cp sample-configs/gochan-postgresql.service $DIRNAME/sample-configs
cp sample-configs/gochan-sqlite3.service $DIRNAME/sample-configs
fi
mkdir -p $DIRNAME/html
cp -r sass $DIRNAME
cp -r html/css $DIRNAME/html/css
cp -r html/error $DIRNAME/html/error
cp -r html/javascript $DIRNAME/html/javascript
touch $DIRNAME/html/firstrun.html
cp html/firstrun.html $DIRNAME/html/firstrun.html
mkdir -p $DIRNAME/log
cp -r templates $DIRNAME
cp initdb_*.sql $DIRNAME
cp sample-configs/*.nginx $DIRNAME/sample-configs/
cp README.md $DIRNAME
cp LICENSE $DIRNAME
cp sample-configs/gochan.example.json $DIRNAME/sample-configs/
cd releases
if [ "$GCOS" = "windows" ] || [ "$GCOS" = "macos" ]; then
zip gochan-v${VERSION}_${GCOS}64.zip gochan-v${VERSION}_${GCOS}64/*
else
tar -zcvf gochan-v${VERSION}_${GCOS}64.tar.gz gochan-v${VERSION}_${GCOS}64/
fi
cd ..
}
if [ $# = 0 ]; then
build
exit 0
fi
while [ -n "$1" ]; do
case "$1" in
clean)
echo "Deleting $BIN(.exe)"
rm -f $BIN
rm -f $BIN.exe
echo "Deleting release builds"
rm -rf releases
;;
dependencies)
go get -v \
github.com/disintegration/imaging \
github.com/nranchev/go-libGeoIP \
github.com/go-sql-driver/mysql \
github.com/lib/pq \
golang.org/x/net/html \
github.com/aquilax/tripcode \
golang.org/x/crypto/bcrypt \
github.com/frustra/bbcode \
github.com/mattn/go-sqlite3 \
github.com/tdewolff/minify \
gopkg.in/mojocn/base64Captcha.v1
# github.com/mojocn/base64Captcha
;;
docker-image)
# echo "Docker image creation not yet implemented"
# exit 1
docker build . -t="eggbertx/gochan"
;;
help|-h|--help)
usage $@
;;
install)
shift
symarg=""
documentroot=""
installdir=""
configpath=""
while [ -n "$1" ]; do
case "$1" in
--symlinks|-s)
symarg="-s"
;;
--document-root|--html)
if [ -n "$2" ] && [ "$2" != "--symlinks" ] && [ "$2" != "-s" ]; then
shift
documentroot="$1"
fi
;;
*)
installdir="$1"
;;
esac
shift
done
if [ "$symarg" = "-s" ]; then
echo "Creating symlinks"
fi
if [ -n "$installdir" ]; then
echo "Install location: '$installdir'"
if [ -z "$documentroot" ]; then
documentroot=$installdir/html
fi
cp $symarg -f $PWD/gochan $installdir/gochan
cp $symarg -f $PWD/*.sql $installdir/
cp $symarg -rf $PWD/templates $installdir/templates/
# cp -f gochan.example.json $installdir/
if [ -f gochan.json ]; then
echo "Copying config file to $installdir/gochan.json"
cp $symarg -f $PWD/gochan.json $installdir/gochan.json
fi
mkdir -p $installdir/log
else
echo "Installing gochan globally"
if [ -z "$documentroot" ]; then
documentroot=/srv/gochan
fi
cp $symarg -f $PWD/gochan /usr/local/bin/gochan
mkdir -p /usr/local/share/gochan
cp $symarg -f $PWD/*.sql /usr/local/share/gochan/
cp $symarg -rf $PWD/templates /usr/local/share/gochan/templates/
echo "Creating /etc/gochan/ (if it doesn't already exist)"
mkdir -p /etc/gochan
echo "/etc/gochan created, you should run 'cp sample-configs/gochan.example.json /etc/gochan/gochan.json'"
# cp -f gochan.example.json /etc/gochan/
# if [ ! -f /etc/gochan/gochan.json ] && [ -f gochan.json ]; then
# echo "Copying gochan.json to /etc/gochan/gochan.json"
# cp $symarg -f $PWD/gochan.json /etc/gochan/gochan.json
# fi
echo "Creating /var/log/gochan (if it doesn't already exist)"
mkdir -p /var/log/gochan
fi
echo "Installing document root files and directories"
mkdir -p $documentroot
cp $symarg -rf $PWD/html/css/ $documentroot/
cp $symarg -rf $PWD/html/javascript/ $documentroot/javascript/
files=$PWD/html/*
for f in $files; do
if [ -f $f ]; then
destfile=$documentroot/$(basename $f)
echo "Installing $f to $destfile"
cp $symarg -f $f $destfile
fi
done
if [ -d /lib/systemd/system ]; then
cat - <<-EOF
It looks like your distribution has systemd. build.sh no longer automatically
installs the service for you, but you can install it yourself by copying the
appropriate .service file in $PWD/sample-configs/ that corresponds to your
SQL database to /lib/systemd/system/gochan.service then running the
following commands
systemctl daemon-reload
systemctl enable gochan.service
systemctl start gochan.service
EOF
fi
echo "Installation complete. Make sure to set the following values in gochan.json:"
echo "DocumentRoot => $documentroot"
echo "TemplateDir => /usr/local/share/gochan/templates"
echo "LogDir => /var/log/gochan"
exit 0
;;
release)
if [ -n "$2" ]; then
release $2
else
release linux
#release macos
release windows
fi
;;
sass)
if [ -z `which sass` ]; then
echo "Sass is not installed, exiting."
exit 1
fi
shift
sassdir="html"
if [ -n "$1" ]; then sassdir=$1; fi
mkdir -p $sassdir
echo "Transpiling Sass files into destination directory `realpath $sassdir/css`"
sass --style compressed --no-source-map sass:$sassdir/css
;;
*)
build $1
shift
;;
esac
shift
done

View file

@ -13,5 +13,5 @@ const (
)
func TestGochan(t *testing.T) {
t.Fatal("This doesn't do anything interesting yet.")
t.Log("This doesn't do anything interesting yet.")
}

View file

@ -64,6 +64,10 @@ else
fi
apt-get -y install git subversion mercurial nginx ffmpeg golang-1.10
mkdir -p /root/bin
ln -s /usr/lib/go-1.10/bin/* /root/bin/
export PATH=$PATH:/root/bin
echo "export PATH=$PATH:/root/bin" >> /root/.bashrc
rm -f /etc/nginx/sites-enabled/* /etc/nginx/sites-available/*
ln -sf /vagrant/sample-configs/gochan-fastcgi.nginx /etc/nginx/sites-available/gochan.nginx
@ -138,10 +142,10 @@ mkdir -p /vagrant/lib
source /home/vagrant/.bashrc
export GOPATH=/vagrant/lib
cd /vagrant
./build.sh dependencies
./build.sh
make dependencies
make
EOF
./build.sh install
make install
# if [ -d /lib/systemd ]; then
# systemctl start gochan.service