#!/bin/sh

# this script packages up all the binaries, and a script (deploy.sh)
# to twiddle with the server and the binaries

set -eux


VERSION=$(date --iso-8601=minutes | tr -d ':' | sed 's|\+.*$||')
if [[ -d .git ]]; then
  VERSION=$(git show --pretty=format:%h -q)-${VERSION}
fi

out=zoekt-${VERSION}
mkdir -p ${out}

for d in cmd/*
do
  if echo $d | grep sandbox ; then
    make -C $d && cp $d/zoekt-sandbox ${out}/
  else
    go build -ldflags "-X main.Version=$VERSION"  -o ${out}/$(basename $d) github.com/google/zoekt/$d
  fi
done

cat <<EOF > ${out}/deploy.sh
#!/bin/bash

echo "Set the following in the environment."
echo ""
echo '  export PATH="'$PWD'/bin:$PATH'
echo ""

set -eux

# Allow sandbox to create NS's
sudo sh -c 'echo 1 > /proc/sys/kernel/unprivileged_userns_clone'

# we mmap the entire index, but typically only want the file contents.
sudo sh -c 'echo 1 >/proc/sys/vm/overcommit_memory'

# allow bind to 80 and 443
sudo setcap 'cap_net_bind_service=+ep' bin/zoekt-webserver

EOF

chmod +x ${out}/deploy.sh

tar -cJf zoekt-deploy-${VERSION}.tar.xz ${out}/*

#!/bin/sh

# this script packages up all the binaries, and a script (deploy.sh)
# to twiddle with the server and the binaries

set -eux
mkdir -p bin


VERSION=$(date --iso-8601=minutes | tr -d ':' | sed 's|\+.*$||')
if [[ -d .git ]]; then
  VERSION=$(git show --pretty=format:%h -q)-${VERSION}
fi

for d in cmd/*
do
  if echo $d | grep sandbox ; then
    make -C $d && cp $d/zoekt-sandbox bin/
  else
    go build -ldflags "-X main.Version=$VERSION"  -o bin/$(basename $d) github.com/google/zoekt/$d
  fi
done

cat <<EOF > bin/deploy.sh
#!/bin/bash

echo "Set the following in the environment."
echo ""
echo '  export PATH="'$PWD'/bin:$PATH'
echo ""

set -eux

# Allow sandbox to create NS's
sudo sh -c 'echo 1 > /proc/sys/kernel/unprivileged_userns_clone'

# we mmap the entire index, but typically only want the file contents.
sudo sh -c 'echo 1 >/proc/sys/vm/overcommit_memory'

# allow bind to 80 and 443
sudo setcap 'cap_net_bind_service=+ep' bin/zoekt-webserver

EOF

chmod +x bin/deploy.sh

zip zoekt-deploy.${VERSION}.zip bin/*

--- 
+++ 
@@ -4,7 +4,6 @@
 # to twiddle with the server and the binaries
 
 set -eux
-mkdir -p bin
 
 
 VERSION=$(date --iso-8601=minutes | tr -d ':' | sed 's|\+.*$||')
@@ -12,16 +11,19 @@
   VERSION=$(git show --pretty=format:%h -q)-${VERSION}
 fi
 
+out=zoekt-${VERSION}
+mkdir -p ${out}
+
 for d in cmd/*
 do
   if echo $d | grep sandbox ; then
-    make -C $d && cp $d/zoekt-sandbox bin/
+    make -C $d && cp $d/zoekt-sandbox ${out}/
   else
-    go build -ldflags "-X main.Version=$VERSION"  -o bin/$(basename $d) github.com/google/zoekt/$d
+    go build -ldflags "-X main.Version=$VERSION"  -o ${out}/$(basename $d) github.com/google/zoekt/$d
   fi
 done
 
-cat <<EOF > bin/deploy.sh
+cat <<EOF > ${out}/deploy.sh
 #!/bin/bash
 
 echo "Set the following in the environment."
@@ -42,6 +44,6 @@
 
 EOF
 
-chmod +x bin/deploy.sh
+chmod +x ${out}/deploy.sh
 
-zip zoekt-deploy.${VERSION}.zip bin/*
+tar -cJf zoekt-deploy-${VERSION}.tar.xz ${out}/*
Build deploy tarball with version in the directory.

Change-Id: I2c50f04a023fa2014c2b5ed5a35a73e9f2cc0c28
