2024-01-29 05:04:48 -08:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2024-03-29 20:49:47 -07:00
|
|
|
USER=$1
|
|
|
|
PASS=$2
|
|
|
|
HOST=$3
|
2024-07-03 03:29:04 -07:00
|
|
|
BUNDLE_NAME=$4
|
2024-07-17 06:00:16 -07:00
|
|
|
SUBFOLDER_TO_UPLOAD=$5
|
2024-08-23 05:07:12 -07:00
|
|
|
# optional folder override in bundle_upload_folder env variable
|
2024-03-30 17:18:48 -07:00
|
|
|
|
2024-01-29 05:04:48 -08:00
|
|
|
SCRIPT_NAME=$(basename "$0")
|
|
|
|
|
2024-03-29 20:49:47 -07:00
|
|
|
if [ -n "${USER}" -a -n "$PASS" -a -n "${HOST}" ]; then
|
2024-03-29 20:40:15 -07:00
|
|
|
echo "$SCRIPT_NAME: Uploading both bundles"
|
2024-04-01 07:59:48 -07:00
|
|
|
|
2024-07-03 03:29:04 -07:00
|
|
|
if [ -n "${BUNDLE_NAME}" ]; then
|
|
|
|
echo "$SCRIPT_NAME: BUNDLE_NAME is ${BUNDLE_NAME}"
|
2024-04-01 07:59:48 -07:00
|
|
|
else
|
2024-07-03 03:29:04 -07:00
|
|
|
echo "$SCRIPT_NAME: BUNDLE_NAME argument not specified"
|
2024-04-01 07:59:48 -07:00
|
|
|
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
|
2024-04-19 08:51:50 -07:00
|
|
|
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
|
|
|
|
|
2024-07-17 06:00:16 -07:00
|
|
|
if [ -n "${SUBFOLDER_TO_UPLOAD}" ]; then
|
|
|
|
echo "$SCRIPT_NAME: SUBFOLDER_TO_UPLOAD is ${SUBFOLDER_TO_UPLOAD}"
|
2024-06-27 09:06:34 -07:00
|
|
|
fi
|
|
|
|
|
2024-07-02 13:10:10 -07:00
|
|
|
if [[ -z "${WHITE_LABEL}" ]]; then
|
|
|
|
echo "WHITE_LABEL environment variable is not specified"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2024-07-03 03:29:04 -07:00
|
|
|
FULL_BUNDLE_FILE="${WHITE_LABEL}_bundle_${BUNDLE_NAME}.zip"
|
|
|
|
UPDATE_BUNDLE_FILE="${WHITE_LABEL}_bundle_${BUNDLE_NAME}_autoupdate.zip"
|
2024-04-01 07:59:48 -07:00
|
|
|
|
2024-01-29 05:04:48 -08:00
|
|
|
RET=0
|
2024-07-18 07:28:39 -07:00
|
|
|
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
|
2024-07-17 06:50:33 -07:00
|
|
|
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
|
2024-04-19 07:22:34 -07:00
|
|
|
mkdir ${DESTINATION_FOLDER}
|
2024-06-27 09:06:34 -07:00
|
|
|
SSHCMD
|
2024-07-17 06:50:33 -07:00
|
|
|
|
|
|
|
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
|
2024-06-27 09:06:34 -07:00
|
|
|
mkdir ${DESTINATION_FOLDER}
|
2024-04-19 07:22:34 -07:00
|
|
|
SSHCMD
|
2024-07-17 06:50:33 -07:00
|
|
|
fi
|
|
|
|
done
|
2024-04-19 07:22:34 -07:00
|
|
|
|
|
|
|
# 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
|
2024-04-19 07:22:34 -07:00
|
|
|
cd ${DESTINATION_FOLDER}
|
|
|
|
put $FULL_BUNDLE_FILE
|
|
|
|
mkdir autoupdate
|
|
|
|
cd autoupdate
|
|
|
|
put $UPDATE_BUNDLE_FILE
|
2024-08-23 05:07:12 -07:00
|
|
|
dir
|
2024-04-19 07:22:34 -07:00
|
|
|
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
|