rusefi/firmware/bin/upload_bundle.sh

81 lines
2.3 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_NAME=$4
SUBFOLDER_TO_UPLOAD=$5
2024-08-23 05:07:12 -07:00
# optional folder override in bundle_upload_folder env variable
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_NAME}" ]; then
echo "$SCRIPT_NAME: BUNDLE_NAME is ${BUNDLE_NAME}"
else
echo "$SCRIPT_NAME: BUNDLE_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="build_server"
2024-04-18 17:04:45 -07:00
echo "$SCRIPT_NAME: bundle_upload_folder env variable was not specified using default ${bundle_upload_folder}"
fi
if [ -n "${SUBFOLDER_TO_UPLOAD}" ]; then
echo "$SCRIPT_NAME: SUBFOLDER_TO_UPLOAD is ${SUBFOLDER_TO_UPLOAD}"
fi
if [[ -z "${WHITE_LABEL}" ]]; then
echo "WHITE_LABEL environment variable is not specified"
exit 1
fi
FULL_BUNDLE_FILE="${WHITE_LABEL}_bundle_${BUNDLE_NAME}.zip"
UPDATE_BUNDLE_FILE="${WHITE_LABEL}_bundle_${BUNDLE_NAME}_autoupdate.zip"
2024-01-29 05:04:48 -08:00
RET=0
if [ -n "${SUBFOLDER_TO_UPLOAD}" ]; then # subfolder to upload bundle is specified explicitly
DESTINATION_SUBFOLDER="${SHORT_BOARD_NAME}/${SUBFOLDER_TO_UPLOAD}"
elif [ "$AUTOMATION_LTS" == "true" -a -n "$AUTOMATION_REF" ]; then # lts build
DESTINATION_SUBFOLDER="lts/${AUTOMATION_REF}"
else
DESTINATION_SUBFOLDER=""
fi
DESTINATION_FOLDER="${bundle_upload_folder}"
# sftp does not support -p flag on mkdir :(
sshpass -p $PASS sftp -o StrictHostKeyChecking=no ${USER}@${HOST} <<SSHCMD
mkdir ${DESTINATION_FOLDER}
SSHCMD
readarray -d "/" -t SUBFOLDER_ARRAY <<< "${DESTINATION_SUBFOLDER}"
for ((n=0; n < ${#SUBFOLDER_ARRAY[*]}; n++))
do
SUBFOLDER_COMPONENT="${SUBFOLDER_ARRAY[n]}"
if [ -n "${SUBFOLDER_COMPONENT}" ]; then
DESTINATION_FOLDER="${DESTINATION_FOLDER}/${SUBFOLDER_COMPONENT}"
sshpass -p $PASS sftp -o StrictHostKeyChecking=no ${USER}@${HOST} <<SSHCMD
mkdir ${DESTINATION_FOLDER}
SSHCMD
fi
done
# sftp does not support -p flag on mkdir :(
sshpass -p $PASS sftp -o StrictHostKeyChecking=no ${USER}@${HOST} <<SSHCMD
2024-08-23 05:07:12 -07:00
dir
cd ${DESTINATION_FOLDER}
put $FULL_BUNDLE_FILE
mkdir autoupdate
cd autoupdate
put $UPDATE_BUNDLE_FILE
2024-08-23 05:07:12 -07:00
dir
SSHCMD
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