2019-10-24 00:44:01 +00:00
#!/bin/bash
set -eo pipefail
__dirname = $( cd $( dirname " $0 " ) ; pwd -P)
cd " ${ __dirname } "
if [ " $1 " = "--setup" ] ; then
export HOME = /home/$2
if [ ! -f .setupdevenv ] ; then
echo "Recompiling environment... this might take a while."
2020-11-08 21:43:19 +00:00
bash configure.sh reinstall
2019-10-24 00:44:01 +00:00
touch .setupdevenv
2020-11-30 19:01:17 +00:00
apt update && apt install -y vim git
2020-09-09 19:24:26 +00:00
chown -R $3 :$4 /code
chown -R $3 :$4 /var/www
2019-10-24 00:44:01 +00:00
fi
2019-10-24 20:07:19 +00:00
echo " Adding $2 to /etc/passwd "
echo " $2 :x: $3 : $4 ::/home/ $2 :/bin/bash " >> /etc/passwd
echo " Adding $2 to /etc/group "
echo " $2 :x: $4 : " >> /etc/group
2020-11-08 16:07:49 +00:00
echo " Adding $2 to /etc/shadow "
echo " $2 :x:14871:::::: " >> /etc/shadow
2020-11-30 19:01:17 +00:00
echo " $2 ALL=(ALL) NOPASSWD:ALL " >> /etc/sudoers
2021-10-22 17:03:48 +00:00
echo "odm ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
2019-10-24 01:06:34 +00:00
echo "echo '' && echo '' && echo '' && echo '###################################' && echo 'ODM Dev Environment Ready. Hack on!' && echo '###################################' && echo '' && cd /code" > $HOME /.bashrc
2019-10-24 00:44:01 +00:00
# Install qt creator
if hash qtcreator 2>/dev/null; then
has_qtcreator = "YES"
fi
if [ " $has_qtcreator " != "YES" ] && [ " $5 " = = "YES" ] ; then
apt install -y libxrender1 gdb qtcreator
fi
# Install liquidprompt
if [ ! -e " $HOME /liquidprompt " ] ; then
git clone https://github.com/nojhan/liquidprompt.git --depth 1 $HOME /liquidprompt
fi
if [ -e " $HOME /liquidprompt " ] ; then
echo " source $HOME /liquidprompt/liquidprompt " >> $HOME /.bashrc
2019-10-24 20:07:19 +00:00
echo "export LP_PS1_PREFIX='(odmdev)'" >> $HOME /.bashrc
2019-10-24 00:44:01 +00:00
fi
# Colors
echo "alias ls='ls --color=auto'" >> $HOME /.bashrc
2020-09-09 19:24:26 +00:00
# Python paths
2020-11-08 16:07:49 +00:00
echo $( python3 /code/opendm/context.py) >> $HOME /.bashrc
2020-10-26 20:46:46 +00:00
# Vim
printf "syntax on\nset showmatch\nset ts=4\nset sts=4\nset sw=4\nset autoindent\nset smartindent\nset smarttab\nset expandtab" > $HOME /.vimrc
2020-09-09 19:24:26 +00:00
2020-09-16 13:53:06 +00:00
# Misc aliases
echo "alias pdal=/code/SuperBuild/install/bin/pdal" >> $HOME /.bashrc
2021-07-03 12:57:37 +00:00
echo "alias opensfm=/code/SuperBuild/install/bin/opensfm/bin/opensfm" >> $HOME /.bashrc
2020-10-23 19:57:16 +00:00
2020-09-16 13:53:06 +00:00
2020-09-09 19:24:26 +00:00
su -c bash $2
2019-10-24 00:44:01 +00:00
exit 0
fi
platform = "Linux" # Assumed
uname = $( uname)
case $uname in
"Darwin" )
2023-06-12 19:12:13 +00:00
platform = "MacOS"
2019-10-24 00:44:01 +00:00
; ;
MINGW*)
platform = "Windows"
; ;
esac
2023-06-12 19:12:13 +00:00
if [ [ $platform != "Linux" && $platform != "MacOS" ] ] ; then
2023-06-12 19:24:17 +00:00
echo "This script only works on Linux and MacOS."
2019-10-24 00:44:01 +00:00
exit 1
fi
if hash docker 2>/dev/null; then
has_docker = "YES"
fi
2021-10-22 17:03:48 +00:00
if hash nvidia-smi 2>/dev/null; then
has_nvidia_smi = "YES"
fi
2019-10-24 00:44:01 +00:00
if [ " $has_docker " != "YES" ] ; then
echo "You need to install docker before running this script."
exit 1
fi
2021-10-22 17:03:48 +00:00
IMAGE_SET = NO
if [ [ ! -z $IMAGE ] ] ; then
IMAGE_SET = YES
fi
2019-10-24 00:44:01 +00:00
export PORT = " ${ PORT : =3000 } "
export QTC = " ${ QTC : =NO } "
2020-09-09 16:10:24 +00:00
export IMAGE = " ${ IMAGE : =opendronemap/nodeodm } "
2021-02-09 17:14:05 +00:00
export GPU = " ${ GPU : =NO } "
2019-10-24 00:44:01 +00:00
if [ -z " $DATA " ] ; then
echo " Usage: DATA=/path/to/datasets [VARS] $0 "
echo
echo "VARS:"
echo " DATA Path to directory that contains datasets for testing. The directory will be mounted in /datasets. If you don't have any, simply set it to a folder outside the ODM repository."
echo " PORT Port to expose for NodeODM (default: $PORT ) "
2020-09-09 16:10:24 +00:00
echo " IMAGE Docker image to use (default: $IMAGE ) "
2021-02-09 17:14:05 +00:00
echo " GPU Enable GPU support (default: $GPU ) "
2019-10-24 00:44:01 +00:00
echo " QTC When set to YES, installs QT Creator for C++ development (default: $QTC ) "
exit 1
fi
echo "Starting development environment..."
echo " Datasets path: $DATA "
2020-09-09 16:10:24 +00:00
echo " Expose port: $PORT "
2019-10-24 00:44:01 +00:00
echo " QT Creator: $QTC "
2020-09-09 16:10:24 +00:00
echo " Image: $IMAGE "
2021-02-09 17:14:05 +00:00
echo " GPU: $GPU "
2019-10-24 00:44:01 +00:00
if [ ! -e " $HOME " /.odm-dev-home ] ; then
mkdir -p " $HOME " /.odm-dev-home
fi
USER_ID = $( id -u)
GROUP_ID = $( id -g)
USER = $( id -un)
2021-10-22 17:03:48 +00:00
GPU_FLAGS = ""
2021-02-09 17:14:05 +00:00
if [ [ " $GPU " != "NO" ] ] ; then
2021-10-22 17:03:48 +00:00
if [ [ " $IMAGE_SET " = "NO" ] ] ; then
IMAGE = " $IMAGE :gpu "
fi
GPU_FLAGS = "--gpus all"
if [ [ " $has_nvidia_smi " = "YES" ] ] ; then
GPU_FLAGS = " $GPU_FLAGS --device /dev/nvidia0 --device /dev/nvidia-uvm --device /dev/nvidia-uvm-tools --device /dev/nvidia-modeset --device /dev/nvidiactl "
fi
2021-02-09 17:14:05 +00:00
fi
2020-10-26 14:40:32 +00:00
xhost + || true
2021-10-22 17:03:48 +00:00
docker run -ti --entrypoint bash --name odmdev --user root -v $( pwd ) :/code -v " $DATA " :/datasets -p $PORT :3000 $GPU_FLAGS --privileged -e DISPLAY -e LANG = C.UTF-8 -e LC_ALL = C.UTF-8 -v= "/tmp/.X11-unix:/tmp/.X11-unix:rw" -v= " $HOME /.odm-dev-home:/home/ $USER " $IMAGE -c " /code/start-dev-env.sh --setup $USER $USER_ID $GROUP_ID $QTC "
2020-09-14 14:04:26 +00:00
exit 0