#!/bin/bash
# Elevate script
if [ ! "$UID" -eq 0 ]
then
    sudo bash "$BASH_SOURCE";
else
    contextRoot="$(mktemp -d)";
    pushd "$contextRoot" > /dev/null;

    # Preview from docker container
    # container_id="$(docker create woodpeckerci/woodpecker-cli:next)"
    # docker cp $container_id:/bin/woodpecker-cli /usr/local/bin/woodpecker-cli

    # Latest from GitHub
    wget https://github.com/woodpecker-ci/woodpecker/releases/download/v0.15.5/woodpecker-cli_linux_amd64.tar.gz \
        -O woodpecker-cli.tar.gz;

    tar -xvzf woodpecker-cli.tar.gz;
    install woodpecker-cli /usr/local/bin;

    popd > /dev/null;
    rm -rf "$contextRoot";
fi