您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

95 行
3.4 KiB

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