diff --git a/bin/app b/bin/app index 43bb5a9..d88d4fd 100644 --- a/bin/app +++ b/bin/app @@ -1,4 +1,18 @@ -DIR=`pwd` -cd /opt/docker/images/$1/ -bin/app "$2" -cd $DIR \ No newline at end of file +DIR=`dirname $0` +DIR=`readlink -e $DIR` +BASE=`basename $DIR` +IFS='/' read -ra ADDR <<< "$DIR" +CONTAINER=${ADDR[-2]} +while : ; do + ID=`docker ps --no-trunc | grep $CONTAINER: | cut -d' ' -f1` + if [ -n "$ID" ]; then + break + fi + if [ ! -n "$STARTED" ]; then + echo "Starting container." + /opt/docker/bin/run $CONTAINER & + STARTED=yes + sleep 10 + fi +done +/opt/docker/bin/ssh $CONTAINER $1 "source .profile; /opt/$CONTAINER" diff --git a/bin/ssh b/bin/ssh index e3552cf..71845a8 100644 --- a/bin/ssh +++ b/bin/ssh @@ -1,4 +1,23 @@ -DIR=`pwd` -cd /opt/docker/images/$1/ -bin/ssh "$2" "$3" -cd $DIR \ No newline at end of file +DIR=`dirname $0` +DIR=`readlink -e $DIR` +BASE=`basename $DIR` +IFS='/' read -ra ADDR <<< "$DIR" +CONTAINER=${ADDR[-2]} +ID=`docker ps --no-trunc | grep $CONTAINER: | cut -d' ' -f1` +if [ -n "$ID" ]; then + IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' $ID` + COMMAND="ssh -X -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i id_rsa $ARGS root@$IP" + if [ ! -e id_rsa ]; then + docker cp $ID:/opt/id_rsa . + fi + if [ ! -z "$1" ] && [ "$1" == "-l" ]; then + DISPLAY=:0 + chmod 0666 id_rsa + su user -c "$COMMAND \"$2\"" + else + chmod 0600 id_rsa + eval "$COMMAND \"$1\"" + fi +else + echo "Container is not running." +fi \ No newline at end of file diff --git a/build/bin/app b/build/bin/app deleted file mode 100644 index d88d4fd..0000000 --- a/build/bin/app +++ /dev/null @@ -1,18 +0,0 @@ -DIR=`dirname $0` -DIR=`readlink -e $DIR` -BASE=`basename $DIR` -IFS='/' read -ra ADDR <<< "$DIR" -CONTAINER=${ADDR[-2]} -while : ; do - ID=`docker ps --no-trunc | grep $CONTAINER: | cut -d' ' -f1` - if [ -n "$ID" ]; then - break - fi - if [ ! -n "$STARTED" ]; then - echo "Starting container." - /opt/docker/bin/run $CONTAINER & - STARTED=yes - sleep 10 - fi -done -/opt/docker/bin/ssh $CONTAINER $1 "source .profile; /opt/$CONTAINER" diff --git a/build/bin/run b/build/bin/run deleted file mode 100644 index 18a8ad4..0000000 --- a/build/bin/run +++ /dev/null @@ -1,6 +0,0 @@ -DIR=`dirname $0` -DIR=`readlink -e $DIR` -BASE=`basename $DIR` -IFS='/' read -ra ADDR <<< "$DIR" -CONTAINER=${ADDR[-2]} -/opt/docker/bin/run -t $CONTAINER "$ARGS" $1 "$2" diff --git a/build/bin/ssh b/build/bin/ssh deleted file mode 100644 index 71845a8..0000000 --- a/build/bin/ssh +++ /dev/null @@ -1,23 +0,0 @@ -DIR=`dirname $0` -DIR=`readlink -e $DIR` -BASE=`basename $DIR` -IFS='/' read -ra ADDR <<< "$DIR" -CONTAINER=${ADDR[-2]} -ID=`docker ps --no-trunc | grep $CONTAINER: | cut -d' ' -f1` -if [ -n "$ID" ]; then - IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' $ID` - COMMAND="ssh -X -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i id_rsa $ARGS root@$IP" - if [ ! -e id_rsa ]; then - docker cp $ID:/opt/id_rsa . - fi - if [ ! -z "$1" ] && [ "$1" == "-l" ]; then - DISPLAY=:0 - chmod 0666 id_rsa - su user -c "$COMMAND \"$2\"" - else - chmod 0600 id_rsa - eval "$COMMAND \"$1\"" - fi -else - echo "Container is not running." -fi \ No newline at end of file