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.
 
 
 
 
 
 

81 rivejä
3.0 KiB

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