Skip to content

Instantly share code, notes, and snippets.

@tgardiner
Created January 13, 2019 01:42
Show Gist options
  • Save tgardiner/c7ae3780a567ef72dbcbcce555f7fa62 to your computer and use it in GitHub Desktop.
Save tgardiner/c7ae3780a567ef72dbcbcce555f7fa62 to your computer and use it in GitHub Desktop.
#!/bin/bash
##
## Statically Compile SSH
## See https://github.com/andrew-d/static-binaries for more binaries
##
set -e
set -o pipefail
set -x
ZLIB_VERSION=1.2.11
OPENSSL_VERSION=1.0.2f
OPENSSH_VERSION=7.9p1
if [ ! -d /build ]; then mkdir /build; fi
if [ ! -d /output ]; then mkdir /output; fi
function build_zlib() {
cd /build
# Download
curl -LO http://zlib.net/zlib-${ZLIB_VERSION}.tar.gz
tar zxvf zlib-${ZLIB_VERSION}.tar.gz
cd zlib-${ZLIB_VERSION}
# Build
CC='/usr/bin/gcc -static' CFLAGS='-fPIC' ./configure \
--static
make -j4
}
function build_openssl() {
cd /build
# Download
curl -LO https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz
tar zxvf openssl-${OPENSSL_VERSION}.tar.gz
cd openssl-${OPENSSL_VERSION}
# Configure
CC='/usr/bin/gcc -static' CFLAGS='-fPIC' ./Configure no-shared no-async linux-x86_64
# Build
make -j4
echo "** Finished building OpenSSL"
}
function build_openssh() {
cd /build
# Download
curl -LO https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${OPENSSH_VERSION}.tar.gz
tar xzvf openssh-${OPENSSH_VERSION}.tar.gz
cd openssh-${OPENSSH_VERSION}
# Build
CC='/usr/bin/gcc -static' \
./configure --with-zlib=/build/zlib-${ZLIB_VERSION} \
--with-ssl-dir=/build/openssl-${OPENSSL_VERSION}
make -j4
strip ssh
}
function doit() {
build_zlib
build_openssl
build_openssh
# Copy to output
if [ -d /output ]
then
OUT_DIR=/output/`uname | tr 'A-Z' 'a-z'`/`uname -m`
mkdir -p $OUT_DIR
cp /build/openssh-${OPENSSH_VERSION}/ssh $OUT_DIR/
echo "** Finished **"
else
echo "** /output does not exist **"
fi
}
doit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment