Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
add some nicer colorisation to compress-diskimg.sh (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sparkles-Laurel authored Oct 23, 2023
1 parent 30d5453 commit 15c1a6f
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions compress-diskimg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,57 @@
# compresses the popcorn disk image with zstd
# using compression level 19

# colors
declare -A COLORS;

COLORS[error]='\e[1;31m';
COLORS[info]='\e[1m';
COLORS[verbose]='\e[1;36m';
COLORS[reset]='\e[0m';

# check if `zstd` is present
if ! command -v zstd; then
echo -e "\e[1;31merror:\e[0m command \"zstd\" is not present" 1>&2;
echo -e "[${COLORS[error]}ERROR${COLORS[reset]}] command \"zstd\" is not present" 1>&2;
exit 1;
fi

# check if `cargo` is present
if ! command -v cargo; then
echo -e "\e[1;31merror:\e[0m command \"cargo\" is not present" 1>&2;
echo -e "[${COLORS[error]}ERROR${COLORS[reset]}] command \"cargo\" is not present" 1>&2;
exit 2;
fi

# check if `cargo bootimage` is present
if ! command -v bootimage; then
echo -e "\e[1;31merror:\e[0m cargo subcommand \"bootimage\" is not present" 1>&2;
echo -e "[${COLORS[error]}ERROR${COLORS[reset]}] cargo subcommand \"bootimage\" is not present" 1>&2;
exit 3;
fi

# if all checks have passed, start building the kernel image
# display the logo header first
echo "compress-diskimg.sh - Compresses a bootable popcorn disk image";
echo "Copyright (c) 2023 The popcorn Project. See LICENSE for more information";
echo "";

echo -e "\e[1m[INFO]\e[0m building disk image...";
echo -e "\e[1m[\e[1;36mEXEC\e[0m\e[1m]\e[0m cargo -v bootimage -v";
echo -e "${COLORS[info]}[INFO]${COLORS[reset]} building disk image...";
echo -e "${COLORS[info]}[${COLORS[verbose]}EXEC${COLORS[reset]}${COLORS[info]}]${COLORS[reset]} cargo -v bootimage -v";
# build the bootimage with verbose output
cargo -v bootimage -v;
exec cargo -v bootimage -v;

if [ $? != 0 ]; then
echo -e "\e[1;31merror:\e[0m \"cargo bootimage\" has failed." 2>&1;
echo -e "[${COLORS[error]}ERROR${COLORS[reset]}] \"cargo bootimage\" has failed." 2>&1;
exit $(($? + 10));
fi

echo "";
echo -e "\e[1m[INFO]\e[0m compressing disk image...";
echo -e "${COLORS[info]}[INFO]${COLORS[reset]} compressing disk image...";
# compress the disk image, with verbose output
echo -e "\e[1m[\e[1;36mEXEC\e[0m\e[1m]\e[0m yes | zstd -vz19o target/x86_64-arch/debug/bootimage-popcorn.bin.zst target/x86_64-arch/debug/bootimage-popcorn.bin";
yes | zstd -vz19o target/x86_64-arch/debug/bootimage-popcorn.bin.zst target/x86_64-arch/debug/bootimage-popcorn.bin;
echo -e "${COLORS[info]}[${COLORS[verbose]}EXEC${COLORS[reset]}${COLORS[info]}]${COLORS[reset]} yes | zstd -vz19o target/x86_64-arch/debug/bootimage-popcorn.bin.zst target/x86_64-arch/debug/bootimage-popcorn.bin";
exec yes | zstd -vz19o target/x86_64-arch/debug/bootimage-popcorn.bin.zst target/x86_64-arch/debug/bootimage-popcorn.bin;
if [ $? != 0 ]; then
echo -e "\e[1;31merror:\e[0m \"zstd -vz19o target/x86_64-arch/debug/bootimage-popcorn.bin.zst target/x86_64-arch/debug/bootimage-popcorn.bin\" failed" 2>&1;
echo -e "[${COLORS[error]}ERROR${COLORS[reset]}] \"zstd -vz19o target/x86_64-arch/debug/bootimage-popcorn.bin.zst target/x86_64-arch/debug/bootimage-popcorn.bin\" failed" 2>&1;
exit $(($? + 20));
fi

# the disk image has been compressed. exit is safe
echo -e "\e[1m[INFO]\e[0m Compressed disk image successfully, written to \"target/x86_64-arch/debug/bootimage-popcorn.bin.zst\"";
echo -e "${COLORS[info]}[INFO]${COLORS[reset]} Compressed disk image successfully, written to \"target/x86_64-arch/debug/bootimage-popcorn.bin.zst\"";

# i mean those who work on popcorn must be nocturnal people so...
echo -e "\e[1m[INFO]\e[0m popcorn project wishes you a nice day!";
echo -e "${COLORS[info]}[INFO]${COLORS[reset]} popcorn project wishes you a nice day!";
exit 0;

0 comments on commit 15c1a6f

Please sign in to comment.