Skip to content

Commit

Permalink
fix yaml and rootfs gdrive download (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
varnholt authored Jan 8, 2025
1 parent a6bb6dc commit 7189c9f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-all-board.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
echo "password: root" >> ./upload/login-pass.txt
- name: Upload artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: ubuntu-22.04-${{ matrix.board }} (this is unzipped size)
path: ./upload
59 changes: 48 additions & 11 deletions rootfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,70 @@
DIR=$PWD
. "${DIR}/version.sh"

if [ -d ${DIR}/dl ] ; then
mkdir -p "${DIR}/dl"
# Create the download directory if it doesn't exist
if [ ! -d "${DIR}/dl" ] ; then
mkdir -p "${DIR}/dl"
fi

if [ -d ${DIR}/dl ] ; then
mkdir -p "${DIR}/dl"
# Ensure ${DIR}/dl exists after attempt to create
if [ ! -d "${DIR}/dl" ] ; then
echo "Failed to create download directory: ${DIR}/dl"
exit 1
fi


# Download the base_rootfs_name file if it doesn't exist
if [ -f "${DIR}/dl/${base_rootfs_name}" ] ; then
echo "File downloaded: ${DIR}/dl/${base_rootfs_name}"
#exit 0 ;
else
wget -P "${DIR}/dl" "${link_ubuntu_relese}/${base_rootfs_name}" || { exit 1 ; }
fi


# https://drive.google.com/file/d/1kEco22WrjYhaFoAfxaGbd41blzu6kYSC/view?usp=sharing
# Google Drive file details
fileid="1kEco22WrjYhaFoAfxaGbd41blzu6kYSC"
rootfs_name="ubuntu-22.04-base-stm32mp1-armhf-16-05-2022.tar.gz"
URL="https://docs.google.com/uc?export=download&id=${fileid}"
BASE_URL="https://drive.google.com/uc?export=download"

cd "${DIR}/dl"
if [ -f "${DIR}/dl/${rootfs_name}" ] ; then
echo "File downloaded: ${DIR}/dl/${rootfs_name}"
else
wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate $URL -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=${fileid}" -O ${rootfs_name} && rm -rf /tmp/cookies.txt || { cd "${DIR}" ; exit 1 ; }
# Step 1: Fetch the download page and save cookies
echo "Fetching initial download page..."
wget --quiet --save-cookies cookies.txt --keep-session-cookies --no-check-certificate \
"${BASE_URL}&id=${fileid}" -O temp.html

# Step 2: Extract the necessary IDs from the HTML response
CONFIRM=$(grep -oP '<input type="hidden" name="confirm" value="\K[^"]+' temp.html)
ACTION_URL=$(grep -oP '<form id="download-form" action="\K[^"]+' temp.html)

if [ -z "${CONFIRM}" ] || [ -z "${ACTION_URL}" ]; then
echo "Failed to extract necessary fields. Exiting."
rm -f temp.html cookies.txt
cd "${DIR}"
exit 1
fi

# Full URL for the file download
FULL_DOWNLOAD_URL="${ACTION_URL}?id=${fileid}&export=download&confirm=${CONFIRM}"

# Step 3: Use the extracted information to download the file
echo "Downloading the file..."
wget --quiet --load-cookies cookies.txt --no-check-certificate "${FULL_DOWNLOAD_URL}" -O "${rootfs_name}"

# Step 4: Clean up temporary files
echo "Cleaning up temporary files..."
rm -f temp.html cookies.txt

# Step 5: Validate the downloaded file
if [ -f "${rootfs_name}" ] && [ "$(file -b --mime-type "${rootfs_name}")" != "text/html" ]; then
echo "File successfully downloaded: ${rootfs_name}"
else
echo "Download failed or the file is invalid. Exiting."
rm -f "${rootfs_name}" # Remove invalid file
cd "${DIR}"
exit 1
fi
fi

cd "${DIR}"
exit 0 ;
exit 0

0 comments on commit 7189c9f

Please sign in to comment.