File indexing completed on 2024-04-28 05:13:32
0001 #!/bin/sh 0002 0003 if [ $(id -u) -eq 0 ]; then 0004 echo "Don't run this script as root" 0005 exit 1 0006 fi 0007 0008 docker_exe="docker" 0009 qt_version=5 0010 0011 usage() 0012 { 0013 echo "Usage: $0 [-n] [-q VERSION ] container | directory" 0014 echo " -n Use nvidia-docker instead of docker executable (see README for details)" 0015 echo " -q Set the QT version that should be supported in image (default 5)" 0016 echo " container An existing development container name." 0017 echo " See 'docker ps -a'." 0018 echo " directory Location to use for a new development container." 0019 echo " Final path component will be the container name." 0020 exit 1 0021 } 0022 0023 while getopts "naq:" o; do 0024 case "${o}" in 0025 n) 0026 docker_exe="nvidia-docker" 0027 ;; 0028 q) 0029 qt_version="$OPTARG" 0030 ;; 0031 a) 0032 attach=true 0033 ;; 0034 *) 0035 usage 0036 ;; 0037 esac 0038 done 0039 shift $((OPTIND-1)) 0040 0041 if [ "$qt_version" = "6" ]; then 0042 base_image="kdepim:qt6-dev" 0043 else 0044 base_image="kdepim:dev" 0045 fi 0046 0047 if [ -z $1 ]; then 0048 usage 0049 fi 0050 0051 container_name=`basename $1` 0052 0053 # Is kdepim-dev already running? 0054 num=$(${docker_exe} ps -f name=${container_name} | wc -l) 0055 if [ ${num} -eq 2 ]; then 0056 if [ "${attach}" = true ]; then 0057 # Attach to it 0058 ${docker_exe} attach ${container_name} 0059 else 0060 ${docker_exe} exec -it -u neon ${container_name} bash 0061 fi 0062 else 0063 # Just stopped? 0064 num=$(${docker_exe} ps -a -f name=${container_name} | wc -l) 0065 if [ ${num} -eq 2 ]; then 0066 # Start it and attach to it 0067 ${docker_exe} start -ai ${container_name} 0068 elif [ ! -d $1 -o ! -w $1 ]; then 0069 echo "$1 is not a container name or a writable directory" 0070 exit 1 0071 else 0072 # Create a new container from the kdepim:dev image 0073 # using directory $1 for repository check-outs. 0074 user=$(id -u) 0075 args="-e DISPLAY \ 0076 -e ICECC_SERVER \ 0077 -e WAYLAND_DISPLAY \ 0078 -e XDG_SESSION_TYPE \ 0079 -v /tmp/.X11-unix:/tmp/.X11-unix:rw,z \ 0080 -v $XDG_RUNTIME_DIR/pulse:$XDG_RUNTIME_DIR/pulse:rw,z \ 0081 -v $1:/home/neon/kdepim:rw,z" 0082 0083 if [ ! -z "$WAYLAND_DISPLAY" ] && [ -e $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY ]; then 0084 args="${args} \ 0085 -v $XDG_RUNTIME_DIR/$WAYLAND_DISPLAY:$XDG_RUNTIME_DIR/$WAYLAND_DISPLAY" 0086 fi 0087 ${docker_exe} run \ 0088 -ti \ 0089 ${args} \ 0090 --user=$(id -u):$(id -g) \ 0091 --privileged \ 0092 --name ${container_name} \ 0093 ${base_image} 0094 fi 0095 fi