You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

101 lines
3.5 KiB

  1. #!/bin/bash
  2. ### Run as a normal user
  3. if [ $EUID -eq 0 ]; then
  4. echo "This script shouldn't be run as root."
  5. exit 1
  6. fi
  7. ## import common lib
  8. . "$HOME/.noaa.conf"
  9. . "$HOME/.tweepy.conf"
  10. . "$NOAA_HOME/common.sh"
  11. # Free disk space
  12. FREE_DISK="$(df | grep "/dev/root" | awk {'print $3'})"
  13. # This is the original path where images were stored
  14. BASEPATH="/var/www/wx/image"
  15. # Size of the old images folder
  16. IMAGEPATH_SIZE="$(du -s $BASEPATH | awk {'print $1'})"
  17. SPACE_NEEDED="$((IMAGEPATH_SIZE * 2))"
  18. if [ "$SPACE_NEEDED" -gt "$FREE_DISK" ]; then
  19. echo "You need more free space"
  20. exit 1
  21. fi
  22. # This is the destination path (AKA the new path)
  23. FINALPATH="/var/www/wx/images"
  24. # This is a list of satellite names
  25. SAT_NAMES="NOAA15 NOAA18 NOAA19 METEOR-M2"
  26. # Here's where the database will live
  27. DB_PATH="${NOAA_HOME}/panel.db"
  28. (
  29. # To speed up the migration process and
  30. # reduce the SD card wear, the database
  31. # operations are done over the RAMFS
  32. # partition
  33. cd "${RAMFS_AUDIO}" || exit 1
  34. sqlite3 "$DB_PATH" < "${NOAA_HOME}/templates/webpanel_schema.sql"
  35. )
  36. cd "$BASEPATH" || exit 1
  37. # The webpanel have thumbnails!
  38. mkdir -p "$FINALPATH/thumb"
  39. # Find all the images
  40. for filename in $(find . -name *.jpg); do
  41. # Grab just the filename without the yyyy/mm/dd path
  42. basename="$(echo "$filename" | sed 's~.*/~~')"
  43. for prefix in $SAT_NAMES; do
  44. basedate="$(echo "$basename" | sed -e "s/^$prefix//" | cut -f1,2 -d'-' | sed -e "s/-//")"
  45. if [[ $basename == *"$prefix"* ]]; then
  46. # Grab the satellite name from the file name
  47. sat_name=$prefix
  48. fi
  49. done
  50. date_normalized=$(echo "$basedate" | sed -e "s/^$sat_name//;s/./&:/12;s/./&:/10;s/./& /8;s/./&\//6;s/./&\//4")
  51. epoch_date=$(date "+%s" -d "$date_normalized")
  52. if [[ $basename == *"METEOR"* ]]; then
  53. # Meteor files have one more dash on its name
  54. passname=$(echo "$basename" | cut -f1,2,3 -d'-')
  55. else
  56. passname=$(echo "$basename" | cut -f1,2 -d'-')
  57. fi
  58. echo "Migration in progress: $basename"
  59. cp "$BASEPATH/$filename" "$FINALPATH"
  60. # Create thumbnails for old images
  61. convert -thumbnail 300 "$BASEPATH/$filename" "$FINALPATH/thumb/$basename"
  62. if [[ $basename == *"METEOR"* ]]; then
  63. # Insert each pass on the database. Also insert the pass prediction
  64. sqlite3 "${RAMFS_AUDIO}/panel.db" "INSERT INTO decoded_passes (pass_start, file_path, daylight_pass, is_noaa) VALUES ($epoch_date,\"$passname\",1,0);"
  65. sqlite3 "${RAMFS_AUDIO}/panel.db" "INSERT OR REPLACE INTO predict_passes (sat_name,pass_start,pass_end,max_elev) VALUES (\"$sat_name\",$epoch_date,$epoch_date,0);"
  66. elif [[ $basename == *"ZA"* ]]; then
  67. sqlite3 "${RAMFS_AUDIO}/panel.db" "INSERT OR REPLACE INTO predict_passes (sat_name,pass_start,pass_end,max_elev) VALUES (\"$sat_name\",$epoch_date,$epoch_date,0);"
  68. if [[ -f "$FINALPATH/$passname-MSA.jpg" ]]; then
  69. # MSA requires a daylight pass and daylight pass is a column of decoded_passes so this is the way to grab them
  70. sqlite3 "${RAMFS_AUDIO}/panel.db" "INSERT INTO decoded_passes (pass_start, file_path, daylight_pass, is_noaa) VALUES ($epoch_date,\"$passname\",1,1);"
  71. else
  72. sqlite3 "${RAMFS_AUDIO}/panel.db" "INSERT INTO decoded_passes (pass_start, file_path, daylight_pass, is_noaa) VALUES ($epoch_date,\"$passname\",0,1);"
  73. fi
  74. fi
  75. # Move the database file to its final destination
  76. mv "${RAMFS_AUDIO}/panel.db" "$DB_PATH"
  77. echo "Done."
  78. echo ""
  79. done