set -e
W=/home/adpcomilearnings/public_html; T=/tmp/urcare_sedinta; TS=$(date +%Y%m%d_%H%M%S); B=/home/adpcomilearnings/backups_deploy/${TS}_sedinta_in_curs
PHP=/opt/cpanel/ea-php74/root/usr/bin/php
# cale | md5 vechi live | md5 nou
L="classes/PacheteAziTexte.php 790162f55b06e874539f09c2d8088874 7a473d7cda3fd90d2f2ce2135db34add
classes/PacheteLunare.php b55e0856c5c4f2726ddcbb50c8cf74bd a8e6c7f03ed261d0cb509caf53338a75
classes/PregatireChatPulsProfInfo.php 40ce62790d64004da298f2d5ee17cf05 c0918e51d7ae7b75463bfa987ff9aa12
includes/pachete_operare_date.php 97ce3d291d606373d9c0189011d59d14 05c12bc28227f07c7b30591c7d71457c
classes/PregatireChatEvenimente.php 7e43293848a3b5112177ddd3b09788de b562fc1495917231bff2948a1ab9ec3b
classes/PregatireChatOperare.php 159559f679bdaded404382198b124a4a 65a1e298445216e7a6d4a4976a2a3d70
classes/PregatireChatPulsProf.php 111e5ad965488f6cd0a2317b6d9f24d6 bb4a10d99da53085b6f11fab4139f40c
includes/pachete_operare_sedinte.php df2b35a82d7dd59a3f65f98fc8badfac 0c925270c6780313976cdd76a1ff172c"
echo "$L" | while read f vechi nou; do
  t=$T/$(echo $f | tr / _)
  [ "$(md5sum < $W/$f | cut -d' ' -f1)" = "$vechi" ] || { echo "GARDĂ: live schimbat $f"; exit 1; }
  [ "$(md5sum < $t | cut -d' ' -f1)" = "$nou" ] || { echo "GARDĂ: copie greșită $f"; exit 1; }
  $PHP -d short_open_tag=1 -l $t >/dev/null || { echo "GARDĂ: lint $f"; exit 1; }
done
mkdir -p $B
echo "$L" | while read f vechi nou; do mkdir -p $B/$(dirname $f); cp -p $W/$f $B/$f; done
echo "$L" | while read f vechi nou; do t=$T/$(echo $f | tr / _); cp $t $W/$f.urcare_tmp; chown adpcomilearnings:adpcomilearnings $W/$f.urcare_tmp; chmod --reference=$W/$f $W/$f.urcare_tmp; done
echo "$L" | while read f vechi nou; do mv $W/$f.urcare_tmp $W/$f; done
echo "$L" | while read f vechi nou; do echo "$f $(md5sum < $W/$f | cut -c1-8) $(stat -c %U $W/$f)"; done
echo "backup: $B"
