initvagrant.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/bin/bash
  2. echo "---------- $0 start ----------"
  3. # this script is run by the root user in the virtual machine
  4. set -e
  5. set -x
  6. who=$(whoami)
  7. echo "Initial setup of SITL-vagrant instance."
  8. if [ $who != 'root' ]; then
  9. echo "SORRY, MUST RUN THIS SCRIPT AS ROOT, GIVING UP"
  10. exit 1
  11. fi
  12. VAGRANT_USER=ubuntu
  13. if [ -e /home/vagrant ]; then
  14. # prefer vagrant user
  15. VAGRANT_USER=vagrant
  16. fi
  17. echo USING VAGRANT_USER:$VAGRANT_USER
  18. cd /home/$VAGRANT_USER
  19. # artful rootfs is 2GB without resize:
  20. resize2fs /dev/sda1
  21. apt-get update
  22. apt-get install -y python3-pip
  23. pip3 install flask
  24. apt-get install -y apache2
  25. apt-get install -y libapache2-mod-wsgi-py3 python-dev
  26. CUSTOM_CONF="/etc/apache2/sites-available//CustomBuild.conf"
  27. #cp /vagrant/CustomBuild.conf "$CUSTOM_CONF"
  28. #perl -pe 's%/home/custom/CustomBuild%/vagrant%' -i "$CUSTOM_CONF"
  29. sudo -H -u $VAGRANT_USER mkdir -p /home/vagrant/base/builds
  30. # TODO: work out how to do custom certs here
  31. cat >"$CUSTOM_CONF" <<EOF
  32. <VirtualHost *:8888>
  33. # ServerName custom.ardupilot.org
  34. WSGIDaemonProcess app threads=5
  35. WSGIScriptAlias / /vagrant/app.wsgi
  36. WSGIScriptAlias /generate /vagrant/app.wsgi
  37. <Directory /vagrant/>
  38. Options FollowSymLinks
  39. AllowOverride None
  40. Require all granted
  41. </Directory>
  42. Alias /builds /base/builds
  43. <Directory /base/>
  44. Options FollowSymLinks Indexes
  45. AllowOverride None
  46. Require all granted
  47. </Directory>
  48. ErrorLog \${APACHE_LOG_DIR}/error.log
  49. LogLevel warn
  50. CustomLog \${APACHE_LOG_DIR}/access.log combined
  51. </VirtualHost>
  52. EOF
  53. # add the arm tools into the path for Apache:
  54. cat >>/etc/apache2/envvars <<EOF
  55. export PATH=/opt/gcc-arm-none-eabi-10-2020-q4-major/bin:\$PATH
  56. EOF
  57. cp /vagrant/app.wsgi /etc/apache2/sites-available/
  58. a2ensite CustomBuild.conf
  59. a2dissite 000-default
  60. cat >>/etc/apache2/ports.conf <<EOF
  61. Listen 8888
  62. EOF
  63. for PKG in empy future ; do
  64. pip install --upgrade $PKG
  65. done
  66. systemctl reload apache2
  67. # apache isn't run as root, so can't run app as vagrant user.
  68. USER=www-data
  69. GROUP=www-data
  70. # create and change permissions of /base - need to work out how to
  71. # effectively pass in --basedir to the WSGI at some stage
  72. for DIR in /base /base/builds /base/tmp; do
  73. mkdir $DIR
  74. chown $USER.$GROUP $DIR
  75. chmod 777 $DIR # TODO: tidy permissions
  76. done
  77. cd /base
  78. sudo -H -u $USER ln -s /home//vagrant/ardupilot /base/ardupilot
  79. pushd /home/$VAGRANT_USER
  80. if [ ! -e ardupilot ]; then
  81. sudo -H -u $VAGRANT_USER git clone --recursive https://github.com/ardupilot/ardupilot
  82. fi
  83. pushd ardupilot
  84. sudo -u $VAGRANT_USER ./Tools/environment_install/install-prereqs-ubuntu.sh -y
  85. popd
  86. chown -R $USER.$GROUP ardupilot
  87. popd
  88. systemctl stop apache2 && systemctl start apache2
  89. # enable permissive ptrace:
  90. perl -pe 's/kernel.yama.ptrace_scope = ./kernel.yama.ptrace_scope = 0/' -i /etc/sysctl.d/10-ptrace.conf
  91. echo 0 > /proc/sys/kernel/yama/ptrace_scope
  92. # the 8888 here comes from Vagrantfile, it's a forwarded port
  93. echo "Check web address: http://127.0.0.1:8888/"
  94. # Now you can run
  95. # vagrant ssh -c "screen -d -R"
  96. echo "---------- $0 end ----------"