timeout 600 go get -u github.com/golang/dep/cmd/dep

cd src/github.com/wal-g/wal-g

timeout 600 make deps
timeout 600 make pg_build
mkdir main/pg/debian
cat > main/pg/debian/changelog<<EOH
wal-g ($(git rev-list HEAD --count)-$(git rev-parse --short HEAD)) stable; urgency=low
  * Yandex autobuild
 -- ${USER} <${USER}@$(hostname)>  $(date +'%a, %d %b %Y %H:%M:%S %z')
EOH
cat > main/pg/debian/control<<'EOH'
Source: wal-g
Section: net
Priority: optional
Maintainer: Andrey Borodin <x4mmm@yandex-team.ru>
Build-Depends: debhelper (>= 9.0.0)
Standards-Version: 3.9.5
Vcs-Git: git://github.com/wal-g/wal-g.git
Vcs-Browser: https://github.com/wal-g/wal-g

Package: wal-g
Architecture: any
Depends: adduser, ${shlibs:Depends}, ${misc:Depends}
Description: Continuous archiving for Postgres with S3 support
 Full documentation: https://github.com/wal-g/wal-g
EOH
cat > main/pg/debian/rules<<'EOH'
#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DH_OPTIONS
export DH_GOPKG := github.com/wal-g/wal-g

override_dh_builddeb:
	dh_builddeb -- -z9 -Zxz -Snone

override_dh_auto_install:
	dh_auto_install

%:
	dh $@ --parallel
EOH
cat > main/pg/debian/compat<<EOH
9
EOH
cat > main/pg/Makefile<<'EOH'
prefix = /usr

all:

install:
	install -D wal-g $(DESTDIR)$(prefix)/bin/wal-g
clean:

distclean: clean

uninstall:
	-rm -rf $(DESTDIR)$(prefix)/bin/wal-g
.PHONY: all install clean distclean uninstall
EOH