#!/bin/sh

GRP_ID=`id -g`
USR_ID=`id -u`
# cp ~/.Xauthority .

if [ $GRP_ID -eq 1000 ]
then
    # rien a faire, tout baigne dans ce cas
    echo "/bin/bash" > fixuid.sh
elif  [ $GRP_ID -eq 0 ]
then echo "Ne pas lancer ce script en tant que root !!"; exit 2
else
    # ce script créé un utilisateur dont les id/grp correspondent à l'appelant.
    # Il est appelé par l'image jahierwan/info-pf-tools-fix
        echo "# Generated by docker-ltpf, do not edit!

sudo groupadd -g $GRP_ID ltpf2
sudo adduser -u $USR_ID --gid $GRP_ID ltpf2 --disabled-password --gecos \"\"
echo \"ltpf2:ltpf2\" | sudo chpasswd 

#


export DISPLAY=:0.0
xhost +
sudo su - ltpf2
/bin/bash

" > fixuid.sh
fi
chmod +wx fixuid.sh
docker run -v "$PWD":/current_dir -w /current_dir -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix  -it jahierwan/info-pf-tools

