mirror of https://github.com/Phantop/appdwarf.git
zzexe: fix some performance issues on large files
This commit is contained in:
parent
49c5b59cfb
commit
4bf66c35dc
25
appdwarf
25
appdwarf
|
@ -36,9 +36,11 @@ unappimage() {
|
|||
|
||||
zzexe() {
|
||||
[ "$1" = "-p" ] && p="$2" && shift 2 # save prefix if present
|
||||
zstdmt -cq19 "$@" | ifne sponge "$1"
|
||||
printfunc zzexe_header | cat - "$1" | ifne sponge "$1"
|
||||
sed -i -e "2s/);$/${1##*[./]})/" -e "7s/^/$p /" "$1"
|
||||
tmp=$(mktemp) # make tmp file to avoid io operations
|
||||
printfunc zzexe_header | sed -e "2s/);$/${1##*[./]})/" -e "7s/^/$p /" > "$tmp"
|
||||
zstdmt -cq19 "$@" >> "$tmp"
|
||||
mv "$tmp" "$1"
|
||||
chmod +x "$1"
|
||||
exit
|
||||
}
|
||||
|
||||
|
@ -64,8 +66,12 @@ case "$1" in
|
|||
chmod +x "$2"
|
||||
exit ;;
|
||||
-d )
|
||||
awk 'f;/^exit \$res$/{f=1}' "$2" | head -c-1 | zstd -cd | ifne sponge "$2"
|
||||
d=dwarfs-root; dwarfsck -d0 -i"$2" && mkdir $d && dwarfsextract -o $d -i "$2"
|
||||
d=dwarfs-root # just to keep line shorter, extract if file is dwarfs
|
||||
dwarfsck -d0 -i"$2" && mkdir $d && dwarfsextract -o $d -i "$2" && exit
|
||||
tmp=$(mktemp) # make tmp file to avoid io operations
|
||||
awk 'f;/^exit \$res$/{f=1}' "$2" | head -c-1 | zstd -cd > "$tmp"
|
||||
mv "$tmp" "$2"
|
||||
chmod +x "$2"
|
||||
exit ;;
|
||||
-p )
|
||||
zzexe "$@" ;;
|
||||
|
@ -73,7 +79,7 @@ case "$1" in
|
|||
shift
|
||||
zzexe "$@" ;;
|
||||
--version | -v )
|
||||
tput setaf 2; echo appdwarf 2022.07.19
|
||||
tput setaf 2; echo appdwarf 2022.07.24
|
||||
tput setaf 6; echo Built by July 🏳️🌈; exit ;;
|
||||
-* | '' )
|
||||
echo "Usage: appdwarf [option] [APP/FILE/FOLDER/URL] [compression options]"
|
||||
|
@ -90,7 +96,7 @@ esac
|
|||
|
||||
if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
|
||||
if [ ! -f "$1" ]; then # file doesn't exist, see if this is a url
|
||||
if ! echo "$1" | grep / ; then # AppImageHub
|
||||
if ! echo "$1" | grep -q / ; then # AppImageHub
|
||||
echo "Checking AppImageHub for this program..."
|
||||
app=https://github.com/AppImage/appimage.github.io/raw/master/apps/$1.md
|
||||
shift
|
||||
|
@ -101,7 +107,7 @@ if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
|
|||
set -- "https://github.com/$app" "$@"
|
||||
fi
|
||||
|
||||
if echo "$1" | grep 'https://github.com/[^/]*/[^/]*/*$'; then # GitHub url
|
||||
if echo "$1" | grep -q 'https://github.com/[^/]*/[^/]*/*$'; then # GitHub url
|
||||
echo "Assuming this is a GitHub repo..."
|
||||
app="$(echo "${1%/}"/releases | sed 's|github.com|api.github.com/repos|')"
|
||||
shift
|
||||
|
@ -121,9 +127,8 @@ if [ ! -d "$1" ]; then # directory doesn't exist, see if this is an appimage
|
|||
rm -rf squashfs-root
|
||||
# this is a file, but it might be an existing dwarfs image
|
||||
if dwarfsck -d0 -i"$1"; then
|
||||
echo "Existing dwarfs image found. Adding header..."
|
||||
set -- "$@" --recompress=none
|
||||
elif unappimage "$1"; then
|
||||
elif file "$1" | grep -q ELF && unappimage "$1"; then
|
||||
echo "AppImage found. Converting..."
|
||||
app="$(basename "$1" .AppImage)"
|
||||
rm -rf "$1" "$app"
|
||||
|
|
Loading…
Reference in New Issue