Skip to content

Commit

Permalink
Add scripts error output
Browse files Browse the repository at this point in the history
  • Loading branch information
ophub committed Jan 30, 2023
1 parent 8cea520 commit 7e09bec
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ update_script() {
echo -e "${INFO} Start installing update dependencies..."
sudo apt-get update
sudo apt-get install -y subversion
[[ "${?}" -ne "0" ]] && error_msg "The [ subversion ] installation failed."

# Convert script repository address to svn format
if [[ "${script_repo}" == http* && -n "$(echo ${script_repo} | grep "tree/main")" ]]; then
Expand All @@ -69,12 +70,14 @@ update_script() {
# Update related files
echo -e "${INFO} Start syncing latest scripts..."
svn export ${script_repo} ${compile_path} --force
[[ "${?}" -ne "0" ]] && error_msg "Sync [ ${script_repo} ] scripts failed."
cp -f ${script_name} ${compile_script}
chmod +x ${compile_script}

# Install dependencies
echo -e "${INFO} Start installing compilation dependencies..."
sudo apt-get install -y $(cat ${script_path}/armbian-compile-kernel-depends)
[[ "${?}" -ne "0" ]] && error_msg "Dependency installation failed."

sync && sleep 3
echo -e "${SUCCESS} Scripts updated successfully."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ update_script() {
# Update related files
echo -e "${STEPS} Start syncing files..."
svn export ${script_repo} ${software_path} --force
[[ "${?}" -ne "0" ]] && error_msg "Sync [ ${script_repo} ] scripts failed."
find ${software_path} -type f -name '*.sh' -exec chmod +x {} \;

sync && sleep 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,17 @@ create_the_swap() {
# create swapfile
[[ "${ROOTFS_TYPE}" == "btrfs" ]] && {
truncate -s 0 ${SWAP_PATH}/swapfile
[[ "${?}" -ne "0" ]] && error_msg "[ truncate ] operation failed."
chattr +C ${SWAP_PATH}/swapfile
btrfs property set ${SWAP_PATH}/swapfile compression none
}
dd if="/dev/zero" of="${SWAP_PATH}/swapfile" bs="1024" count="$((1048576 * ${swap_gb}))" conv="fsync"
[[ "${?}" -ne "0" ]] && error_msg "Failed to write [ ${SWAP_PATH}/swapfile ] using dd."
chmod 600 ${SWAP_PATH}/swapfile
mkswap -L SWAP ${SWAP_PATH}/swapfile
[[ "${?}" -ne "0" ]] && error_msg "[ mkswap ] operation failed."
swapon ${SWAP_PATH}/swapfile
[[ "${?}" -ne "0" ]] && error_msg "[ swapon ] operation failed."

# Add swap to the mount point
sed -i '/swap/d' /etc/fstab
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ check_depends() {
echo -e "${STEPS} Start installing the necessary dependencies..."
sudo apt-get update
sudo apt-get install -y ${dpkg_packages[*]}
[[ "${?}" -ne "0" ]] && error_msg "Dependency installation failed."
fi
}

Expand All @@ -99,24 +100,28 @@ sync_config() {
echo -e "${STEPS} Start syncing operation instruction and service script..."
[[ -d "${sbin_path}" ]] || mkdir -p ${sbin_path}
svn export ${github_repo}/common-files${sbin_path} ${sbin_path} --force
[[ "${?}" -ne "0" ]] && error_msg "Sync [ ${github_repo}/common-files${sbin_path} ] scripts failed."
chmod +x ${sbin_path}/armbian-*

# Update software service related files
echo -e "${STEPS} Start syncing software service script..."
[[ -d "${share_path}" ]] || mkdir -p ${share_path}
svn export ${github_repo}/common-files${share_path} ${share_path} --force
[[ "${?}" -ne "0" ]] && error_msg "Sync [ ${github_repo}/common-files${share_path} ] scripts failed."
find ${share_path} -type f -name '*.sh' -exec chmod +x {} \;

[[ "${PLATFORM}" == "amlogic" ]] && {
# Update operation instruction and service related files
echo -e "${STEPS} Start syncing Amlogic platform specific scripts..."
svn export ${github_repo}/platform-files/amlogic/rootfs${sbin_path} ${sbin_path} --force
[[ "${?}" -ne "0" ]] && error_msg "Sync [ ${github_repo}/platform-files/amlogic/rootfs${sbin_path} ] scripts failed."
chmod +x ${sbin_path}/armbian-*

# Update openvfd related files
echo -e "${STEPS} Start syncing Amlogic platform openvfd service script..."
[[ -d "${openvfd_path}" ]] || mkdir -p ${openvfd_path}
svn export ${github_repo}/platform-files/amlogic/rootfs${openvfd_path} ${openvfd_path} --force
[[ "${?}" -ne "0" ]] && error_msg "Sync [ ${github_repo}/platform-files/amlogic/rootfs${openvfd_path} ] scripts failed."
chmod +x ${openvfd_path}/vfdservice
}

Expand Down
8 changes: 8 additions & 0 deletions build-armbian/armbian-files/common-files/usr/sbin/armbian-tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,14 @@ EOF

if [[ "${file_system_type}" == "btrfs" ]]; then
mkfs.btrfs -f -U ${ROOTFS_UUID} -L "${LB_PRE}DATA" -m single "/dev/${PT_PRE}3"
[[ "${?}" -eq "0" ]] || error_msg "Failed to format using [ mkfs.btrfs ]"
mount -t btrfs -o compress=zstd:6 "/dev/${PT_PRE}3" "${data_path}"
[[ "${?}" -ne "0" ]] && error_msg "Failed to mount [ /dev/${PT_PRE}3 ] partition."
else
mkfs.ext4 -F -q -U ${ROOTFS_UUID} -L "${LB_PRE}DATA" -b 4k -m 0 "/dev/${PT_PRE}3"
[[ "${?}" -eq "0" ]] || error_msg "Failed to format using [ mkfs.ext4 ]"
mount -t ext4 "/dev/${PT_PRE}3" "${data_path}"
[[ "${?}" -ne "0" ]] && error_msg "Failed to mount [ /dev/${PT_PRE}3 ] partition."
fi

# Add auto mount to /etc/fstab
Expand All @@ -149,16 +153,20 @@ expand_current_part() {
echo -e "${STEPS} Install growpart or xfsprogs expansion and formatting tool ... "
apt-get update
apt-get install cloud-guest-utils xfsprogs -y
[[ "${?}" -ne "0" ]] && error_msg "Dependency installation failed."

echo -e "${STEPS} Expansion Partition ... "
growpart /dev/${DISK_NAME} 2
[[ "${?}" -ne "0" ]] && error_msg "[ growpart ] operation failed."

echo -e "${STEPS} Expansion file system ... "
ROOTFS_TYPE="$(df -hT / | grep "/" | awk '{print $2}')"
if [[ "${ROOTFS_TYPE}" == "btrfs" ]]; then
btrfs filesystem resize max /
[[ "${?}" -ne "0" ]] && error_msg "[ btrfs ] operation failed."
else
resize2fs /dev/${ROOT_PTNAME}
[[ "${?}" -ne "0" ]] && error_msg "[ resize2fs ] operation failed."
fi

sync && sleep 3
Expand Down
13 changes: 10 additions & 3 deletions build-armbian/armbian-files/common-files/usr/sbin/armbian-update
Original file line number Diff line number Diff line change
Expand Up @@ -256,27 +256,29 @@ rescue_kernel() {
rm -rf config-* initrd.img-* System.map-* vmlinuz-* uInitrd* *Image dtb*
[[ "${PLATFORM}" == "amlogic" ]] && cp -rf /boot/{u-boot.ext,u-boot.emmc} -t . 2>/dev/null
cp -rf /boot/{*-${kernel_signature},uInitrd,*Image,dtb} -t .
[[ "$?" -ne "0" ]] && error_msg "(1/3) [ boot ] kernel files rescue failed."
[[ "${?}" -ne "0" ]] && error_msg "(1/3) [ boot ] kernel files rescue failed."
echo -e "${INFO} (1/3) [ boot ] kernel files rescue succeeded."

# 02. For /usr/lib/modules/${kernel_signature}
cd ${rescue_path}/rootfs/usr/lib/modules
rm -rf *
cp -rf /usr/lib/modules/${kernel_signature} -t .
[[ "$?" -ne "0" ]] && error_msg "(2/3) [ modules ] kernel files rescue failed."
[[ "${?}" -ne "0" ]] && error_msg "(2/3) [ modules ] kernel files rescue failed."
echo -e "${INFO} (2/3) [ modules ] kernel files rescue succeeded."

# 03. For /usr/src/linux-headers-${kernel_signature}
cd ${rescue_path}/rootfs/usr/src
rm -rf linux-headers-*
cp -rf /usr/src/linux-headers-${kernel_signature} -t .
[[ "$?" -ne "0" ]] && error_msg "(3/3) [ headers ] kernel files rescue failed."
[[ "${?}" -ne "0" ]] && error_msg "(3/3) [ headers ] kernel files rescue failed."
echo -e "${INFO} (3/3) [ headers ] kernel files rescue succeeded."

# Unmount the emmc partition
cd ${rescue_path}
umount -f ${rescue_path}/bootfs
[[ "${?}" -ne "0" ]] && error_msg "Failed to umount [ ${rescue_path}/bootfs ]"
umount -f ${rescue_path}/rootfs
[[ "${?}" -ne "0" ]] && error_msg "Failed to umount [ ${rescue_path}/rootfs ]"

sync && echo ""
}
Expand Down Expand Up @@ -401,6 +403,7 @@ backup_kernel() {
# 1. Pack the boot-*.tar.gz file
rm -rf *
cp -rf /boot/*-${current_kernel_signature} -t .
[[ "${?}" -ne "0" ]] && error_msg "(1/4) Failed to copy [ /boot/*-${current_kernel_signature} ] files."
rm -rf dtb*
chmod +x *
tar -czf boot-${current_kernel_signature}.tar.gz *
Expand All @@ -410,20 +413,23 @@ backup_kernel() {
# 2. Pack the dtb-*.tar.gz file
rm -rf *
cp -rf /boot/dtb/${PLATFORM}/* -t .
[[ "${?}" -ne "0" ]] && error_msg "(2/4) Failed to copy [ /boot/dtb/${PLATFORM}/* ] files."
tar -czf dtb-${PLATFORM}-${current_kernel_signature}.tar.gz *
mv -f *.tar.gz ${backup_path}/${current_kernel}
echo -e "${INFO} (2/4) The [ dtb-${PLATFORM}-${current_kernel_signature}.tar.gz ] backup successful."

# 3. Pack the header-*.tar.gz file
rm -rf *
cp -rf /usr/src/linux-headers-${current_kernel_signature}/* -t .
[[ "${?}" -ne "0" ]] && error_msg "(3/4) Failed to copy [ /usr/src/linux-headers-${current_kernel_signature}/* ] files."
tar -czf header-${current_kernel_signature}.tar.gz *
mv -f *.tar.gz ${backup_path}/${current_kernel}
echo -e "${INFO} (3/4) The [ header-${current_kernel_signature}.tar.gz ] backup successful."

# 4. Pack the modules-*.tar.gz file
rm -rf *
cp -rf /usr/lib/modules/${current_kernel_signature} -t .
[[ "${?}" -ne "0" ]] && error_msg "(4/4) Failed to copy [ /usr/lib/modules/${current_kernel_signature} ] files."
tar -czf modules-${current_kernel_signature}.tar.gz *
mv -f *.tar.gz ${backup_path}/${current_kernel}
echo -e "${INFO} (4/4) The [ modules-${current_kernel_signature}.tar.gz ] backup successful."
Expand Down Expand Up @@ -507,6 +513,7 @@ update_uboot() {
dd if="${BOOTLOADER_IMG}" of="${DEV_EMMC}" conv=fsync bs=1 count=444 2>/dev/null
dd if="${BOOTLOADER_IMG}" of="${DEV_EMMC}" conv=fsync bs=512 skip=1 seek=1 2>/dev/null
fi
[[ "${?}" -eq "0" ]] || error_msg "Failed to write bootloader using [ dd ]."

sync && echo ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,9 @@ create_partition() {
[[ -d "/usr/lib/u-boot" ]] || mkdir -p /usr/lib/u-boot
MYBOX_UBOOT="/usr/lib/u-boot/mybox-bootloader.img"
[[ -f "${MYBOX_UBOOT}" ]] && rm -f ${MYBOX_UBOOT}
echo -e "${INFO} Start backup default bootloader."
echo -e "${INFO} Start backing up the default bootloader."
dd if="${DEV_EMMC}" of="${MYBOX_UBOOT}" bs=1M count=4 conv=fsync
[[ "${?}" -eq "0" ]] || error_msg "Using dd to backup [ ${MYBOX_UBOOT} ] failed."

# Clear emmc disk data
exists_pts="$(parted ${DEV_EMMC} print 2>/dev/null | grep 'primary' | wc -l)"
Expand All @@ -339,7 +340,7 @@ create_partition() {
let i++
done
fi
dd if=/dev/zero of=${DEV_EMMC} bs=512 count=1 conv=fsync
#dd if=/dev/zero of=${DEV_EMMC} bs=512 count=1 conv=fsync

# Use the ampart partition tool
AMPART_STATUS="no"
Expand Down Expand Up @@ -388,6 +389,7 @@ create_partition() {
parted -s "${DEV_EMMC}" mklabel msdos
parted -s "${DEV_EMMC}" mkpart primary fat32 $((BLANK1))MiB $((BLANK1 + BOOT - 1))MiB
parted -s "${DEV_EMMC}" mkpart primary ${file_system_type} $((BLANK1 + BOOT + BLANK2))MiB 100%
[[ "${?}" -eq "0" ]] || error_msg "Failed to create partition using [ parted ]."

# Write bootloader
if [[ -n "${MAINLINE_UBOOT}" && -f "/usr/lib/u-boot/${MAINLINE_UBOOT}" && "${auto_mainline_uboot}" == "yes" ]]; then
Expand All @@ -399,28 +401,32 @@ create_partition() {
dd if="/usr/lib/u-boot/${BOOTLOADER_IMG}" of="${DEV_EMMC}" conv=fsync bs=1 count=444
dd if="/usr/lib/u-boot/${BOOTLOADER_IMG}" of="${DEV_EMMC}" conv=fsync bs=512 skip=1 seek=1
elif [[ -n "${MYBOX_UBOOT}" && -f "${MYBOX_UBOOT}" ]]; then
echo -e "${INFO} Restore the mybox bootloader: [ ${MYBOX_UBOOT} ]"
echo -e "${INFO} Write the mybox bootloader: [ ${MYBOX_UBOOT} ]"
dd if="${MYBOX_UBOOT}" of="${DEV_EMMC}" conv=fsync bs=1 count=444
dd if="${MYBOX_UBOOT}" of="${DEV_EMMC}" conv=fsync bs=512 skip=1 seek=1
fi
[[ "${?}" -eq "0" ]] || error_msg "Failed to write bootloader using [ dd ]."
}

# Copy bootfs partition files
copy_bootfs() {
cd /
echo -e "${STEPS} Start processing the bootfs partition..."
echo -e "${STEPS} Start processing the BOOTFS partition..."

PART_BOOT="${DEV_EMMC}p1"

if grep -q ${PART_BOOT} /proc/mounts; then
echo -e "${INFO} Unmounting BOOT partiton."
umount -f ${PART_BOOT}
[[ "${?}" -eq "0" ]] || error_msg "Failed to umount [ ${PART_BOOT} ]."
fi
echo -e "${INFO} Formatting BOOTFS partition."

echo -e "${INFO} Start formatting BOOTFS partition..."
mkfs.vfat -F 32 -n "BOOT_EMMC" ${PART_BOOT}
[[ "${?}" -eq "0" ]] || error_msg "Failed to format using [ mkfs.vfat ]."

mount -o rw ${PART_BOOT} ${DIR_INSTALL}
[[ "$?" -ne "0" ]] && error_msg "Failed to mount BOOTFS partition"
[[ "${?}" -ne "0" ]] && error_msg "Failed to mount BOOTFS partition."

echo -e "${INFO} Start copy BOOTFS partition data."
cp -rf /boot/* ${DIR_INSTALL}
Expand Down Expand Up @@ -475,6 +481,7 @@ EOF

sync && sleep 3
umount -f ${DIR_INSTALL}
[[ "${?}" -eq "0" ]] || error_msg "Failed to umount [ ${DIR_INSTALL} ]."
}

# Copy rootfs partition files
Expand All @@ -487,19 +494,23 @@ copy_rootfs() {
if grep -q ${PART_ROOT} /proc/mounts; then
echo -e "${INFO} Unmounting ROOT partiton."
umount -f ${PART_ROOT}
[[ "${?}" -eq "0" ]] || error_msg "Failed to umount [ ${PART_ROOT} ]."
fi

echo -e "${INFO} Formatting ROOTFS partition."
echo -e "${INFO} Start formatting ROOTFS partition..."
if [[ "${file_system_type}" == "btrfs" ]]; then
mkfs.btrfs -f -U ${ROOTFS_UUID} -L "ROOTFS_EMMC" -m single ${PART_ROOT}
sleep 3
[[ "${?}" -eq "0" ]] || error_msg "Failed to format using [ mkfs.btrfs ]"

mount -t btrfs -o compress=zstd:6 ${PART_ROOT} ${DIR_INSTALL}
[[ "${?}" -ne "0" ]] && error_msg "Failed to mount ROOTFS partition."
else
mkfs.ext4 -F -q -U ${ROOTFS_UUID} -L "ROOTFS_EMMC" -b 4k -m 0 ${PART_ROOT}
sleep 3
[[ "${?}" -eq "0" ]] || error_msg "Failed to format using [ mkfs.ext4 ]"

mount -t ext4 ${PART_ROOT} ${DIR_INSTALL}
[[ "${?}" -ne "0" ]] && error_msg "Failed to mount ROOTFS partition."
fi
[[ "$?" -ne "0" ]] && error_msg "Failed to mount ROOTFS partition"

echo -e "${INFO} Start copy ROOTFS partition data."
# Create relevant directories
Expand Down Expand Up @@ -574,6 +585,7 @@ EOF

sync && sleep 3
umount -f ${DIR_INSTALL}
[[ "${?}" -eq "0" ]] || error_msg "Failed to umount [ ${DIR_INSTALL} ]."
}

# Check script permission
Expand Down

0 comments on commit 7e09bec

Please sign in to comment.