fetch_releases_cronjob.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # this script is intended to be run from a crontab owned by the
  3. # www-data user on ArduPilot's autotest server
  4. # CBS_REMOTES_RELOAD_TOKEN can be supplied as an environment
  5. # variable in the crontab line, for example:
  6. # 0 * * * * CBS_REMOTES_RELOAD_TOKEN=8d64ed06945 /home/custom/beta/CustomBuild/scripts/fetch_release_cronjob.sh
  7. # or can be read from base/secrets/reload_token (the token from the file gets the preference)
  8. CUSTOM_HOME=/home/custom
  9. TOPDIR=$CUSTOM_HOME/beta
  10. LOGDIR=$TOPDIR/cron
  11. BASEDIR=$TOPDIR/base
  12. # Maximum number of log files to retain
  13. MAX_LOG_FILES=50
  14. # Get the current timestamp
  15. TIMESTAMP=$(date +"%Y%m%d_%H%M%S")
  16. # Function to clean up old log files
  17. cleanup_old_logs() {
  18. # Find and sort log files by modification time, oldest first
  19. LOG_FILES=($(ls -1t ${LOGDIR}/fetch_releases_*.log 2>/dev/null))
  20. # Count the number of log files
  21. NUM_LOG_FILES=${#LOG_FILES[@]}
  22. # If the number of log files is greater than the maximum allowed
  23. if [ $NUM_LOG_FILES -gt $MAX_LOG_FILES ]; then
  24. # Loop through and delete the oldest files
  25. for ((i = $MAX_LOG_FILES ; i < $NUM_LOG_FILES ; i++ )); do
  26. rm -f "${LOG_FILES[$i]}"
  27. done
  28. fi
  29. }
  30. # Call the cleanup function before executing the main script
  31. cleanup_old_logs
  32. # Run fetch_releases.py to add official releases from AP
  33. python3 $TOPDIR/CustomBuild/scripts/fetch_releases.py \
  34. --appurl https://custom-beta.ardupilot.org/refresh_remotes \
  35. --basedir $BASEDIR \
  36. >> $LOGDIR/fetch_releases_${TIMESTAMP}.log 2>&1
  37. # Run fetch_whitelisted_tags.py to add tags from whitelisted repos
  38. python3 $TOPDIR/CustomBuild/scripts/fetch_whitelisted_tags.py \
  39. --basedir $BASEDIR \
  40. >> $LOGDIR/fetch_whitelisted_tags_${TIMESTAMP}.log 2>&1