mirror of
https://github.com/OMGeeky/homecontrol.esp-sensors.git
synced 2026-02-23 15:49:52 +01:00
enhance deployment script to only copy changed files
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
#pip install adafruit-ampy
|
#pip install adafruit-ampy
|
||||||
CODE_DIR="src/"
|
CODE_DIR="src/"
|
||||||
LIBS_DIR=deploy/upload
|
LIBS_DIR=deploy/upload
|
||||||
|
|
||||||
UPLOAD_SOURCE_DIR=deploy/upload
|
|
||||||
CONFIG_FILE=deploy/config.json
|
CONFIG_FILE=deploy/config.json
|
||||||
ACTUAL_UPLOAD_SOURCE_DIR=deploy/actual_upload
|
|
||||||
LAST_UPLOAD_DIR=deploy/last_upload
|
LAST_UPLOAD_DIR=deploy/last_upload
|
||||||
|
UPLOAD_SOURCE_DIR=deploy/upload
|
||||||
|
ACTUAL_UPLOAD_SOURCE_DIR=deploy/actual_upload
|
||||||
UPLOAD_TARGET_DIR=
|
UPLOAD_TARGET_DIR=
|
||||||
|
|
||||||
echo "preparing for deployment"
|
echo "preparing for deployment"
|
||||||
@@ -28,12 +28,32 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
# check what files have changed and only upload the changed files (use $ACTUAL_UPLOAD_SOURCE_DIR for the changed files)
|
# check what files have changed and only upload the changed files (use $ACTUAL_UPLOAD_SOURCE_DIR for the changed files)
|
||||||
echo "Checking for changes in the upload directory"
|
|
||||||
rm -rf "$ACTUAL_UPLOAD_SOURCE_DIR"
|
rm -rf "$ACTUAL_UPLOAD_SOURCE_DIR"
|
||||||
mkdir -p "$ACTUAL_UPLOAD_SOURCE_DIR"
|
mkdir -p "$ACTUAL_UPLOAD_SOURCE_DIR"
|
||||||
#rsync -a --delete --ignore-existing "$UPLOAD_SOURCE_DIR/" "$LAST_UPLOAD_DIR/" "$ACTUAL_UPLOAD_SOURCE_DIR/"
|
if [[ "$1" == "-f" ]]; then
|
||||||
# TODO: use diff or rsync to check for changes and only upload the changed files (and delete the files, that are no longer there)
|
echo "Force copying all files"
|
||||||
cp -r "$UPLOAD_SOURCE_DIR"/* "$ACTUAL_UPLOAD_SOURCE_DIR"
|
cp -r "$UPLOAD_SOURCE_DIR"/* "$ACTUAL_UPLOAD_SOURCE_DIR"
|
||||||
|
else
|
||||||
|
echo "Checking for changes in the upload directory"
|
||||||
|
# Use diff to find changes and copy only modified or new files
|
||||||
|
for file in $(find "$UPLOAD_SOURCE_DIR" -type f); do
|
||||||
|
relative_path="${file#$UPLOAD_SOURCE_DIR/}"
|
||||||
|
last_file="$LAST_UPLOAD_DIR/$relative_path"
|
||||||
|
|
||||||
|
if [[ ! -f "$last_file" ]] || ! diff -q "$file" "$last_file" > /dev/null; then
|
||||||
|
echo "Copying changed file: $file"
|
||||||
|
mkdir -p "$(dirname "$ACTUAL_UPLOAD_SOURCE_DIR/$relative_path")"
|
||||||
|
cp "$file" "$ACTUAL_UPLOAD_SOURCE_DIR/$relative_path"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# TODO: remove files that are no longer in the upload directory but were in the last upload directory
|
||||||
|
# for file in $(find "$LAST_UPLOAD_DIR" -type f); do
|
||||||
|
# relative_path="${file#$LAST_UPLOAD_DIR/}"
|
||||||
|
# if [[ ! -f "$UPLOAD_SOURCE_DIR/$relative_path" ]]; then
|
||||||
|
# echo "Removing file: $file"
|
||||||
|
# fi
|
||||||
|
# done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
if [ -z "$ESP_PORT" ]; then
|
if [ -z "$ESP_PORT" ]; then
|
||||||
@@ -42,4 +62,5 @@ if [ -z "$ESP_PORT" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Deploying to ESP32 on port '$ESP_PORT'"
|
echo "Deploying to ESP32 on port '$ESP_PORT'"
|
||||||
|
# TODO: clear storage, if -f flag is passed in?
|
||||||
ampy --port "$ESP_PORT" put "$ACTUAL_UPLOAD_SOURCE_DIR"/ "$UPLOAD_TARGET_DIR"/
|
ampy --port "$ESP_PORT" put "$ACTUAL_UPLOAD_SOURCE_DIR"/ "$UPLOAD_TARGET_DIR"/
|
||||||
|
|||||||
Reference in New Issue
Block a user