From fc2b792ae002dd4d1caa3b2ad5f82a5e365a0272 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 13 Jan 2015 22:31:50 -0500 Subject: [PATCH] Minor bootstrap.sh changes --- bootstrap.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/bootstrap.sh b/bootstrap.sh index 242ec57..4a94a04 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,12 +1,20 @@ #!/bin/bash +# If the script was not run as root +if [ "$(id -u)" != "0" ]; then + echo "Switching to root..." + sudo /vagrant/bootstrap.sh + exit +fi # Download wpilib from github if the folder doesn't already exist (test -d /vagrant/wpilib||(mkdir /vagrant/wpilib;curl -sL https://github.com/stonewareslord/wpilib/tarball/master | tar -xzC /vagrant/wpilib --strip-components=1))& # Create the build folder if it doesn't already exist mkdir -p /vagrant/build /vagrant/src -# Install the frc toolchain -add-apt-repository -y ppa:byteit101/frc-toolchain -apt-get update -apt-get install -y frc-toolchain +# Install the frc toolchain if it isn't installed already +dpkg -s frc-toolchain 2>&1 >/dev/null || { + add-apt-repository -y ppa:byteit101/frc-toolchain + apt-get update + apt-get install -y frc-toolchain +} # Compiles code in the /vagrant/src folder echo "echo 'Starting build';(test -d /vagrant/src/Debug&&test -f /vagrant/src/Debug/makefile&&(cd /vagrant/src/Debug/&&make -f makefile clean;make -f makefile;cd -))||(test -f /vagrant/build/FRCUserProgram&&rm /vagrant/build/FRCUserProgram;test -f \`cat /vagrant/config/buildfile|head -n 1\`&&(arm-frc-linux-gnueabi-g++ -std=c++1y -I/vagrant/wpilib/include '-I/vagrant/src' -O0 -g3 -Wall -c -fmessage-length=0 -o /vagrant/build/Robot.o /vagrant/src/\`cat /vagrant/config/buildfile|head -n 1\`&&arm-frc-linux-gnueabi-g++ -L/vagrant/wpilib/lib -Wl,-rpath,/opt/GenICam_v2_3/bin/Linux_armv7-a -o /vagrant/build/FRCUserProgram /vagrant/build/Robot.o -lwpi;rm /vagrant/build/Robot.o))||(/vagrant/compile.sh);echo 'Done'" > /usr/local/bin/build # Uploads the code to the rRIO based on /vagrant/config/host file @@ -14,4 +22,8 @@ echo "cat /vagrant/build/FRCUserProgram | ssh \`cat /vagrant/config/host|head -n # Creates ssh key if it doesn't exist and cats the public key to the rRIO echo "test -d ~/.ssh||mkdir ~/.ssh;test -f ~/.ssh/id_rsa||ssh-keygen -t rsa -f ~/.ssh/id_rsa -b 4096 -q -N '';cat ~/.ssh/id_rsa.pub|ssh \`cat /vagrant/config/host|head -n 1\` 'cat >> /tmp/key;mkdir -p ~/.ssh;cat /tmp/key >> ~/.ssh/authorized_keys;rm /tmp/key'" > /usr/local/bin/putkey chmod +x /usr/local/bin/build /usr/local/bin/deploy /usr/local/bin/putkey -echo "Done provisioning. Run vagrant ssh to connect to the virtual machine." +echo "Done provisioning. " +# If provisioned from Vagrant +if [ $(cd "$(dirname "$0")"; pwd) != "/vagrant" ]; then + echo "Run 'vagrant ssh' to connect to the virtual machine" +fi