Replace awk with homemade select_word shell function

gf-arm64
FriendlyNeighborhoodShane 4 years ago
parent d8f05a2835
commit f3a1729558

@ -22,8 +22,21 @@ log() { echo "$1"; }
$bootmode || mount -o bind /dev/urandom /dev/random;
select_word() {
select_term="$1";
cat | while read -r select_line; do
select_current=0;
select_found="";
for select_each in $select_line; do
select_current="$(( $select_current + 1 ))";
[ "$select_current" = "$select_term" ] && { select_found="yes"; break; }
done;
[ "$select_found" = "yes" ] && echo "$select_each";
done;
}
file_getprop() {
grep "^$2" "$1" | head -n1 | awk '{ print $1 }' | cut -d= -f2;
grep "^$2" "$1" | head -n1 | select_word 1 | cut -d= -f2;
}
abort() {
@ -77,7 +90,7 @@ $bootmode || {
}
}
for bin in awk cat chcon chmod chown cp cut df du echo find grep head losetup ls mkdir mount ps rm sed tail touch umount unzip; do
for bin in cat chcon chmod chown cp cut df du echo find grep head losetup ls mkdir mount ps rm sed tail touch umount unzip; do
[ "$(which "$bin")" ] || abort "No $bin available";
done;
@ -142,7 +155,7 @@ sizecheck() {
break;
done;
[ -e "$sizeobject" ] || { echo 0; return 0; }
objectsize="$(du -s "$sizeobject" | awk '{ print $1 }')";
objectsize="$(du -s "$sizeobject" | select_word 1)";
libsize=0;
case "$sizeobject" in
*.apk)
@ -151,7 +164,7 @@ sizecheck() {
for archlib in $libarches; do
if [ "$(echo "$apkunzip" | grep "lib/$archlib/lib.*.so")" ]; then
libsizeb=0;
for entry in $(unzip -l "$sizeobject" | grep "lib/$archlib/lib.*.so" | awk '{ print $1 }'); do
for entry in $(unzip -l "$sizeobject" | grep "lib/$archlib/lib.*.so" | select_word 1); do
libsizeb="$(($libsizeb + $entry))";
done;
libsize="$(($libsizeb / 1024 + 1))";
@ -418,11 +431,11 @@ if [ "$action" = "installation" ]; then
packsizem="$(($packsize / 1024 + 1))";
log "Pack size is $packsizem";
if [ "$magisk" = "yes" ]; then
datfreem="$(($(df -Pk "/data" | tail -n 1 | awk '{ print $4 }') / 1024))";
datfreem="$(($(df -Pk "/data" | tail -n 1 | select_word 4) / 1024))";
log "Free data space is $datfreem";
[ "$datfreem" -lt "$packsizem" ] && abort "Not enough free space in your data!";
elif [ "$magisk" = "no" ]; then
sysfreem="$(($(df -Pk "/$sysroot/system" | tail -n 1 | awk '{ print $4 }') / 1024))";
sysfreem="$(($(df -Pk "/$sysroot/system" | tail -n 1 | select_word 4) / 1024))";
log "Free system space is $sysfreem";
[ "$sysfreem" -lt "$packsizem" ] && abort "Not enough free space in your system!";
fi;

@ -14,6 +14,19 @@ tmpdir="$workdir/tmp";
updatetime="$(date -u +%Y%m%d%H%M%S)";
updatelog="$reldir/update-$updatetime.log";
select_word() {
select_term="$1";
cat | while read -r select_line; do
select_current=0;
select_found="";
for select_each in $select_line; do
select_current="$(( $select_current + 1 ))";
[ "$select_current" = "$select_term" ] && { select_found="yes"; break; }
done;
[ "$select_found" = "yes" ] && echo "$select_each";
done;
}
echo " ";
echo "-- Minimal MicroG Update Script --";
echo "-- The Essentials Only MicroG Pack --";
@ -21,7 +34,7 @@ echo "-- From The MicroG Telegram group --";
echo "-- No, not the Official one --";
# Bin check
for bin in awk chmod cp curl grep head jq mv rm sort unzip wget; do
for bin in chmod cp curl grep head jq mv rm sort unzip wget; do
[ "$(which $bin)" ] || { echo " " >&2; echo "FATAL: No $bin found" >&2; return 1; }
done;
@ -57,7 +70,7 @@ $(echo "$stuff_download" | grep -Pi "^[ \t]*[^ \t]*$include[^ \t]*[ \t]+")
done;
stuff_download="$(echo "$stuff_download_new" | sort -u)";
repo_apps="$(echo "$stuff_download" | grep -P "^[ \t]*[^ \t]+[ \t]+repo[ \t]+")";
for repo in $(echo "$repo_apps" | awk '{ print $3 }'); do
for repo in $(echo "$repo_apps" | select_word 3); do
stuff_repo_new="$stuff_repo_new
$(echo "$stuff_repo" | grep -P "^[ \t]*$(dirname "$repo")[ \t]+" | head -n1)
";
@ -74,9 +87,9 @@ pre_update_actions;
echo " ";
echo " - Downloading repos...";
for repo in $(echo "$stuff_repo" | awk '{ print $1 }'); do
for repo in $(echo "$stuff_repo" | select_word 1); do
line="$(echo "$stuff_repo" | grep -P "^[ \t]*$repo[ \t]+" | head -n1)";
repourl="$(echo "$line" | awk '{ print $2 }')";
repourl="$(echo "$line" | select_word 2)";
[ "$repourl" ] || { echo "ERROR: Repo $repo has no URL" >&2; continue; }
echo " -- REPO: Downloading repo $repo";
wget -q --show-progress "$repourl/index-v1.jar" -O "$tmpdir/repos/$repo.jar";
@ -92,11 +105,11 @@ done;
echo " ";
echo " - Downloading assets...";
for object in $(echo "$stuff_download" | awk '{ print $1 }'); do
for object in $(echo "$stuff_download" | select_word 1); do
line="$(echo "$stuff_download" | grep -P "^[ \t]*$object[ \t]+" | head -n1)";
source="$(echo "$line" | awk '{ print $2 }')";
objectpath="$(echo "$line" | awk '{ print $3 }')";
objectarg="$(echo "$line" | awk '{ print $4 }')";
source="$(echo "$line" | select_word 2)";
objectpath="$(echo "$line" | select_word 3)";
objectarg="$(echo "$line" | select_word 4)";
[ "$objectpath" ] || { echo "ERROR: $object has no source arguments" >&2; continue; }
echo " -- ASSET: Downloading object $object from source $source";
case "$source" in
@ -114,7 +127,7 @@ for object in $(echo "$stuff_download" | awk '{ print $1 }'); do
;;
gitlab)
echo " ---- Getting GitLab project ID for $object";
objectid="$(curl -sN "https://gitlab.com/$objectpath" | grep "Project ID" | head -n1 | awk '{ print $3 }')";
objectid="$(curl -sN "https://gitlab.com/$objectpath" | grep "Project ID" | head -n1 | select_word 3)";
[ "$objectid" ] || { echo "ERROR: $object gitlab project ID not found" >&2; continue; }
echo " ---- Getting GitLab URL for $object";
objectupload="$(curl -sN "https://gitlab.com/api/v4/projects/$objectid/repository/tags" | jq -r '.[].release.description' | grep -Po "(/uploads/[^()]*$objectarg)" | head -n1 | tr -d "()")";
@ -125,8 +138,8 @@ for object in $(echo "$stuff_download" | awk '{ print $1 }'); do
objectrepo="$(dirname "$objectpath")";
objectpackage="$(basename "$objectpath")";
[ "$objectarg" ] && {
objectarch="$(echo "$objectarg" | awk -F":" '{ print $1 }')";
objectsdk="$(echo "$objectarg" | awk -F":" '{ print $2 }')";
objectarch="$(echo "$objectarg" | sed "s|:| |g" | select_word 1)";
objectsdk="$(echo "$objectarg" | sed "s|:| |g" | select_word 2)";
}
[ "$objectrepo" ] && [ "$objectpackage" ] || { echo "ERROR: $object has no valid repo arguments" >&2; continue; }
[ -f "$tmpdir/repos/$objectrepo.json" ] || { echo "ERROR: $object repo $objectrepo does not exist" >&2; continue; }

Loading…
Cancel
Save