#!/usr/bin/bash

# Remove deprecated flags and adjust exported desktop names for compatibility.
if [ -f /usr/bin/distrobox-enter ]; then
    sed -i '/log_timestamp/s/-u //' /usr/bin/distrobox-enter
fi
# Keep `${container_name}` literal inside sed because we are editing script text,
# not expanding a shell variable at runtime here.
# shellcheck disable=SC2016
if [ -f /usr/bin/distrobox-export ]; then
    sed -i '/desktop_home_file=/s/${container_name}-//' /usr/bin/distrobox-export
fi

# Ensure distrobox global config directory exists.
if [ ! -d "/etc/distrobox/" ]; then
  mkdir -p /etc/distrobox/
fi

# Provide a default image only when the admin has not set one yet.
if [ ! -e "/etc/distrobox/distrobox.conf" ]; then
  echo 'container_image_default=xivastudio/biglinux-archlinux:latest' > /etc/distrobox/distrobox.conf
fi
