rusefi/firmware/bin/upload_bundle.sh

52 lines
1.7 KiB
Bash
Raw Normal View History

2024-01-29 05:04:48 -08:00
#!/usr/bin/env bash
USER=$1
PASS=$2
HOST=$3
BUNDLE_FILE_NAME=$4
2024-01-29 05:04:48 -08:00
SCRIPT_NAME=$(basename "$0")
if [ -n "${USER}" -a -n "$PASS" -a -n "${HOST}" ]; then
2024-03-29 20:40:15 -07:00
echo "$SCRIPT_NAME: Uploading both bundles"
if [ -n "${BUNDLE_FILE_NAME}" ]; then
2024-04-02 07:42:41 -07:00
echo "$SCRIPT_NAME: BUNDLE_FILE_NAME is ${BUNDLE_FILE_NAME}"
else
2024-04-02 07:42:41 -07:00
echo "$SCRIPT_NAME: BUNDLE_FILE_NAME argument not specified"
exit 1
fi
2024-04-18 17:04:45 -07:00
if [ -n "${bundle_upload_folder}" ]; then
echo "$SCRIPT_NAME: bundle_upload_folder is ${bundle_upload_folder}"
else
bundle_upload_folder="rusefi_bundle"
echo "$SCRIPT_NAME: bundle_upload_folder env variable was not specified using default ${bundle_upload_folder}"
fi
# technical debt: more than one file uses magic 'rusefi_bundle_' constant, can we extract constant?
FULL_BUNDLE_FILE="rusefi_bundle_${BUNDLE_FILE_NAME}.zip"
UPDATE_BUNDLE_FILE="rusefi_bundle_${BUNDLE_FILE_NAME}_autoupdate.zip"
2024-01-29 05:04:48 -08:00
RET=0
2024-03-07 19:17:51 -08:00
if [ "$LTS" == "true" -a -n "$REF" ]; then
2024-04-18 17:04:45 -07:00
DESTINATION_FOLDER="${bundle_upload_folder}/lts/${REF}"
2024-01-29 05:04:48 -08:00
else
2024-04-18 17:04:45 -07:00
DESTINATION_FOLDER="${bundle_upload_folder}"
2024-01-29 05:04:48 -08:00
fi
2024-04-19 06:58:31 -07:00
tar -czf - $FULL_BUNDLE_FILE | sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no ${USER}@${HOST} "mkdir -p ${DESTINATION_FOLDER}; tar -xzf - -C ${DESTINATION_FOLDER}"
2024-03-29 20:40:15 -07:00
RET=$((RET+$?+PIPESTATUS))
if [ -f $UPDATE_BUNDLE_FILE ]; then
2024-04-19 06:58:31 -07:00
tar -czf - $UPDATE_BUNDLE_FILE | sshpass -p "$PASS" ssh -o StrictHostKeyChecking=no ${USER}@${HOST} "mkdir -p ${DESTINATION_FOLDER}/autoupdate; tar -xzf - -C ${DESTINATION_FOLDER}/autoupdate"
RET=$((RET+$?+PIPESTATUS))
else
echo "File $UPDATE_BUNDLE_FILE does not exist."
fi
2024-01-29 05:04:48 -08:00
if [ $RET -ne 0 ]; then
echo "$SCRIPT_NAME: Bundle upload failed"
exit 1
fi
2024-04-19 07:08:42 -07:00
echo "$SCRIPT_NAME: DONE $FULL_BUNDLE_FILE"
2024-01-29 05:04:48 -08:00
else
echo "$SCRIPT_NAME: Upload not configured"
fi