Skip to content

Commit

Permalink
Minor fixes and cleanup all around // 0.1.x -> 0.9.x
Browse files Browse the repository at this point in the history
Most notably, Xming should install correctly now and no longer runs in access control disabled mode (X0.hosts configured properly)
Additionally, some minor bug fixes.

Some notes for the future:
This really really should be restructured. The checkOS method has grown to basically become the entire script and runs a lot of things before arguments are even processed.
This makes some things work in odd ways; for example: on windows ~/Documents/UAVA is created even if a custom path is specified (and also, custom paths don't work since you need to provide docker with a Windows style path but put the unix style path in the alias)
There's also a lot of repeated code/things that really should be made functions. For example, the check grep for string/if not, add routine; the download+install .exe routine; and so on.

But, those are future problems. Unless something goes very wrong or there's a compelling reason why this script needs to be cleaned up or published, I'm inclined to leave it as is for now.

Also, I fully expect (and hope) that this script will become obsolete in the near future, as bash on windows matures and docker grows to better support different platforms.

About the versions: With this commit, I'm ready to call rust-dev-env beta software. I'm bumping the version up to 0.9.5 and changing the branches to match.
I realise 0.1.x never actually made it into master, but I think that's fine.
I want 1.0.0 to be the first 'stable' release, and since I feel like we're nearing that this is going to be 0.9.5 and that's that.

I haven't been keeping up with the issues on Github so, here's where we are:
This and prior commits:
    * close #2
    * close #6
    * fix #8
    * close #9 (probably - needs macOS testing)
    * fix #10 (and then broke it again, but that's another thing)
    * fix #11
    * close #12 (probably - also needs macOS testing)
    * close #13
    * close #14 (and we even take of Docker!)
    * started #15?
    * possibly maybe took care of #16 but needs testing
    * fix #17
    * added something like #19 to the end of the install script
    * close #20
    * close #21 (there are other issues with this, but that's for a new issue)
    * close #22
    * close #23
    * close #24 (probably - needs testing; n.b: windows users are taken care of)
    * close #26
    * #27 cannot be avoided
    * fix #28
    * fix #29
    * fix #30

Finally, shout out to Steven for helping test this script on Windows. Thanks Steven! (@stevenjzhu)
  • Loading branch information
rrbutani committed Sep 28, 2017
1 parent 133f6a5 commit f695f00
Showing 1 changed file with 49 additions and 15 deletions.
64 changes: 49 additions & 15 deletions Infrastructure/rust-dev-env/install-uav-rust-dev-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
# All or nothing:
set -e

VERSION="0.9.5"

DOCKER="docker"
DEPENDENCIES=("cat grep expr whoami xargs which docker")

Expand Down Expand Up @@ -241,9 +243,9 @@ function windowsDependency_Xming

xmingWinPath=$(dos2wslPath "$(windowsCMD "echo %programfiles(x86)%")\\Xming\\Xming.exe")

# Install:
if [ -e "$xmingWinPath" ]; then
print "Xming is installed!" $GREEN
return 0
else
# Install Xming:
print "We couldn't find Xming on your computer, so we're"
Expand All @@ -265,12 +267,29 @@ function windowsDependency_Xming

sleep 3

$CMD /C "$dPathWin" /SILENT | more
$CMD /C "$dPathWin" /TYPE=full /SILENT | more

# Check if it really installed, just to be sure:
windowsDependency_Xming
return $?
fi

# Now configure:
print "Making sure Xming is configured correctly:" $PURPLE

xmingInstallDir=$(dos2wslPath "$(windowsCMD "echo %programfiles(x86)%")\\Xming")
dockerMachineIP=$(docker-machine.exe ip)

if ! grep -q "${dockerMachineIP}" "${xmingInstallDir}/X0.hosts"; then
print "Adding ${dockerMachineIP} to allowed X Hosts." $CYAN
echo "${dockerMachineIP}" >> "${xmingInstallDir}/X0.hosts"
fi

print "Launching Xming now!" $GREEN
print "If you get a Windows Firewall popup, please allow Xming through." $BOLD

sleep 1
bash -c "cd \"${xmingInstallDir}\" && ./Xming.exe :0 -clipboard -multiwindow >/dev/null 2>&1" &
}

function windowsDependency_DockerClient
Expand Down Expand Up @@ -425,7 +444,7 @@ function windows_ConfigureForDockerForWindows
done

# Add necessary things to .bashrc
PROF_TITLE="# Additions for Docker For Windows #"
PROF_TITLE="# Additions for Docker For Windows v${VERSION}#"

