Permalink
Browse files

framework: remove older 'bashisms', 'local' isn't POSIX-compliant

  • Loading branch information...
PeterPawn committed Oct 31, 2018
1 parent 8dc525d commit a765f5e37e3c98e4fc334653c4421613f16f9a45
Showing with 34 additions and 40 deletions.
  1. +22 −24 framework/implant_public_key
  2. +12 −16 framework/unpack_squashfs
@@ -120,46 +120,44 @@ progress()
# #
#######################################################################################################
check_modulus()
{
local modulus="$1"
local key_size=1024
local bytes=$(( key_size / 8 ))
(
modulus="$1"
key_size=1024
bytes=$(( key_size / 8 ))
if [ ${#modulus} -ne $(( bytes * 2 )) ]; then
if [ "$(expr \( "$modulus" : "\(..\).*" \) )" = "00" ] && [ ${#modulus} -ne $(( ( bytes + 1 ) * 2 )) ]; then
return 1
exit 1
fi
fi
if [ "$(expr \( "$modulus" : "\([0-9a-f]*\)" \) )" = "$modulus" ]; then
return 0
exit 0
fi
return 1
}
exit 1
)
#######################################################################################################
# #
# find free directory #
# #
#######################################################################################################
is_directory_a_mountpoint()
{
local dir="$1"
[ "$(sed -n -e "s|^[^ ]* \($dir\) .*$|\1|p" $procfs_mounts)" = "$dir" ] && return 0
return 1
}
(
dir="$1"
[ "$(sed -n -e "s|^[^ ]* \($dir\) .*$|\1|p" $procfs_mounts)" = "$dir" ] && exit 0
exit 1
)
#######################################################################################################
# #
# find the next usable key file name #
# #
#######################################################################################################
get_key_index()
{
local exists=$1
local index=$2
local name
local i
(
exists=$1
index=$2
if [ $exists -eq 0 ]; then
if ! [ -f $key_location/$plugin_pubkey_mask ] && ! [ -h $key_location/$plugin_pubkey_mask ]; then
printf "%u" $(( index + 1 ))
return 0
exit 0
fi
while [ $index -ge $pubkey_min ]; do
name="$(printf "$pubkey_mask" $index)"
@@ -168,17 +166,17 @@ get_key_index()
continue
fi
printf "%u" $index
return 0
exit 0
done
printf "-1"
return 1
exit 1
else
while [ $index -ge $pubkey_min ]; do
name="$(printf "$pubkey_mask" $index)"
if [ -f $key_location/$name ] && ! [ -h $key_location/$name ]; then
if ! [ "$(sed -n -e "s|^[^ ]* \($key_location/$name\) .*|\1|p" $procfs_mounts)" = "$key_location/$name" ]; then
printf "%u" $index
return 0
exit 0
fi
fi
index=$(( index - 1 ))
@@ -191,8 +189,8 @@ get_key_index()
done
fi
printf "-1"
return 1
}
exit 1
)
#######################################################################################################
# #
# check mode parameter #
@@ -134,9 +134,8 @@ is_puma_based_device()
#######################################################################################################
is_active_mountpoint()
{
local line
line="$(sed -n -e "\|^[0-9]\+ [0-9]\+ [0-9:]* [^ ]* $1 .* - .*|p" "$mount_info")"
[ ${#line} -eq 0 ] && return 1 || return 0
__line="$(sed -n -e "\|^[0-9]\+ [0-9]\+ [0-9:]* [^ ]* $1 .* - .*|p" "$mount_info")"
[ ${#__line} -eq 0 ] && return 1 || return 0
}
#######################################################################################################
# #
@@ -145,10 +144,9 @@ is_active_mountpoint()
#######################################################################################################
get_filesystem_device()
{
local line
line="$(sed -n -e "\|^[0-9]\+ [0-9]\+ [0-9:]* [^ ]* $1 .* - .*|p" "$mount_info")"
[ ${#line} -eq 0 ] && exit 1
set -- $line
__line="$(sed -n -e "\|^[0-9]\+ [0-9]\+ [0-9:]* [^ ]* $1 .* - .*|p" "$mount_info")"
[ ${#__line} -eq 0 ] && exit 1
set -- $__line
while [ $# -gt 0 ]; do
[ "$1" = "-" ] && printf "%s" "$3" && exit 0
shift
@@ -193,30 +191,28 @@ get_update_image_name()
#######################################################################################################
get_filesystem()
{
local name
local mtd
if is_puma_based_device; then
eval name="\$puma_filesystem_name_$1"
sed -n -e "s|^${name}=\(.*\)|\1|p" "$puma_partitions"
eval __name="\$puma_filesystem_name_$1"
sed -n -e "s|^${__name}=\(.*\)|\1|p" "$puma_partitions"
return 0
elif [ "$(get_system_type)" = "VR9" ]; then
if [ -d "$vr9_wrapper" ]; then
if [ "$1" = "active" ]; then
printf "%s/%s" "$vr9_wrapper" "$vr9_root_filesystem"
return 0
elif [ "$1" = "inactive" ]; then
name="$(eval printf "\$filesystem_name" "\$$1_prefix")"
mtd="$(printf "$mtd_block_name" "$(get_mtd_number "$name")")"
printf "mount:%s:%s" "$mtd" "$vr9_root_filesystem"
__name="$(eval printf "\$filesystem_name" "\$$1_prefix")"
__mtd="$(printf "$mtd_block_name" "$(get_mtd_number "$__name")")"
printf "mount:%s:%s" "$__mtd" "$vr9_root_filesystem"
return 0
fi
else
printf "Missing YAFFS2 wrapper directory for VR9-based device.\n" 1>&2
exit 1
fi
elif [ "$(get_system_type)" = "GRX500" ]; then
name="$(eval printf "\$filesystem_name" "\$$1_prefix")"
printf "$mtd_block_name" "$(get_mtd_number "$name")"
__name="$(eval printf "\$filesystem_name" "\$$1_prefix")"
printf "$mtd_block_name" "$(get_mtd_number "$__name")"
return 0
fi
printf "Unknown and therefore unsupported system found.\n" 1>&2

0 comments on commit a765f5e

Please sign in to comment.