Skip to content

Commit

Permalink
script & args -> startup command, fix megastep#171
Browse files Browse the repository at this point in the history
* edit `makeself-header`:

  * change every `script` & `scriptargs` to `startup_command`

  * use `quote` (implemented in `makeself.sh`) to assign `startup_command`

  * change diagnostic references of "script" to "command"

* edit `makeself.sh`:

  * add Rich Felker's `quote` and `save`

  * move first instructions to follow last function definition

  * use `save` to assign `MS_COMMAND`

  * use `save` to assign `STARTUP_COMMAND`

* add `test/startupcommandtest` to test weird characters in files and startup
  commands
  • Loading branch information
realtime-neil committed Sep 16, 2019
1 parent 50fb888 commit ca26b3a
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 33 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ addons:
script:
- ./make-release.sh
- cd test
- "./appendtest"
- "./datetest"
- "./extracttest"
- "./startupcommandtest"
- "./suidtest"
- "./tarextratest"
- "./appendtest"
- "./whitespacetest"
- "./whitespacelicense"
- "./whitespacetest"
- cd ..
deploy:
provider: releases
Expand Down
27 changes: 13 additions & 14 deletions makeself-header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ TMPROOT=\${TMPDIR:=/tmp}
USER_PWD="\$PWD"; export USER_PWD
label="$LABEL"
script="$SCRIPT"
scriptargs="$SCRIPTARGS"
startup_command=$(quote "$STARTUP_COMMAND")
licensetxt="$LICENSE"
helpheader='$HELPHEADER'
targetdir="$archdirname"
Expand Down Expand Up @@ -311,10 +310,10 @@ do
fi
echo Date of packaging: $DATE
echo Built with Makeself version $MS_VERSION on $OSTYPE
echo Build command was: "$MS_COMMAND"
if test x"\$script" != x; then
echo Script run after extraction:
echo " " \$script \$scriptargs
echo Build command was: $MS_COMMAND
if test x"\$startup_command" != x; then
echo Command run after extraction:
echo " \$(echo \$startup_command | xargs)"
fi
if test x"$copy" = xcopy; then
echo "Archive will copy itself to a temporary location"
Expand All @@ -331,8 +330,7 @@ do
;;
--dumpconf)
echo LABEL=\"\$label\"
echo SCRIPT=\"\$script\"
echo SCRIPTARGS=\"\$scriptargs\"
echo STARTUP_COMMAND=\"\$startup_command\"
echo archdirname=\"$archdirname\"
echo KEEP=$KEEP
echo NOOVERWRITE=$NOOVERWRITE
Expand Down Expand Up @@ -590,12 +588,11 @@ fi
cd "\$tmpdir"
res=0
if test x"\$script" != x; then
if test x"\$startup_command" != x; then
if test x"\$export_conf" = x"y"; then
MS_BUNDLE="\$0"
MS_LABEL="\$label"
MS_SCRIPT="\$script"
MS_SCRIPTARGS="\$scriptargs"
MS_STARTUP_COMMAND="\$startup_command"
MS_ARCHDIRNAME="\$archdirname"
MS_KEEP="\$KEEP"
MS_NOOVERWRITE="\$NOOVERWRITE"
Expand All @@ -608,13 +605,15 @@ if test x"\$script" != x; then
MS_Printf "OK to execute: \$script \$scriptargs \$* ? [Y/n] "
read yn
if test x"\$yn" = x -o x"\$yn" = xy -o x"\$yn" = xY; then
eval "\"\$script\" \$scriptargs \"\\\$@\""; res=\$?;
eval "\$startup_command \"\\\$@\""; res=\$?
fi
else
eval "\"\$script\" \$scriptargs \"\\\$@\""; res=\$?
eval "\$startup_command \"\\\$@\""; res=\$?
fi
if test "\$res" -ne 0; then
test x"\$verbose" = xy && echo "The program '\$script' returned an error code (\$res)" >&2
if test x"\$verbose" = xy; then
echo "The command '\$startup_command' returned an error code (\$res)" >&2
fi
fi
fi
if test x"\$keep" = xn; then
Expand Down
36 changes: 19 additions & 17 deletions makeself.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,16 @@
# Self-extracting archives created with this script are explictly NOT released under the term of the GPL
#

MS_VERSION=2.4.0
MS_COMMAND="$0"
unset CDPATH
# Procedures

for f in "${1+"$@"}"; do
MS_COMMAND="$MS_COMMAND \\\\
\\\"$f\\\""
done
# https://www.etalabs.net/sh_tricks.html, "Shell-quoting arbitrary strings"
quote() { printf %s\\n "$1" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/" ; }

# For Solaris systems
if test -d /usr/xpg4/bin; then
PATH=/usr/xpg4/bin:$PATH
export PATH
fi

# Procedures
# https://www.etalabs.net/sh_tricks.html, "Working with arrays"
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}

MS_Usage()
{
Expand Down Expand Up @@ -163,6 +157,16 @@ MS_Usage()
exit 1
}

MS_VERSION=2.4.0
MS_COMMAND="$(save $0 $@)"
unset CDPATH

# For Solaris systems
if test -d /usr/xpg4/bin; then
PATH=/usr/xpg4/bin:$PATH
export PATH
fi

# Default settings
if type gzip 2>&1 > /dev/null; then
COMPRESS=gzip
Expand Down Expand Up @@ -459,10 +463,8 @@ else
fi

LABEL="$3"
SCRIPT="$4"
test "x$SCRIPT" = x || shift 1
shift 3
SCRIPTARGS="$*"
STARTUP_COMMAND="$(save $@)"
fi

if test "$KEEP" = n -a "$CURRENT" = y; then
Expand Down
64 changes: 64 additions & 0 deletions test/startupcommandtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash

THIS="$(readlink -f "$0")"
HERE="$(dirname "${THIS}")"
SUT="$(dirname "${HERE}")/makeself.sh"

testStartupCommand() {
(
export TMPDIR="$(mktemp -d "${PWD}/tmpdir.XXXXXX")"

local weirdname_list="$(mktemp -t weirdname_list.XXXXXX)"
cat >"${weirdname_list}" <<'EOF'
_!_exclamation_mark
_"_quotation_mark
_#_octothorp
_$_dollar
_%_percent
_&_ampersand
_'_apostrophe
_(_left_parenthesis
_)_right_parenthesis
_*_asterisk
_+_plus
_,_comma
_-_hyphen
_._full_stop
_:_colon
_;_semicolon
_<_less_than
_=_equals
_>_greater_than
_?_interrogative
_@_ampersat
_[_left_square_bracket
_\_reverse_solidus
_]_right_square_bracket
_^_caret
_{_left_bracket
_|_vertical_bar
_}_right_bracket
EOF

while read weirdname; do
local archive_dir="$(mktemp -dt archive_dir.XXXXXX)"
echo "${weirdname}" | tee "${archive_dir}/${weirdname}.txt"
local file_name="$(mktemp -ut "file_name.XXXXXX")"
"${SUT}" \
--nocomp --nox11 \
"${archive_dir}" "${file_name}" "The Label" "ls -lah ${weirdname}.txt"
assertEqual $? 0
"${file_name}" --list
assertEqual $? 0
"${file_name}" --info
assertEqual $? 0
"${file_name}" --dumpconf
assertEqual $? 0
"${file_name}"
assertEqual $? 0
done <"${weirdname_list}"
rm -rf "${TMPDIR}"
)
}

source "${HERE}/bashunit/bashunit.bash"

0 comments on commit ca26b3a

Please sign in to comment.