2020-02-28 22:39:11 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -ve
|
|
|
|
|
|
|
|
PROVISION="scripts/provision/$BOX/vagrant"
|
|
|
|
|
|
|
|
if [ ! -f /etc/vagrant_box_build_time ]; then
|
2020-03-04 15:25:40 +00:00
|
|
|
echo 'This script should only be called during vagrant provisioning'
|
2020-02-28 22:39:11 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-03-04 15:25:40 +00:00
|
|
|
if [[ $HOME = /go/* ]]; then
|
|
|
|
echo 'Must not launch vagrant from /go/'
|
2020-02-28 22:39:11 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2020-02-28 23:51:19 +00:00
|
|
|
cd
|
2020-02-28 22:39:11 +00:00
|
|
|
|
|
|
|
# --- Default to root user for vagrant ssh
|
|
|
|
cat <<\EOF >/etc/profile.d/root.sh
|
|
|
|
[ $EUID -ne 0 ] && exec sudo -i
|
|
|
|
EOF
|
|
|
|
|
2020-02-28 23:51:19 +00:00
|
|
|
# --- Setup go version
|
2020-02-28 22:39:11 +00:00
|
|
|
if [ -z "${GOPATH}" ]; then
|
|
|
|
GOPATH=$(realpath $HOME/../../../..)
|
|
|
|
echo "WARNING: Assuming GOPATH=$GOPATH"
|
|
|
|
else
|
|
|
|
echo "Using parent GOPATH=$GOPATH"
|
|
|
|
fi
|
|
|
|
|
2020-02-28 23:51:19 +00:00
|
|
|
# --- Setup basic env
|
|
|
|
cat <<EOF >/etc/profile.d/env.sh
|
2020-03-02 16:38:07 +00:00
|
|
|
export ARCH=amd64
|
2020-02-28 23:51:19 +00:00
|
|
|
export GO111MODULE=off
|
2020-03-04 15:25:40 +00:00
|
|
|
export GOPATH=$GOPATH
|
2020-02-28 23:51:19 +00:00
|
|
|
export PATH=/usr/local/bin:$PATH:/usr/local/go/bin:$GOPATH/bin
|
2020-03-04 15:25:40 +00:00
|
|
|
export HOME=$HOME && cd
|
2020-02-28 23:51:19 +00:00
|
|
|
EOF
|
|
|
|
. /etc/profile.d/env.sh
|
|
|
|
|
|
|
|
# --- Clean go cache
|
2020-02-28 22:39:11 +00:00
|
|
|
rm -rf .cache/go-build || true
|
|
|
|
|
2020-02-28 23:51:19 +00:00
|
|
|
# --- Set color prompt
|
|
|
|
sed -i 's|:/bin/ash$|:/bin/bash|g' /etc/passwd
|
2020-03-06 17:46:10 +00:00
|
|
|
cat <<\EOF >/etc/profile.d/color.sh
|
2020-02-28 23:51:19 +00:00
|
|
|
alias ls='ls --color=auto'
|
2020-03-06 17:46:10 +00:00
|
|
|
export PS1='\033[31m[ \033[90m\D{%F 🐮 %T}\033[31m ]\n\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h\[\033[35m\]:\[\033[33;1m\]\w\[\033[m\]\$ '
|
2020-02-28 23:51:19 +00:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# --- Setup install script from docker run commands
|
|
|
|
mkdir -p ${GOPATH}/bin
|
|
|
|
mkdir -p /go
|
2020-03-02 16:38:07 +00:00
|
|
|
ln -sf $GOPATH/bin /go/bin
|
2020-02-28 23:51:19 +00:00
|
|
|
sed ':a;N;$!ba;s/\\\n/ /g' <Dockerfile.dapper | grep '^RUN ' | sed -e 's/^RUN //' >/tmp/docker-run
|
|
|
|
export BINDIR=/go/bin
|
|
|
|
export GOPATH=/go
|
|
|
|
export HOME=/tmp
|
|
|
|
|
|
|
|
# --- Add k3s motd
|
|
|
|
cat <<\EOF >/etc/motd
|
|
|
|
, ,
|
|
|
|
,-----------|'------'| |\ ____
|
|
|
|
/. '-'@ o|-' | | /___ \
|
|
|
|
|/| | .. | | | __ __) | ____
|
|
|
|
| .________.'----' | |/ /|__ < / __/
|
|
|
|
| || | || | < ___) |\__ \
|
|
|
|
\__|' \__|' |_|\_\_____/____/
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2020-03-02 16:38:07 +00:00
|
|
|
# --- Utility function to download go
|
|
|
|
download_go() {
|
|
|
|
goversion=$(grep "^FROM " Dockerfile.dapper | sed -e 's/^FROM golang:\(.*\)-.*/\1/')
|
|
|
|
if [ -z "$goversion" ]; then
|
2020-03-04 15:25:40 +00:00
|
|
|
echo 'Cannot find version of go to fetch'
|
2020-03-02 16:38:07 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
echo "Installing go $goversion"
|
|
|
|
curl -sL https://storage.googleapis.com/golang/go${goversion}.linux-${ARCH}.tar.gz | tar -xzf - -C /usr/local
|
|
|
|
}
|
|
|
|
|
|
|
|
# --- Utility function to download dqlite
|
|
|
|
download_dqlite() {
|
|
|
|
dqliteURL="https://github.com/$(grep dqlite-build Dockerfile.dapper | sed -e 's/^.*--from=\([^ ]*\).*$/\1/' -e 's|:|/releases/download/|')/dqlite-$ARCH.tgz"
|
|
|
|
if [ -z "$dqliteURL" ]; then
|
2020-03-04 15:25:40 +00:00
|
|
|
echo 'Cannot find dqlite URL to fetch'
|
2020-03-02 16:38:07 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
mkdir -p /usr/src/
|
|
|
|
echo "Downloading DQLITE from $dqliteURL"
|
2020-03-06 17:46:10 +00:00
|
|
|
curl -sL $dqliteURL -o /usr/src/dqlite.tgz
|
2020-03-02 16:38:07 +00:00
|
|
|
}
|
|
|
|
|
2020-02-28 22:39:11 +00:00
|
|
|
# --- Run vagrant provision script if available
|
|
|
|
if [ ! -f "${PROVISION}" ]; then
|
2020-03-04 15:25:40 +00:00
|
|
|
echo "WARNING: Unable to execute provision script \"${PROVISION}\""
|
2020-02-28 22:39:11 +00:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
echo "running '${PROVISION}'..." && \
|
|
|
|
. ${PROVISION} && \
|
|
|
|
echo "finished '${PROVISION}'!"
|