diff --git a/.gitignore b/.gitignore index 9047423..f9fb143 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ build.sh.log configuration/*.sh dynamic_data/* +last_build_date.txt +last_build_date_lts.txt software/ diff --git a/build.sh b/build.sh index 0d8b6d0..899a2ec 100755 --- a/build.sh +++ b/build.sh @@ -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 @@ -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 @@ -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." @@ -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 @@ -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 diff --git a/upload_iso.sh b/upload_iso.sh index e649997..428b67e 100755 --- a/upload_iso.sh +++ b/upload_iso.sh @@ -4,10 +4,62 @@ # @since 2022-03-19 #### +#### +# @param +# @param +#### +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: >${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." @@ -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 #### -function echo_if_be_verbose () +function _echo_if_be_verbose () { if [[ ${BE_VERBOSE} -eq 1 ]]; then @@ -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 @@ -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 @@ -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