Skip to content

Commit

Permalink
Moved creation and handling of latest_build_date from build.sh to upl…
Browse files Browse the repository at this point in the history
…oad_iso.sh
  • Loading branch information
stevleibelt committed Oct 16, 2024
1 parent ba9655b commit d8f835c
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 22 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
build.sh.log
configuration/*.sh
dynamic_data/*
last_build_date.txt
last_build_date_lts.txt
software/
31 changes: 23 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ function add_packages_and_repository ()

PATH_TO_THE_PACKAGES_FILE="${PATH_TO_THE_ARCHLIVE}/packages.x86_64"
PATH_TO_THE_PACMAN_CONF_FILE="${PATH_TO_THE_ARCHLIVE}/pacman.conf"
PATH_TO_THE_PACMAN_D_ARCHZFS_FILE="${PATH_TO_THE_ARCHLIVE}/pacman.d/archzfs"
PATH_TO_THE_PACMAN_D_DIRECTORY="${PATH_TO_THE_ARCHLIVE}/pacman.d"
PATH_TO_THE_PACMAN_D_ARCHZFS_FILE="${PATH_TO_THE_PACMAN_D_DIRECTORY}/archzfs"
#eo: variable

#bo: argument validation
Expand Down Expand Up @@ -151,12 +152,28 @@ function add_packages_and_repository ()
else
_echo_if_be_verbose " PATH_TO_THE_PACMAN_CONF_FILE >>${PATH_TO_THE_PACMAN_CONF_FILE}<<."
fi

if [[ ! -d "${PATH_TO_THE_PACMAN_D_DIRECTORY}" ]];
then
_echo_if_be_verbose " Creating >>${PATH_TO_THE_PACMAN_D_DIRECTORY}<<."
/usr/bin/mkdir "${PATH_TO_THE_PACMAN_D_DIRECTORY}"
fi


if [[ -f "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}" ]];
then
_echo_if_be_verbose " Truncating >>${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}<<."
/usr/bin/truncate -s 0 "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"
else
_echo_if_be_verbose " Creating >>${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}<<."
/usr/bin/touch "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"
fi
#eo: environment check

#bo: repo index
if [[ "${#REPO_INDEX_OR_EMPTY_STRING}" -gt 0 ]];
then
_echo_if_be_verbose " Adapted repo index to >>${REPO_INDEX_OR_EMPTY_STRING}<< in file >>${PATH_TO_THE_PACMAN_CONF_FILE}<<."
_echo_if_be_verbose " Adapted repo index to >>${REPO_INDEX_OR_EMPTY_STRING}<< in file >>${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}<<."

#@see: https://github.com/stevleibelt/arch-linux-live-cd-iso-with-zfs/pull/6/files
# archzfs repo often lags behind core a week or so, causing zfs kmod/kernel version mismatch and build failure
Expand All @@ -182,15 +199,15 @@ function add_packages_and_repository ()
_echo_if_be_verbose " Creating archzfs mirrorlist file >>${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}<<."

#bo: adding repository
echo "Server = http://archzfs.com/\$repo/\$arch" >> ${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}
echo "Server = http://mirror.sum7.eu/archlinux/archzfs/\$repo/\$arch" >> ${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}
echo "Server = https://mirror.biocrafting.net/archlinux/archzfs/\$repo/\$arch" >> ${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}
echo "Server = http://archzfs.com/\$repo/\$arch" >> "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"
echo "Server = http://mirror.sum7.eu/archlinux/archzfs/\$repo/\$arch" >> "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"
echo "Server = https://mirror.biocrafting.net/archlinux/archzfs/\$repo/\$arch" >> "${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}"

_echo_if_be_verbose " Adding archzfs repositories to PATH_TO_THE_PACMAN_CONF_FILE >>${PATH_TO_THE_PACMAN_CONF_FILE}<<."

echo "" >> ${PATH_TO_THE_PACMAN_CONF_FILE}
echo "[archzfs]" >> ${PATH_TO_THE_PACMAN_CONF_FILE}
echo "Include = /etc/pacman.d/archzfs" >> ${PATH_TO_THE_PACMAN_CONF_FILE}
echo "Include = ${PATH_TO_THE_PACMAN_D_ARCHZFS_FILE}" >> ${PATH_TO_THE_PACMAN_CONF_FILE}
#eo: adding repository

_echo_if_be_verbose " Adding packages."
Expand Down Expand Up @@ -824,7 +841,6 @@ function _main ()
local ISO_FILE_PATH
local PATH_TO_THIS_SCRIPT
local PATH_TO_THE_DYNAMIC_DATA_DIRECTORY
local PATH_TO_THE_LATEST_BUILD_DATE
local PATH_TO_THE_OPTIONAL_CONFIGURATION_FILE
local PATH_TO_THE_OUTPUT_DIRECTORY
local PATH_TO_THE_PROFILE_DIRECTORY
Expand Down Expand Up @@ -944,7 +960,6 @@ function _main ()
PATH_TO_THE_OUTPUT_DIRECTORY="${PATH_TO_THE_DYNAMIC_DATA_DIRECTORY}/out"

ISO_FILE_PATH="${PATH_TO_THE_OUTPUT_DIRECTORY}/${BUILD_FILE_NAME}.iso"
PATH_TO_THE_LATEST_BUILD_DATE="${PATH_TO_THE_OUTPUT_DIRECTORY}/last_build_date.txt"

SHA512_FILE_PATH="${ISO_FILE_PATH}.sha512sum"
#end of variables declaration
Expand Down
84 changes: 70 additions & 14 deletions upload_iso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,62 @@
# @since 2022-03-19
####

####
# @param <string: arch_iso_file_path>
# @param <string: latest_build_date_file_path>
####
function _create_latest_build_date ()
{
local ARCH_ISO_FILE_PATH
local CREATION_DATE_TIME
local LATEST_BUILD_DATE_FILE_PATH

ARCH_ISO_FILE_PATH="${1}"
CREATION_DATE_TIME=""
LATEST_BUILD_DATE_FILE_PATH="${2}"

if [[ ! -f "${ARCH_ISO_FILE_PATH}" ]];
then
echo ":: Error!"
echo " Invalid arch iso file path provided"
echo " >>${ARCH_ISO_FILE_PATH}<< is not a file"
echo ""

exit 20
fi

if [[ -f ${PATH_TO_THE_LATEST_BUILD_DATE} ]];
then
if /usr/bin/rm "${PATH_TO_THE_LATEST_BUILD_DATE}";
then
_echo_if_be_verbose " Removed file: ${PATH_TO_THE_LATEST_BUILD_DATE}"
else
echo ":: Error - Could not remove file"
echo " File path: ${PATH_TO_THE_LATEST_BUILD_DATE}"

exit 21
fi
fi

_echo_if_be_verbose " Creating file >>${LATEST_BUILD_DATE_FILE_PATH}<<"

#add date
CREATION_DATE_TIME=$(stat -c '%w' "${ARCH_ISO_FILE_PATH}" | cut -d ' ' -f 1)
_echo_if_be_verbose " Detected creation date >>${CREATION_DATE_TIME}<<"

#add time
CREATION_DATE_TIME=$(echo -n "${CREATION_DATE_TIME}T"; stat -c '%w' "${ARCH_ISO_FILE_PATH}" | cut -d ' ' -f 2 | cut -d '.' -f 1)
_echo_if_be_verbose " Detected creation date time >>${CREATION_DATE_TIME}<<"

touch "${LATEST_BUILD_DATE_FILE_PATH}"

echo "${CREATION_DATE_TIME}" > "${LATEST_BUILD_DATE_FILE_PATH}"
}

####
# @param: <string: path_to_the_local_configuration_file
####
function create_local_configuration_file ()
function _create_local_configuration_file ()
{
#bo: variables
local CURRENT_DATE
Expand All @@ -26,7 +78,7 @@ function create_local_configuration_file ()
echo ":: ERROR - File does not exist!"
echo " File path >>${PATH_TO_THE_LOCAL_CONFIGURATION_DIST}<< is invalid."

exit 1
exit 30
fi

echo ":: Local configration file is missing. I will create it but you need to answere some questions."
Expand All @@ -53,14 +105,14 @@ function create_local_configuration_file ()
echo "local PATH_TO_SSH_KEY_FILE=\"${PATH_TO_SSH_KEY_FILE}\"" >> "${PATH_TO_THE_LOCAL_CONFIGURATION}"
echo "local SCP_HOST_PATH=\"${SCP_HOST_PATH}\"" >> "${PATH_TO_THE_LOCAL_CONFIGURATION}"

echo_if_be_verbose " Created file >>${PATH_TO_THE_LOCAL_CONFIGURATION}<<."
_echo_if_be_verbose " Created file >>${PATH_TO_THE_LOCAL_CONFIGURATION}<<."
#eo: user input destination scp host path"
}

####
# @param <string: output>
####
function echo_if_be_verbose ()
function _echo_if_be_verbose ()
{
if [[ ${BE_VERBOSE} -eq 1 ]];
then
Expand Down Expand Up @@ -136,11 +188,11 @@ function _main ()

if [[ ${IS_LTS_KERNEL} -eq 1 ]];
then
PATH_TO_THE_LATEST_BUILD_DATE="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/last_build_date_lts.txt"
PATH_TO_THE_LATEST_BUILD_DATE="${PATH_TO_THIS_SCRIPT}/last_build_date_lts.txt"
PATH_TO_THE_ISO="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/archlinux-archzfs-linux-lts.iso"
PATH_TO_THE_ISO_SHA512="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/archlinux-archzfs-linux-lts.iso.sha512sum"
else
PATH_TO_THE_LATEST_BUILD_DATE="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/last_build_date.txt"
PATH_TO_THE_LATEST_BUILD_DATE="${PATH_TO_THIS_SCRIPT}/last_build_date.txt"
PATH_TO_THE_ISO="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/archlinux-archzfs-linux.iso"
PATH_TO_THE_ISO_SHA512="${PATH_TO_THIS_SCRIPT}/dynamic_data/out/archlinux-archzfs-linux.iso.sha512sum"
fi
Expand All @@ -160,11 +212,11 @@ function _main ()
#bo: load or create local configuration
if [[ ! -f ${PATH_TO_THE_LOCAL_CONFIGURATION} ]];
then
echo_if_be_verbose " No file >>${PATH_TO_THE_LOCAL_CONFIGURATION}<< found."
create_local_configuration_file "${PATH_TO_THE_LOCAL_CONFIGURATION}"
_echo_if_be_verbose " No file >>${PATH_TO_THE_LOCAL_CONFIGURATION}<< found."
_create_local_configuration_file "${PATH_TO_THE_LOCAL_CONFIGURATION}"
fi

echo_if_be_verbose " Sourcing file >>${PATH_TO_THE_LOCAL_CONFIGURATION}<< found."
_echo_if_be_verbose " Sourcing file >>${PATH_TO_THE_LOCAL_CONFIGURATION}<< found."
source "${PATH_TO_THE_LOCAL_CONFIGURATION}"
#eo: load or create local configuration

Expand All @@ -179,16 +231,20 @@ function _main ()

if [[ ! -f "${PATH_TO_THE_ISO_SHA512}" ]];
then
echo_if_be_verbose " File >>${PATH_TO_THE_ISO_SHA512}<< not found. Creating it."
_echo_if_be_verbose " File >>${PATH_TO_THE_ISO_SHA512}<< not found. Creating it."
sha512sum "${PATH_TO_THE_ISO}" >> "${PATH_TO_THE_ISO_SHA512}"
fi
#eo: environment check

#bo: create latest build date file
_create_latest_build_date "${PATH_TO_THE_ISO}" "${PATH_TO_THE_LATEST_BUILD_DATE}"
#eo: create latest build date file

#bo: upload
echo_if_be_verbose " Starting upload using following arguments:"
echo_if_be_verbose " Files: >>${PATH_TO_THE_LATEST_BUILD_DATE}<<, >>${PATH_TO_THE_ISO_SHA512}<< and >>${PATH_TO_THE_ISO}<<."
echo_if_be_verbose " Key: >>${PATH_TO_SSH_KEY_FILE}<<."
echo_if_be_verbose " Hostpath: >>${SCP_HOST_PATH}<<."
_echo_if_be_verbose " Starting upload using following arguments:"
_echo_if_be_verbose " Files: >>${PATH_TO_THE_LATEST_BUILD_DATE}<<, >>${PATH_TO_THE_ISO_SHA512}<< and >>${PATH_TO_THE_ISO}<<."
_echo_if_be_verbose " Key: >>${PATH_TO_SSH_KEY_FILE}<<."
_echo_if_be_verbose " Hostpath: >>${SCP_HOST_PATH}<<."

if [[ ${IS_DRY_RUN} -eq 0 ]];
then
Expand Down

0 comments on commit d8f835c

Please sign in to comment.