Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced the old MD5 method with checkmd5. #61

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Template/COMMON/initrd/bin/checkmd5
Binary file not shown.
73 changes: 29 additions & 44 deletions Template/COMMON/initrd/init
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ TORAM_ALL_OTHER_FILES="boot EFI version"
LOG_FILE="$LOG_DIR/initrd.log"

MY_LOG=/init.log
CHECKMD5_LOG=/checkmd5.log
VID_DIR="/etc/live/version"
VID_FILE="$VID_DIR/linuxfs.ver"
MAKE_OLD="rootfs xtra deb xtra.tgz linuxfs.md5 state"
Expand Down Expand Up @@ -380,6 +381,9 @@ main_wrapper() {

write_log_files $MY_LOG $NEW_ROOT/$LOG_FILE
MY_LOG=$NEW_ROOT/$LOG_FILE.color
local new_checkmd5_log=$NEW_ROOT/$LOG_DIR/$(basename $CHECKMD5_LOG)
[ -f "$CHECKMD5_LOG" ] && cp -p "$CHECKMD5_LOG" "$new_checkmd5_log"
CHECKMD5_LOG=$new_checkmd5_log
[ "$NO_SAVE_LOGS" ] || copy_live_logs "$NEW_ROOT" "$LOG_DIR"

breakpoint b9 "Bash shell right before starting init"
Expand Down Expand Up @@ -5095,64 +5099,45 @@ check_vid() {
#------------------------------------------------------------------------------
check_md5()
{
local dir=$1 passed="passed" failed="failed"
local dir=$1
[ ! -d "$dir" ] && dir=$(echo $1 | sed 's|\(.*\)/.*|\1|')
dir=$(echo $dir | sed 's|/$||')
if ! [ -d "$dir" ]; then
msg $tbar
err "Directory %s does not exist" "$(fqe $1)"
err "Can't perform %s check" md5
err "Can't perform %s check" MD5
msg $tbar
return 0
fi

local fcnt=0
local fcnt=$(ls -1dp $dir/*.md5 | grep -v "/$" | wc -l)

vmsg 2 $tbar
#. Check <md5> of files in <some> directory
tsplash_alert_nc "$_Check_X_of_files_in_Y_directory_Please_be_patient_" md5 "$(fq $dir)"

local file fname md5_file file_md5 true_md5 error
for fname in $(ls $dir); do
file=$dir/$fname
local size=$(du -sm $file | cut -f1)
md5_file="$file.md5"
[ -f "$md5_file" -a -f "$file" ] || continue

local size_str="$nc_co($num_co$size$nc_co M)"
# vmsg 1
vmsg 1 $tbar
vmsg_nc 1 "$_file_X_" "${nc_co}$fname $size_str"
fcnt=$(( fcnt + 1 ))
true_md5="$(head -n 1 $md5_file | cut -d" " -f1)"

(bogo_meter)&
local pid=$!
file_md5=$(md5sum $file | cut -d" " -f1)
kill -9 $pid

if [ "$file_md5" == "$true_md5" ]; then
vmsg_nc 1 "$_result_X_" "${ok_co}$passed"
else
vmsg_nc 1 "$_result_X_" "${err_co}$failed"
error=true
fi

vmsg 6 " wanted: %s" "$num_co$true_md5"
vmsg 6 " got: %s" "$num_co$file_md5"
done
if tsplash_enabled; then
tsplash_alert_nc "$_Check_X_of_files_in_Y_directory_Please_be_patient_" MD5 "$(fq $dir)"
fi

vmsg 1
if [ "$fcnt" = 0 ]; then
#. No <md5> checksums were found in <directory>. Can't do any <md5> checks.
err "$_No_X_checksums_were_found_in_Y_Cant_do_any_Z_checks_" md5 "$(fqe $dir)" md5
elif [ "$error" ]; then
non_fatal "$_At_least_one_X_checksum_did_not_match_" md5
elif [ "$fcnt" = 1 ]; then
tsplash_alert "$_Success_The_file_passed_"
err "$_No_X_checksums_were_found_in_Y_Cant_do_any_Z_checks_" MD5 "$(fqe $dir)" MD5
else
#. Success! All <count> file(s) passed
tsplash_alert "$_Success_All_X_files_passed_" $(nq $fcnt)
# openvt does not pass the exit value through.
tsplash_enabled && local back_tty=$(fgconsole)
[ "$back_tty" != "" ] && chvt $MY_TTY
(cd "$dir" && checkmd5 --log=$CHECKMD5_LOG *.md5)
local rc=$?
[ "$back_tty" != "" ] && chvt $back_tty

if [ "$rc" = 1 ]; then
non_fatal "$_At_least_one_X_checksum_did_not_match_" MD5
elif [ "$rc" = 2 ]; then
tsplash_alert "$_The_integrity_check_was_aborted_"
elif [ "$rc" != 0 ]; then
non_fatal "$_The_integrity_check_could_not_be_completed_"
elif [ "$fcnt" = 1 ]; then
tsplash_alert "$_Success_The_file_passed_"
else
tsplash_alert "$_Success_All_X_files_passed_" $(nq $fcnt)
fi
fi
vmsg 2 $tbar
}
Expand Down
2 changes: 2 additions & 0 deletions Template/COMMON/initrd/live/locale/xlat/en/init.xlat
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ _The_default_is_="The default is"
_The_device_X_already_has_label_Y_="The device %s already has label %s"
_The_device_X_has_no_label_="The device %s has no label"
_The_entered_passphrase_does_not_match_="The entered passphrase does not match"
_The_integrity_check_could_not_be_completed_="The integrity check could not be completed."
_The_integrity_check_was_aborted_="The integrity check was aborted."
_The_limiting_factors_are_highlighted_in_X_="The limiting factors are highlighted in %s"
_The_module_directory_X_is_missing_="The module directory %s is missing"
_The_number_X_is_out_of_range_="The number <%s> is out of range"
Expand Down