Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

migrate_data.sh 2.4 KiB

4 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. ## import common lib
  3. . "$HOME/.noaa.conf"
  4. . "$HOME/.tweepy.conf"
  5. . "$NOAA_HOME/common.sh"
  6. # TODO: Warn the user
  7. BASEPATH="/var/www/wx/image"
  8. FINALPATH="/var/www/wx/images"
  9. SAT_NAMES="NOAA15 NOAA18 NOAA19 METEOR-M2"
  10. DB_PATH="${NOAA_HOME}/panel.db"
  11. (
  12. cd "${RAMFS_AUDIO}" || exit 1
  13. sqlite3 < "${NOAA_HOME}/panel.sql"
  14. )
  15. cd "$BASEPATH" || exit 1
  16. mkdir -p "$FINALPATH/thumb"
  17. for filename in $(find . -name *.jpg); do
  18. basename="$(echo "$filename" | sed 's~.*/~~')"
  19. for prefix in $SAT_NAMES; do
  20. basedate="$(echo "$basename" | sed -e "s/^$prefix//" | cut -f1,2 -d'-' | sed -e "s/-//")"
  21. if [[ $basename == *"$prefix"* ]]; then
  22. sat_name=$prefix
  23. fi
  24. done
  25. date_normalized=$(echo "$basedate" | sed -e "s/^$sat_name//;s/./&:/12;s/./&:/10;s/./& /8;s/./&\//6;s/./&\//4")
  26. epoch_date=$(date "+%s" -d "$date_normalized")
  27. if [[ $basename == *"METEOR"* ]]; then
  28. passname=$(echo "$basename" | cut -f1,2,3 -d'-')
  29. else
  30. passname=$(echo "$basename" | cut -f1,2 -d'-')
  31. fi
  32. echo "Migration in progress: $basename"
  33. cp "$BASEPATH/$filename" "$FINALPATH"
  34. convert -thumbnail 300 "$BASEPATH/$filename" "$FINALPATH/thumb/$basename"
  35. if [[ $basename == *"METEOR"* ]]; then
  36. sqlite3 "${RAMFS_AUDIO}/panel.db" "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($epoch_date,\"$passname\",1,0);"
  37. sqlite3 "${RAMFS_AUDIO}/panel.db" "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($epoch_date,\"$passname\",1,0);"
  38. 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);"
  39. elif [[ $basename == *"ZA"* ]]; then
  40. 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);"
  41. if [[ -f "$FINALPATH/$passname-MSA.jpg" ]]; then
  42. sqlite3 "${RAMFS_AUDIO}/panel.db" "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($epoch_date,\"$passname\",1,1);"
  43. else
  44. sqlite3 "${RAMFS_AUDIO}/panel.db" "insert into decoded_passes (pass_start, file_path, daylight_pass, is_noaa) values ($epoch_date,\"$passname\",0,1);"
  45. fi
  46. fi
  47. mv "${RAMFS_AUDIO}/panel.db" "$DB_PATH"
  48. echo "Done."
  49. echo ""
  50. done