launch_chffrplus.sh 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/bash
  2. if [ -z "$BASEDIR" ]; then
  3. BASEDIR="/data/openpilot"
  4. fi
  5. source "$BASEDIR/launch_env.sh"
  6. DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
  7. function agnos_init {
  8. # TODO: move this to agnos
  9. sudo rm -f /data/etc/NetworkManager/system-connections/*.nmmeta
  10. # set success flag for current boot slot
  11. sudo abctl --set_success
  12. # TODO: do this without udev in AGNOS
  13. # udev does this, but sometimes we startup faster
  14. sudo chgrp gpu /dev/adsprpc-smd /dev/ion /dev/kgsl-3d0
  15. sudo chmod 660 /dev/adsprpc-smd /dev/ion /dev/kgsl-3d0
  16. # Check if AGNOS update is required
  17. if [ $(< /VERSION) != "$AGNOS_VERSION" ]; then
  18. AGNOS_PY="$DIR/system/hardware/tici/agnos.py"
  19. MANIFEST="$DIR/system/hardware/tici/agnos.json"
  20. if $AGNOS_PY --verify $MANIFEST; then
  21. sudo reboot
  22. fi
  23. $DIR/system/hardware/tici/updater $AGNOS_PY $MANIFEST
  24. fi
  25. }
  26. function launch {
  27. # Remove orphaned git lock if it exists on boot
  28. [ -f "$DIR/.git/index.lock" ] && rm -f $DIR/.git/index.lock
  29. # Check to see if there's a valid overlay-based update available. Conditions
  30. # are as follows:
  31. #
  32. # 1. The BASEDIR init file has to exist, with a newer modtime than anything in
  33. # the BASEDIR Git repo. This checks for local development work or the user
  34. # switching branches/forks, which should not be overwritten.
  35. # 2. The FINALIZED consistent file has to exist, indicating there's an update
  36. # that completed successfully and synced to disk.
  37. if [ -f "${BASEDIR}/.overlay_init" ]; then
  38. find ${BASEDIR}/.git -newer ${BASEDIR}/.overlay_init | grep -q '.' 2> /dev/null
  39. if [ $? -eq 0 ]; then
  40. echo "${BASEDIR} has been modified, skipping overlay update installation"
  41. else
  42. if [ -f "${STAGING_ROOT}/finalized/.overlay_consistent" ]; then
  43. if [ ! -d /data/safe_staging/old_openpilot ]; then
  44. echo "Valid overlay update found, installing"
  45. LAUNCHER_LOCATION="${BASH_SOURCE[0]}"
  46. mv $BASEDIR /data/safe_staging/old_openpilot
  47. mv "${STAGING_ROOT}/finalized" $BASEDIR
  48. cd $BASEDIR
  49. echo "Restarting launch script ${LAUNCHER_LOCATION}"
  50. unset AGNOS_VERSION
  51. exec "${LAUNCHER_LOCATION}"
  52. else
  53. echo "openpilot backup found, not updating"
  54. # TODO: restore backup? This means the updater didn't start after swapping
  55. fi
  56. fi
  57. fi
  58. fi
  59. # handle pythonpath
  60. ln -sfn $(pwd) /data/pythonpath
  61. export PYTHONPATH="$PWD"
  62. # hardware specific init
  63. if [ -f /AGNOS ]; then
  64. agnos_init
  65. fi
  66. # write tmux scrollback to a file
  67. tmux capture-pane -pq -S-1000 > /tmp/launch_log
  68. # start manager
  69. cd system/manager
  70. if [ ! -f $DIR/prebuilt ]; then
  71. ./build.py
  72. fi
  73. ./manager.py
  74. # if broken, keep on screen error
  75. while true; do sleep 1; done
  76. }
  77. launch