diff options
author | Gatis Paeglis <gatis.paeglis@theqtcompany.com> | 2016-04-28 09:13:20 +0200 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@theqtcompany.com> | 2016-04-28 07:46:55 +0000 |
commit | 6c84fc72006791369a0d278d8203b94e716b9210 (patch) | |
tree | ac22982bb0e6db3de2a548e46755c4f215d75265 /qt-ostree | |
parent | e3bf8b4f901113277b69315b938ae9a7063e9c25 (diff) |
Move from legacy /boot to /usr/lib/ostree-boot
Having contents in the legacy /boot (as in OSTree
deployment tree) location gets shadowed at boot
time with the real boot/ directory.
This patch also cleans up command line argument
validation code and adds version numbers to the
shipped kernel/initramfs images.
Change-Id: I4ae82406c6bfce4a6221e2d4fa6468e7c43ca23d
Reviewed-by: Gatis Paeglis <gatis.paeglis@theqtcompany.com>
Diffstat (limited to 'qt-ostree')
-rwxr-xr-x | qt-ostree/qt-ostree | 93 |
1 files changed, 41 insertions, 52 deletions
diff --git a/qt-ostree/qt-ostree b/qt-ostree/qt-ostree index 8be7024..f4b9139 100755 --- a/qt-ostree/qt-ostree +++ b/qt-ostree/qt-ostree @@ -32,7 +32,7 @@ ROOT=$(dirname $(readlink -f $0)) WORKDIR=$PWD GENERATED_TREE=${WORKDIR}/tree -BOOT_FILE_PATH=${GENERATED_TREE}/boot +BOOT_FILE_PATH=${GENERATED_TREE}/usr/lib/ostree-boot SERVER_ROOT=${WORKDIR}/httpd CREATE_OTA_SYSROOT=false OTA_SYSROOT=${WORKDIR}/sysroot @@ -170,14 +170,18 @@ usage() echo } -update_invalid_args() +validation_error() { + error_message=${1} + if [ $INVALID_ARGS = false ] ; then echo - echo "Following errors occurred:" + echo "Following validation errors occurred:" echo fi INVALID_ARGS=true + + echo "error: ${error_message}" } validate_arg() @@ -189,55 +193,50 @@ validate_arg() if [ -z "${value}" ] ; then if [ ${required} = true ] ; then - update_invalid_args - echo ${arg} "is not set." + validation_error "${arg} is not set." fi return 0 fi if [ ! -${flag} ${value} ] ; then - update_invalid_args case ${flag} in d) - echo "${arg} requires a directory path, but ${value} was provided." + validation_error "${arg} requires a directory path, but ${value} was provided." ;; f) - echo "${arg} requires a path to a file, but ${value} was provided." + validation_error "${arg} requires a path to a file, but ${value} was provided." ;; esac return 0 fi - valid=true - case "${arg}" in + case ${arg} in --gpg-trusted-keyring) - if [[ ${value} != *.gpg ]] ; then - valid=false - error="--gpg-trusted-keyring expects gpg keyring file with the .gpg extension, but ${value} was provided." + if [[ ${GPG_TRUSTED_KEYRING} != *.gpg ]] ; then + validation_error "--gpg-trusted-keyring expects gpg keyring file with the .gpg extension, but ${GPG_TRUSTED_KEYRING} was provided." + fi + ;; + --initramfs) + if [[ "$(basename ${INITRAMFS})" != initramfs-* ]] ; then + error="The provided initramfs image ${INITRAMFS} doesn't seem to be generated by the bundled 'generate-initramfs' script." + error+=" The required naming pattern is initramfs-\${device}-\${release} or initramfs-\${release}." + validation_error "${error}" fi ;; --sysroot-image-path) - count=$(ls ${value}/*.img 2> /dev/null | wc -l) + count=$(ls ${SYSROOT_IMAGE_PATH}/*.img 2> /dev/null | wc -l) if [ ${count} -gt 1 ] ; then - valid=false - error="Found ${count} *.img files in --sysroot-image-path ${value}/, but expected to find 1 *.img file." + validation_error "Found ${count} *.img files in --sysroot-image-path ${SYSROOT_IMAGE_PATH}/, but expected to find 1 *.img file." elif [ ${count} = 1 ] ; then BINARY_IMAGE=true else - count=$(ls ${value}/*.tar.gz 2> /dev/null | wc -l) + count=$(ls ${SYSROOT_IMAGE_PATH}/*.tar.gz 2> /dev/null | wc -l) if [ ${count} = 0 ] ; then - valid=false - error="--sysroot-image-path ${value}/ must contain *.img or *.tar.gz sysroot image files." + validation_error "--sysroot-image-path ${SYSROOT_IMAGE_PATH}/ must contain *.img or *.tar.gz sysroot image files." fi fi - ;; + ;; esac - - if [ $valid = false ] ; then - update_invalid_args - echo ${error} - return 0 - fi } parse_args() @@ -314,8 +313,7 @@ parse_args() qt_ostree_exit 0 ;; -*) - echo - echo "Unknown parameter: ${1}" + validation_error "Unknown parameter: ${1}" usage qt_ostree_exit 1 ;; @@ -336,14 +334,12 @@ parse_args() validate_arg "--tls-client-key-path" "${CLIENT_KEY}" false f if [[ $USE_GPG = true && ( -z "${GPG_KEY}" || -z "${GPG_HOMEDIR}" ) ]] ; then - update_invalid_args # Note: --gpg-homedir is not required when keyring is stored in a standard path, # but just to me sure that a commit won't fail, we require both of these args. - echo "Must specify both --gpg-sign and --gpg-homedir for GPG signing feature." + validation_error "Must specify both --gpg-sign and --gpg-homedir for GPG signing feature." fi if [[ $USE_CLIENT_TLS = true && ( -z "${CLIENT_CERT}" || -z "${CLIENT_KEY}" ) ]] ; then - update_invalid_args - echo "Must specify both --tls-client-cert-path and --tls-client-key-path for TLS client authentication feature." + validation_error "Must specify both --tls-client-cert-path and --tls-client-key-path for TLS client authentication feature." fi if [ $INVALID_ARGS = true ] ; then usage @@ -384,26 +380,25 @@ clean_workdir() organize_boot_files() { - cp ${INITRAMFS} ${BOOT_FILE_PATH}/initramfs - # Find kernel image. cd ${BOOT_FILE_PATH}/ - kernel_found=false - for file in *; do - if file -b $file | grep -qi "kernel"; then - qt_ostree_info "Found kernel image ${BOOT_FILE_PATH}/${file}" - kernel_found=true - if [ "${file}" != "vmlinuz" ] ; then - # Rename as OSTree expects that kernel image is named 'vmlinuz'. - mv ${file} vmlinuz - fi + for kernel in *; do + if file -b ${kernel} | grep -qi "kernel"; then + kernel=${BOOT_FILE_PATH}/${kernel} + qt_ostree_info "Found kernel image ${kernel}" break fi done - if [ $kernel_found = false ] ; then + if [ -z "${kernel}" ] ; then qt_ostree_error "Failed to find kernel image in ${BOOT_FILE_PATH}" fi + # OSTree deploy requires vmlinuz-*. + release=$(basename ${INITRAMFS} | cut -f2- -d'-') + bootcsum=$(cat ${kernel} ${INITRAMFS} | sha256sum | cut -f 1 -d ' ') + mv ${kernel} ${BOOT_FILE_PATH}/vmlinuz-${release}-${bootcsum} + cp ${INITRAMFS} ${BOOT_FILE_PATH}/initramfs-${release}-${bootcsum} + # Boot loader companions. if [[ "${BOOTLOADER}" = "u-boot" && -n "${UBOOT_ENV_FILE}" ]] ; then cp ${UBOOT_ENV_FILE} ${BOOT_FILE_PATH}/ @@ -482,10 +477,6 @@ convert_to_ostree_sysroot() fi organize_boot_files - cd ${BOOT_FILE_PATH} - bootcsum=$(cat vmlinuz initramfs | sha256sum | cut -f 1 -d ' ') - mv vmlinuz vmlinuz-${bootcsum} - mv initramfs initramfs-${bootcsum} # OSTree requires /etc/os-release file (see The Boot Loader Specification). if [ ! -e ${GENERATED_TREE}/etc/os-release ] ; then @@ -601,9 +592,7 @@ populate_filesystem_images() if [ $RECOVERY_PARTITION = true ] ; then mkdir recovery-dd mount recovery.${RECOVERYFS_TYPE} recovery-dd/ - cp ${BOOT_FILE_PATH}/initramfs-* recovery-dd/initramfs - # Ship the kernel version that match the initramfs version. - cp ${BOOT_FILE_PATH}/vmlinuz-* recovery-dd/vmlinuz + cp ${BOOT_FILE_PATH}/* recovery-dd/ chattr -R +i recovery-dd/ fi @@ -722,7 +711,7 @@ create_ota_sysroot() extract_sysroot() { mkdir ${GENERATED_TREE}/ - mkdir ${BOOT_FILE_PATH}/ + mkdir -p ${BOOT_FILE_PATH}/ if [ $BINARY_IMAGE = true ] ; then # Extract binary image. |