Skip to content

Commit bc3dbbd

Browse files
committed
updated variable assignments, replaced tr operation with sed, improved terminal detection and error handling
1 parent 4d315b0 commit bc3dbbd

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

makeself-header.sh

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ script="$SCRIPT"
2323
scriptargs="$SCRIPTARGS"
2424
cleanup_script="${CLEANUP_SCRIPT}"
2525
licensetxt="$LICENSE"
26-
helpheader='$HELPHEADER'
26+
helpheader="${HELPHEADER}"
2727
targetdir="$archdirname"
2828
filesizes="$filesizes"
2929
totalsize="$totalsize"
@@ -92,7 +92,7 @@ MS_PrintLicense()
9292
MS_diskspace()
9393
{
9494
(
95-
df -kP "\$1" | tail -1 | awk '{ if (\$4 ~ /%/) {print \$3} else {print \$4} }'
95+
df -k "\$1" | tail -1 | awk '{ if (\$4 ~ /%/) {print \$3} else {print \$4} }'
9696
)
9797
}
9898
@@ -127,7 +127,7 @@ MS_dd_Progress()
127127
blocks=\`expr \$length / \$bsize\`
128128
bytes=\`expr \$length % \$bsize\`
129129
(
130-
dd ibs=\$offset skip=1 count=0 2>/dev/null
130+
dd ibs=\$offset skip=1 count=1 2>/dev/null
131131
pos=\`expr \$pos \+ \$bsize\`
132132
MS_Printf " 0%% " 1>&2
133133
if test \$blocks -gt 0; then
@@ -157,7 +157,7 @@ MS_dd_Progress()
157157
MS_Help()
158158
{
159159
cat << EOH >&2
160-
\${helpheader}Makeself version $MS_VERSION
160+
Makeself version $MS_VERSION
161161
1) Getting help or info about \$0 :
162162
\$0 --help Print this message
163163
\$0 --info Print embedded info : title, default target directory, embedded script ...
@@ -190,7 +190,7 @@ MS_Help()
190190
on the current terminal.
191191
--cleanup-args args Arguments to the cleanup script. Wrap in quotes to provide
192192
multiple arguments.
193-
-- Following arguments will be passed to the embedded script
193+
-- Following arguments will be passed to the embedded script\${helpheader}
194194
EOH
195195
}
196196
@@ -200,7 +200,7 @@ MS_Verify_Sig()
200200
MKTEMP_PATH=\`exec <&- 2>&-; which mktemp || command -v mktemp || type mktemp\`
201201
test -x "\$GPG_PATH" || GPG_PATH=\`exec <&- 2>&-; which gpg || command -v gpg || type gpg\`
202202
test -x "\$MKTEMP_PATH" || MKTEMP_PATH=\`exec <&- 2>&-; which mktemp || command -v mktemp || type mktemp\`
203-
offset=\`head -n "\$skip" "\$1" | wc -c | tr -d " "\`
203+
offset=\`head -n "\$skip" "\$1" | wc -c | sed "s/ //g"\`
204204
temp_sig=\`mktemp -t XXXXX\`
205205
echo \$SIGNATURE | base64 --decode > "\$temp_sig"
206206
gpg_output=\`MS_dd "\$1" \$offset \$totalsize | LC_ALL=C "\$GPG_PATH" --verify "\$temp_sig" - 2>&1\`
@@ -235,8 +235,8 @@ MS_Check()
235235
if test x"\$quiet" = xn; then
236236
MS_Printf "Verifying archive integrity..."
237237
fi
238-
offset=\`head -n "\$skip" "\$1" | wc -c | tr -d " "\`
239-
fsize=\`cat "\$1" | wc -c | tr -d " "\`
238+
offset=\`head -n "\$skip" "\$1" | wc -c | sed "s/ //g"\`
239+
fsize=\`cat "\$1" | wc -c | sed "s/ //g"\`
240240
if test \$totalsize -ne \`expr \$fsize - \$offset\`; then
241241
echo " Unexpected archive size." >&2
242242
exit 2
@@ -424,7 +424,7 @@ EOLSM
424424
;;
425425
--list)
426426
echo Target directory: \$targetdir
427-
offset=\`head -n "\$skip" "\$0" | wc -c | tr -d " "\`
427+
offset=\`head -n "\$skip" "\$0" | wc -c | sed "s/ //g"\`
428428
for s in \$filesizes
429429
do
430430
MS_dd "\$0" \$offset \$s | MS_Decompress | UnTAR t
@@ -433,7 +433,7 @@ EOLSM
433433
exit 0
434434
;;
435435
--tar)
436-
offset=\`head -n "\$skip" "\$0" | wc -c | tr -d " "\`
436+
offset=\`head -n "\$skip" "\$0" | wc -c | sed "s/ //g"\`
437437
arg1="\$2"
438438
shift 2 || { MS_Help; exit 1; }
439439
for s in \$filesizes
@@ -556,6 +556,7 @@ copy)
556556
cp "\$0" "\$SCRIPT_COPY"
557557
chmod +x "\$SCRIPT_COPY"
558558
cd "\$TMPROOT"
559+
export USER_PWD="\$tmpdir"
559560
exec "\$SCRIPT_COPY" --phase2 -- \$initargs
560561
;;
561562
phase2)
@@ -564,7 +565,7 @@ phase2)
564565
esac
565566
566567
if test x"\$nox11" = xn; then
567-
if tty -s; then # Do we have a terminal?
568+
if test -t 1; then # Do we have a terminal on stdout?
568569
:
569570
else
570571
if test x"\$DISPLAY" != x -a x"\$xterm_loop" = x; then # No, but do we have X?
@@ -576,7 +577,7 @@ if test x"\$nox11" = xn; then
576577
break
577578
fi
578579
done
579-
chmod a+x \$0 || echo Please add execution rights on \$0
580+
chmod a+x \$0 || echo Please add execution rights on \$0 >&2
580581
if test \`echo "\$0" | cut -c1\` = "/"; then # Spawn a terminal!
581582
exec \$XTERM -e "\$0 --xwin \$initargs"
582583
else
@@ -616,7 +617,7 @@ location="\`pwd\`"
616617
if test x"\$SETUP_NOCHECK" != x1; then
617618
MS_Check "\$0"
618619
fi
619-
offset=\`head -n "\$skip" "\$0" | wc -c | tr -d " "\`
620+
offset=\`head -n "\$skip" "\$0" | wc -c | sed "s/ //g"\`
620621
621622
if test x"\$verbose" = xy; then
622623
MS_Printf "About to extract $USIZE KB in \$tmpdir ... Proceed ? [Y/n] "

0 commit comments

Comments
 (0)