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

Change-Id: I2c50f04a023fa2014c2b5ed5a35a73e9f2cc0c28