if grep -q "${PROF_TITLE}" "$HOME/.bashrc"; then
print ".bashrc changes already present." $PURPLE
Expand All @@ -442,6 +461,9 @@ for ((i=0; i< \${#y[@]}; i++)); do eval "\${y[\$i]}"; done
popd > /dev/null
# Change /mnt/c/ to /c/ in current working directory path
cd \$(pwd | sed 's/\/mnt\/c\//\/c\//')
PATH="\$HOME/bin:\$HOME/.local/bin:\$PATH"
PATH="\$PATH:/c/Program Files/Docker/Docker/resources/bin/"
export PATH=$PATH
EOF
fi

Expand All @@ -453,7 +475,12 @@ EOF
for ((i=0; i< ${#y[@]}; i++)); do eval "${y[$i]}"; done
popd > /dev/null

docker images
PATH="\$HOME/bin:\$HOME/.local/bin:\$PATH"
PATH="\$PATH:/c/Program Files/Docker/Docker/resources/bin/"
export PATH=$PATH

docker images > /dev/null 2>&1
return $?
}

function windows_InstallDockerToolbox
Expand Down Expand Up @@ -510,7 +537,7 @@ function windows_ConfigureForDockerToolbox
done

# Add necessary things to .bashrc
PROF_TITLE="# Additions for Docker Toolbox #"
PROF_TITLE="# Additions for Docker Toolbox v${VERSION}#"

if grep -q "${PROF_TITLE}" "$HOME/.bashrc"; then
print ".bashrc changes already present." $PURPLE
Expand All @@ -529,6 +556,9 @@ for ((i=0; i< \${#y[@]}; i++)); do eval "\${y[\$i]}"; done
popd > /dev/null
# Change /mnt/c/ to /c/ in current working directory path
cd \$(pwd | sed 's/\/mnt\/c\//\/c\//')
PATH="\$HOME/bin:\$HOME/.local/bin:\$PATH"
PATH="\$PATH:/c/Program\ Files/Docker\ Toolbox/"
export PATH=$PATH
EOF
fi

Expand All @@ -541,8 +571,11 @@ EOF
readarray -t y <<<"$arr"
for ((i=0; i< ${#y[@]}; i++)); do eval "${y[$i]}"; done
popd > /dev/null
PATH="\$HOME/bin:\$HOME/.local/bin:\$PATH"
PATH="\$PATH:/c/Program\ Files/Docker\ Toolbox/"
export PATH=$PATH

docker images
docker images > /dev/null 2>&1
return $?
}

Expand Down Expand Up @@ -674,7 +707,8 @@ function windowsDocumentsPath

# And print
print "Using ${PRJCT_DIR} as default Windows Path" $BOLD
print "(can be accessed at ${WIN_PROJ} in Windows)" $BOLD
print "(can be accessed at ${WIN_HOME}\\Documents\\" $BOLD -n
print "UAVA in Windows)" $BOLD
}

function windows
Expand Down Expand Up @@ -704,7 +738,7 @@ function windows
print "Using ${DISPLAY} as \$DISPLAY..." $PURPLE

# Continue with .bashrc additions:
PROF_TITLE="# Added automagically for Docker #"
PROF_TITLE="# Added automagically for Docker (v${VERSION})#"

if grep -q "${PROF_TITLE}" "$HOME/.bashrc"; then
print "Changes already present." $PURPLE
Expand All @@ -714,8 +748,6 @@ function windows
cat << EOF >> "$HOME/.bashrc"
${PROF_TITLE}
PATH="\$HOME/bin:\$HOME/.local/bin:\$PATH"
PATH="\$PATH:/c/Program\ Files/Docker\ Toolbox/"
export DISPLAY=:0
alias docker-machine="docker-machine.exe"
EOF
Expand Down Expand Up @@ -900,13 +932,14 @@ function installAliases
# ALIAS_FILE_LOC=${ALIAS_FILE-"~/.bash_aliases"}
print "Using ${ALIAS_FILE:="${HOME}/.bash_aliases"} as alias file."

if grep -q "# ${CNTNR_NAME} Aliases v0.1.0 #" ${ALIAS_FILE}; then
PROF_TITLE="# ${CNTNR_NAME} Aliases v${VERSION} #"
if grep -q "${PROF_TITLE}" ${ALIAS_FILE}; then
print "Aliases already installed." $PURPLE
return $?
fi

cat << EOF >> "${ALIAS_FILE}"
# ${CNTNR_NAME} Aliases v0.1.0 #
${PROF_TITLE}
alias uava='cd "${PRJCT_DIR}"'
alias uavai='docker exec -it ${CNTNR_NAME} bash -c "intellij-idea-community"'
alias uavas='docker exec -it ${CNTNR_NAME} bash -c "subl"'
Expand Down Expand Up @@ -935,7 +968,8 @@ EOF
cat << EOF >> "${ALIAS_FILE}"
function uavaS
{
\$("${CMD}" /C "$(windowsCMD "echo %programfiles(x86)%")\\Xming\\Xming.exe" :0 -clipboard -multiwindow -ac >nul 2>&1) &
xmingInstallDir="$(dos2wslPath "$(windowsCMD "echo %programfiles(x86)%")\\Xming")"
bash -c "cd \"\${xmingInstallDir}\" && ./Xming.exe :0 -clipboard -multiwindow >/dev/null 2>&1" &
docker start ${CNTNR_NAME}
}
alias uavaE='docker stop ${CNTNR_NAME} -t 1'
Expand Down Expand Up @@ -993,10 +1027,10 @@ trap emergencyExit SIGINT SIGTERM

#Notes:
# It's actually possible to automate the WSL installation, but I don't want to do this.
# (https://github.com/xezpeleta/bowinstaller)
# (https://github.com/xezpeleta/bowinstaller) (nvm, this is broken)

##########################
# AUTHOR: Rahul Butani #
# DATE: Sept 26, 2017 #
# VERSION: 0.9.3 #
# VERSION: 0.9.5 #
##########################

0 comments on commit f695f00

Please sign in to comment.