#!/usr/bin/env fish

# Extend the container in mullvadvpn-app with some useful dev tools and run it.

cd $HOME/proj/mullvadvpn-app

set base_tag (cat building/android-container-image.txt)
set custom_tag "$base_tag-extra"

# check if image exists
if not podman image inspect $custom_tag >/dev/null
    echo "Building custom image"
    set tmp_dockerfile (mktemp)
    echo "
FROM $base_tag

RUN apt-get update -y && apt-get upgrade -y && apt-get install -y \
    fish \
    procps

# cargo-binstall
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash

RUN cargo binstall bacon cargo-watch zoxide starship exa


RUN curl -L --proto '=https' -sSf https://git.nubo.sh/hulthe/df/raw/branch/master/manager/setup.sh | bash

RUN tee /entrypoint.sh <<EOF
#!/bin/bash
(cd ~/.config/dotfiles && git pull && dotfiles)

exec \"\\\$@\"
EOF

RUN chmod +x /entrypoint.sh

ENTRYPOINT [\"/entrypoint.sh\"]

" >$tmp_dockerfile

    podman build -f $tmp_dockerfile -t $custom_tag || exit 1
    rm $tmp_dockerfile
end

podman run --rm -it \
    --hostname mullpod \
    -v .:/build \
    -v cargo-target:/cargo-target:Z \
    -v cargo-registry:/root/.cargo/registry:Z \
    -v gradle-cache:/root/.gradle:Z \
    $custom_tag fish
