Make get.sh more usable as a package builder

Add package.sh script as a wrapper for get.sh that sets necessary
envvars.
This commit is contained in:
fox.cpp 2019-11-19 17:25:15 +03:00
parent f569d7e941
commit 3a61903189
No known key found for this signature in database
GPG key ID: E76D97CCEDE90B6C
3 changed files with 56 additions and 15 deletions

3
dist/install.sh vendored
View file

@ -7,6 +7,9 @@ if [ -z "$FAIL2BANDIR" ]; then
FAIL2BANDIR=/etc/fail2ban
fi
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $script_dir
install -Dm 0644 -t "$PREFIX/share/vim/vimfiles/ftdetect/" vim/ftdetect/maddy-conf.vim
install -Dm 0644 -t "$PREFIX/share/vim/vimfiles/ftplugin/" vim/ftplugin/maddy-conf.vim
install -Dm 0644 -t "$PREFIX/share/vim/vimfiles/syntax/" vim/syntax/maddy-conf.vim

35
get.sh
View file

@ -20,6 +20,9 @@ fi
if [ "$SUDO" == "" ]; then
SUDO=sudo
fi
if [ "$NO_RUN" == "" ]; then
NO_RUN=0
fi
export CGO_CFLAGS="-g -O2 -D_FORTIFY_SOURCE=2 $CFLAGS"
export CGO_CXXFLAGS="-g -O2 -D_FORTIFY_SOURCE=2 $CXXFLAGS"
@ -97,13 +100,9 @@ install_executables() {
install_dist() {
echo 'Installing dist files...' >&2
pushd "`source_dir`/dist" >/dev/null
$SUDO ./install.sh
popd >/dev/null
$SUDO "`source_dir`/dist/install.sh"
$SUDO sed -Ei "s!/usr/bin!$PREFIX/bin!g" "$SYSTEMDUNITS/system/maddy.service" "$SYSTEMDUNITS/system/maddy@.service"
$SUDO systemctl daemon-reload
}
install_man() {
@ -122,14 +121,14 @@ install_man() {
echo 'Installing man pages...' >&2
for f in `source_dir`/man/*.1.scd; do
scdoc < "$f" | gzip > tmp.gz
$SUDO install -Dm 0644 tmp.gz "$PREFIX/share/man/man1"
scdoc < "$f" | gzip > /tmp/maddy-tmp.gz
$SUDO install -Dm 0644 /tmp/maddy-tmp.gz "$PREFIX/share/man/man1/`basename -s .scd $f`.gz"
done
for f in `source_dir`/man/*.5.scd; do
scdoc < "$f" | gzip > tmp.gz
$SUDO install -Dm 0644 tmp.gz "$PREFIX/share/man/man5"
scdoc < "$f" | gzip > /tmp/maddy-tmp.gz
$SUDO install -Dm 0644 /tmp/maddy-tmp.gz "$PREFIX/share/man/man5/`basename -s .scd $f`.gz"
done
rm tmp.gz
rm /tmp/maddy-tmp.gz
}
@ -144,19 +143,22 @@ install_config() {
if ! [ -e "$CONFPATH" ]; then
echo 'Installing default configuration...' >&2
cp "`source_dir`/maddy.conf" .
install "`source_dir`/maddy.conf" /tmp/maddy.conf
host=`hostname`
set +e # premit to fail
read -p "What's your domain, btw? [$host] > " DOMAIN
set -e
if [ "$DOMAIN" = "" ]; then
DOMAIN=$host
fi
echo 'Good, I will put that into configuration for you.' >&2
sed -Ei "s/^\\$\\(primary_domain\) = .+$/$\(primary_domain\) = $DOMAIN/" maddy.conf
sed -Ei "s/^\\$\\(hostname\) = .+$/$\(hostname\) = $DOMAIN/" maddy.conf
sed -Ei "s/^\\$\\(primary_domain\) = .+$/$\(primary_domain\) = $DOMAIN/" /tmp/maddy.conf
sed -Ei "s/^\\$\\(hostname\) = .+$/$\(hostname\) = $DOMAIN/" /tmp/maddy.conf
$SUDO install -Dm 0644 maddy.conf "$CONFPATH"
$SUDO install -Dm 0644 /tmp/maddy.conf "$CONFPATH"
rm /tmp/maddy.conf
else
echo "Configuration already exists in /etc/maddy/maddy.conf, skipping defaults installation." >&2
fi
@ -173,6 +175,7 @@ run() {
install_man
install_config
create_user
$SUDO systemctl daemon-reload
echo "Okay, almost ready." >&2
echo "It's up to you to figure out TLS certificates and DNS stuff, though." >&2
@ -180,4 +183,6 @@ run() {
echo "https://github.com/foxcpp/maddy/wiki/Tutorial:-Setting-up-a-mail-server-with-maddy" >&2
}
run
if [ "$NO_RUN" != "1" ]; then
run
fi

33
package.sh Executable file
View file

@ -0,0 +1,33 @@
#!/bin/bash
# Build maddy using get.sh and copy all installation files into maddy-pkgdir-XXXXXXXXX directory.
# DO NOT RUN FROM THE SOURCE DIRECTORY. IT WILL BREAK.
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
if [ "$script_dir" = "$PWD" ]; then
echo 'Do not run package.sh from the source directory.' >&2
exit 1
fi
if [ "$pkgdir" = "" ]; then
pkgdir=$PWD/maddy-pkgdir-`date +%s`
rm -rf $pkgdir
mkdir $pkgdir
fi
export PREFIX=$pkgdir/usr FAIL2BANDIR=$pkgdir/etc/fail2ban CONFPATH=$pkgdir/etc/maddy/maddy.conf NO_RUN=1 SUDO=fakeroot
source $script_dir/get.sh
mkdir -p maddy-setup
cd maddy-setup/
function run() {
ensure_go_toolchain
download_and_compile
install_executables
install_dist
install_man
install_config </dev/null
}
run