diff --git a/makeself-header.sh b/makeself-header.sh index 17bf32d..fb6392b 100755 --- a/makeself-header.sh +++ b/makeself-header.sh @@ -1,29 +1,37 @@ cat << EOF > "$archname" -#!/bin/sh +#!/bin/bash # This script was generated using Makeself $MS_VERSION # The license covering this archive and its contents, if any, is wholly independent of the Makeself license (GPL) ORIG_UMASK=\`umask\` -if test "$KEEP_UMASK" = n; then - umask 077 -fi -CRCsum="$CRCsum" -MD5="$MD5sum" SHA="$SHAsum" SIGNATURE="$Signature" -TMPROOT=\${TMPDIR:=/tmp} +TMPROOT=\${TMPDIR:="/home/tmpdir"} +if ! test -d "\$TMPROOT"; then + TMPROOT="\$HOME" +fi +if ! test -d "\$TMPROOT"; then + TMPROOT="\$PWD" +fi +export TMPDIR="\$TMPROOT" USER_PWD="\$PWD" +if ! test -d "\$USER_PWD"; then + exit 1 +fi export USER_PWD ARCHIVE_DIR=\`dirname "\$0"\` export ARCHIVE_DIR +name_of_file="\$0 " +package_name=\`echo \$name_of_file | cut -d "/" -f2 | sed "s/.run//g" \` +pwd_of_file="\$PWD" label="$LABEL" script="$SCRIPT" scriptargs="$SCRIPTARGS" cleanup_script="${CLEANUP_SCRIPT}" licensetxt="$LICENSE" -helpheader="${HELPHEADER}" +helpheader='$HELPHEADER' targetdir="$archdirname" filesizes="$filesizes" totalsize="$totalsize" @@ -35,6 +43,13 @@ nodiskspace="n" export_conf="$EXPORT_CONF" decrypt_cmd="$DECRYPT_CMD" skip="$SKIP" +PACKAGE_LOG_NAME=makeself +readonly user_n=\$(whoami) +info_record_path="\$HOME/log/makeself" +info_record_file="makeself.log" +info_record_file_bak="makeself.log.bak" +log_file=\$info_record_path/\$info_record_file +LOG_SIZE_THRESHOLD=1024000 print_cmd_arg="" if type printf > /dev/null; then @@ -57,6 +72,55 @@ fi unset CDPATH +function rotate_log() { + check_path "\$log_file" + mv -f "\$log_file" "\$info_record_path/\$info_record_file_bak" + touch "\$log_file" 2>/dev/null + check_path "\$info_record_path/\$info_record_file_bak" + chmod 440 "\$info_record_path/\$info_record_file_bak" + check_path "\$log_file" + chmod 640 "\$log_file" +} +function check_path() { + if [ "\$1" != \$(realpath "\$1") ]; then + echo >&2 + echo "Log file is not support symlink, exiting!" >&2 + exit 1 + fi +} + +function log_check() { + local log_size + log_size=\$(find \$log_file -exec ls -l {} \; | awk '{ print \$5 }') + if [[ "\${log_size}" -ge "\${LOG_SIZE_THRESHOLD}" ]];then + rotate_log + fi +} + +# usage log "INFO" "this is message" +function log() { + if [ ! -d "\$info_record_path" ];then + mkdir -p "\$info_record_path" + chmod 750 "\$info_record_path" + fi + if [[ ! -f "\$log_file" ]];then + touch "\$log_file" + chmod 640 "\$log_file" + fi + # print log to log file + if [ -f "\$log_file" ]; then + log_check "\$log_file" + if ! echo -e "[\${PACKAGE_LOG_NAME}] [\${package_name}][\$(date +%Y%m%d-%H:%M:%S)] [\$user_n] [\$1] \$2" >>"\$log_file" + then + echo "can not write log, exiting!" >&2 + exit 1 + fi + else + echo "log file not exist, exiting!" >&2 + exit 1 + fi +} + MS_Printf() { \$print_cmd \$print_cmd_arg "\$1" @@ -92,7 +156,7 @@ MS_PrintLicense() MS_diskspace() { ( - df -k "\$1" | tail -1 | awk '{ if (\$4 ~ /%/) {print \$3} else {print \$4} }' + df -kP "\$1" | tail -1 | awk '{ if (\$4 ~ /%/) {print \$3} else {print \$4} }' ) } @@ -127,7 +191,7 @@ MS_dd_Progress() blocks=\`expr \$length / \$bsize\` bytes=\`expr \$length % \$bsize\` ( - dd ibs=\$offset skip=1 count=1 2>/dev/null + dd ibs=\$offset skip=1 2>/dev/null pos=\`expr \$pos \+ \$bsize\` MS_Printf " 0%% " 1>&2 if test \$blocks -gt 0; then @@ -157,40 +221,21 @@ MS_dd_Progress() MS_Help() { cat << EOH >&2 -Makeself version $MS_VERSION - 1) Getting help or info about \$0 : - \$0 --help Print this message - \$0 --info Print embedded info : title, default target directory, embedded script ... - \$0 --lsm Print embedded lsm entry (or no LSM) - \$0 --list Print the list of files in the archive - \$0 --check Checks integrity of the archive - \$0 --verify-sig key Verify signature agains a provided key id - - 2) Running \$0 : - \$0 [options] [--] [additional arguments to embedded script] - with following options (in that order) - --confirm Ask before running embedded script - --quiet Do not print anything except error messages - --accept Accept the license - --noexec Do not run embedded script (implies --noexec-cleanup) - --noexec-cleanup Do not run embedded cleanup script - --keep Do not erase target directory after running - the embedded script - --noprogress Do not show the progress during the decompression - --nox11 Do not spawn an xterm - --nochown Do not give the target folder to the current user - --chown Give the target folder to the current user recursively - --nodiskspace Do not check for available disk space - --target dir Extract directly to a target directory (absolute or relative) - This directory may undergo recursive chown (see --nochown). - --tar arg1 [arg2 ...] Access the contents of the archive through the tar command - --ssl-pass-src src Use the given src as the source of password to decrypt the data - using OpenSSL. See "PASS PHRASE ARGUMENTS" in man openssl. - Default is to prompt the user to enter decryption password - on the current terminal. - --cleanup-args args Arguments to the cleanup script. Wrap in quotes to provide - multiple arguments. - -- Following arguments will be passed to the embedded script\${helpheader} +Usage: \$0 [options] +Options: + --help | -h Print this message + --info Print embedded info : title, default target directory, embedded script ... + --list Print the list of files in the archive + --check Checks integrity and version dependency of the archive + --quiet | -q Quiet install mode, skip human-computer interactions + If the package requires an EULA, quiet installations are useful for scripting the installation + Using this option means accepting the EULA + --nox11 Do not spawn an xterm + --noexec Do not run embedded script + --extract= Extract directly to a target directory (absolute or relative) + Usually used with --noexec to just extract files without running + --tar arg1 [arg2 ...] Access the contents of the archive through the tar command +\${helpheader} EOH } @@ -200,7 +245,7 @@ MS_Verify_Sig() MKTEMP_PATH=\`exec <&- 2>&-; which mktemp || command -v mktemp || type mktemp\` test -x "\$GPG_PATH" || GPG_PATH=\`exec <&- 2>&-; which gpg || command -v gpg || type gpg\` test -x "\$MKTEMP_PATH" || MKTEMP_PATH=\`exec <&- 2>&-; which mktemp || command -v mktemp || type mktemp\` - offset=\`head -n "\$skip" "\$1" | wc -c | sed "s/ //g"\` + offset=\`head -n "\$skip" "\$1" | wc -c | tr -d " "\` temp_sig=\`mktemp -t XXXXX\` echo \$SIGNATURE | base64 --decode > "\$temp_sig" gpg_output=\`MS_dd "\$1" \$offset \$totalsize | LC_ALL=C "\$GPG_PATH" --verify "\$temp_sig" - 2>&1\` @@ -221,22 +266,14 @@ MS_Verify_Sig() MS_Check() { - OLD_PATH="\$PATH" - PATH=\${GUESS_MD5_PATH:-"\$OLD_PATH:/bin:/usr/bin:/sbin:/usr/local/ssl/bin:/usr/local/bin:/opt/openssl/bin"} - MD5_ARG="" - MD5_PATH=\`exec <&- 2>&-; which md5sum || command -v md5sum || type md5sum\` - test -x "\$MD5_PATH" || MD5_PATH=\`exec <&- 2>&-; which md5 || command -v md5 || type md5\` - test -x "\$MD5_PATH" || MD5_PATH=\`exec <&- 2>&-; which digest || command -v digest || type digest\` - PATH="\$OLD_PATH" - SHA_PATH=\`exec <&- 2>&-; which shasum || command -v shasum || type shasum\` test -x "\$SHA_PATH" || SHA_PATH=\`exec <&- 2>&-; which sha256sum || command -v sha256sum || type sha256sum\` if test x"\$quiet" = xn; then MS_Printf "Verifying archive integrity..." fi - offset=\`head -n "\$skip" "\$1" | wc -c | sed "s/ //g"\` - fsize=\`cat "\$1" | wc -c | sed "s/ //g"\` + offset=\`head -n "\$skip" "\$1" | wc -c | tr -d " "\` + fsize=\`cat "\$1" | wc -c | tr -d " "\` if test \$totalsize -ne \`expr \$fsize - \$offset\`; then echo " Unexpected archive size." >&2 exit 2 @@ -245,7 +282,6 @@ MS_Check() i=1 for s in \$filesizes do - crc=\`echo \$CRCsum | cut -d" " -f\$i\` if test -x "\$SHA_PATH"; then if test x"\`basename \$SHA_PATH\`" = xshasum; then SHA_ARG="-a 256" @@ -257,40 +293,12 @@ MS_Check() shasum=\`MS_dd_Progress "\$1" \$offset \$s | eval "\$SHA_PATH \$SHA_ARG" | cut -b-64\`; if test x"\$shasum" != x"\$sha"; then echo "Error in SHA256 checksums: \$shasum is different from \$sha" >&2 + log "ERROR" "Error in SHA256 checksums: \$shasum is different from \$sha" exit 2 elif test x"\$quiet" = xn; then MS_Printf " SHA256 checksums are OK." >&2 + log "INFO" "SHA256 checksums are OK." fi - crc="0000000000"; - fi - fi - if test -x "\$MD5_PATH"; then - if test x"\`basename \$MD5_PATH\`" = xdigest; then - MD5_ARG="-a md5" - fi - md5=\`echo \$MD5 | cut -d" " -f\$i\` - if test x"\$md5" = x00000000000000000000000000000000; then - test x"\$verb" = xy && echo " \$1 does not contain an embedded MD5 checksum." >&2 - else - md5sum=\`MS_dd_Progress "\$1" \$offset \$s | eval "\$MD5_PATH \$MD5_ARG" | cut -b-32\`; - if test x"\$md5sum" != x"\$md5"; then - echo "Error in MD5 checksums: \$md5sum is different from \$md5" >&2 - exit 2 - elif test x"\$quiet" = xn; then - MS_Printf " MD5 checksums are OK." >&2 - fi - crc="0000000000"; verb=n - fi - fi - if test x"\$crc" = x0000000000; then - test x"\$verb" = xy && echo " \$1 does not contain a CRC checksum." >&2 - else - sum1=\`MS_dd_Progress "\$1" \$offset \$s | CMD_ENV=xpg4 cksum | awk '{print \$1}'\` - if test x"\$sum1" != x"\$crc"; then - echo "Error in checksums: \$sum1 is different from \$crc" >&2 - exit 2 - elif test x"\$quiet" = xn; then - MS_Printf " CRC checksums are OK." >&2 fi fi i=\`expr \$i + 1\` @@ -311,6 +319,7 @@ MS_Decompress() if test \$? -ne 0; then echo " ... Decompression failed." >&2 + log "ERROR" "Decompression failed." fi } @@ -340,6 +349,22 @@ MS_cleanup() eval \$finish; exit 15 } +Script_Args_Check() +{ + script_supported_args=\$(echo \${helpheader} | grep -oE -e "--[^ ]+" | awk -F"=" {'print \$1'}) + arg_to_test=\$(echo \$1|awk -F"=" {'print \$1'}) + + for arg in \${script_supported_args}; + do + if test x"\$arg_to_test" = x"\$arg" ;then + return + fi + done + + MS_Help + exit 1 +} + finish=true xterm_loop= noprogress=$NOPROGRESS @@ -353,7 +378,7 @@ sig_key= initargs="\$@" -while true +while [ -n "\$*" ] do case "\$1" in -h | --help) @@ -365,10 +390,6 @@ do noprogress=y shift ;; - --accept) - accept=y - shift - ;; --info) echo Identification: "\$label" echo Target directory: "\$targetdir" @@ -397,34 +418,9 @@ do fi exit 0 ;; - --dumpconf) - echo LABEL=\"\$label\" - echo SCRIPT=\"\$script\" - echo SCRIPTARGS=\"\$scriptargs\" - echo CLEANUPSCRIPT=\"\$cleanup_script\" - echo archdirname=\"$archdirname\" - echo KEEP=$KEEP - echo NOOVERWRITE=$NOOVERWRITE - echo COMPRESS=$COMPRESS - echo filesizes=\"\$filesizes\" - echo totalsize=\"\$totalsize\" - echo CRCsum=\"\$CRCsum\" - echo MD5sum=\"\$MD5sum\" - echo SHAsum=\"\$SHAsum\" - echo SKIP=\"\$skip\" - exit 0 - ;; - --lsm) -cat << EOLSM -EOF -eval "$LSM_CMD" -cat << EOF >> "$archname" -EOLSM - exit 0 - ;; --list) echo Target directory: \$targetdir - offset=\`head -n "\$skip" "\$0" | wc -c | sed "s/ //g"\` + offset=\`head -n "\$skip" "\$0" | wc -c | tr -d " "\` for s in \$filesizes do MS_dd "\$0" \$offset \$s | MS_Decompress | UnTAR t @@ -433,9 +429,11 @@ EOLSM exit 0 ;; --tar) - offset=\`head -n "\$skip" "\$0" | wc -c | sed "s/ //g"\` + offset=\`head -n "\$skip" "\$0" | wc -c | tr -d " "\` arg1="\$2" shift 2 || { MS_Help; exit 1; } + log "INFO" "Start --tar process." + echo "Makeself logfile: \$log_file" for s in \$filesizes do MS_dd "\$0" \$offset \$s | MS_Decompress | tar "\$arg1" - "\$@" @@ -444,56 +442,27 @@ EOLSM exit 0 ;; --check) + echo "Makeself logfile: \$log_file" MS_Check "\$0" y - exit 0 - ;; - --verify-sig) - sig_key="\$2" - shift 2 || { MS_Help; exit 1; } - MS_Verify_Sig "\$0" - ;; - --confirm) - verbose=y - shift + scriptargs="\$scriptargs \$1" + shift ;; --noexec) script="" cleanup_script="" shift ;; - --noexec-cleanup) - cleanup_script="" - shift - ;; - --keep) + --extract=*) keep=y - shift - ;; - --target) - keep=y - targetdir="\${2:-.}" - shift 2 || { MS_Help; exit 1; } - ;; - --noprogress) - noprogress=y - shift - ;; + targetdir=\`echo \$1 | cut -d"=" -f2 \` + if ! shift; then MS_Help; exit 1; fi + log "INFO" "Extract files to targetdir." + echo "Makeself logfile: \$log_file" + ;; --nox11) nox11=y shift ;; - --nochown) - ownership=n - shift - ;; - --chown) - ownership=y - shift - ;; - --nodiskspace) - nodiskspace=y - shift - ;; --xwin) if test "$NOWAIT" = n; then finish="echo Press Return to close this window...; read junk" @@ -505,31 +474,20 @@ EOLSM copy=phase2 shift ;; - --ssl-pass-src) - if test x"$ENCRYPT" != x"openssl"; then - echo "Invalid option --ssl-pass-src: \$0 was not encrypted with OpenSSL!" >&2 - exit 1 - fi - decrypt_cmd="\$decrypt_cmd -pass \$2" - shift 2 || { MS_Help; exit 1; } - ;; - --cleanup-args) - cleanupargs="\$2" - shift 2 || { MS_Help; exit 1; } - ;; - --) - shift - break ;; - -*) - echo Unrecognized flag : "\$1" >&2 - MS_Help - exit 1 - ;; *) - break ;; + Script_Args_Check \$1 + scriptargs="\$scriptargs '\$1'" + shift + ;; esac done +quiet_para="" +if test x"\$quiet" = xy; then + quiet_para="--quiet " +fi +scriptargs="--\$name_of_file""--\"\$pwd_of_file\""" \$quiet_para""\$scriptargs" + if test x"\$quiet" = xy -a x"\$verbose" = xy; then echo Cannot be verbose and quiet at the same time. >&2 exit 1 @@ -556,7 +514,6 @@ copy) cp "\$0" "\$SCRIPT_COPY" chmod +x "\$SCRIPT_COPY" cd "\$TMPROOT" - export USER_PWD="\$tmpdir" exec "\$SCRIPT_COPY" --phase2 -- \$initargs ;; phase2) @@ -565,7 +522,7 @@ phase2) esac if test x"\$nox11" = xn; then - if test -t 1; then # Do we have a terminal on stdout? + if tty -s; then # Do we have a terminal? : else if test x"\$DISPLAY" != x -a x"\$xterm_loop" = x; then # No, but do we have X? @@ -577,7 +534,7 @@ if test x"\$nox11" = xn; then break fi done - chmod a+x \$0 || echo Please add execution rights on \$0 >&2 + chmod a+x \$0 || echo Please add execution rights on \$0 if test \`echo "\$0" | cut -c1\` = "/"; then # Spawn a terminal! exec \$XTERM -e "\$0 --xwin \$initargs" else @@ -607,7 +564,7 @@ else fi mkdir \$dashp "\$tmpdir" || { echo 'Cannot create target directory' \$tmpdir >&2 - echo 'You should try option --target dir' >&2 + echo 'You should try option --extract=' >&2 eval \$finish exit 1 } @@ -617,7 +574,7 @@ location="\`pwd\`" if test x"\$SETUP_NOCHECK" != x1; then MS_Check "\$0" fi -offset=\`head -n "\$skip" "\$0" | wc -c | sed "s/ //g"\` +offset=\`head -n "\$skip" "\$0" | wc -c | tr -d " "\` if test x"\$verbose" = xy; then MS_Printf "About to extract $USIZE KB in \$tmpdir ... Proceed ? [Y/n] " @@ -647,7 +604,6 @@ if test x"\$nodiskspace" = xn; then if test "\$leftspace" -lt $USIZE; then echo echo "Not enough space left in "\`dirname \$tmpdir\`" (\$leftspace KB) to decompress \$0 ($USIZE KB)" >&2 - echo "Use --nodiskspace option to skip this check and proceed anyway" >&2 if test x"\$keep" = xn; then echo "Consider setting TMPDIR to a directory with more free space." fi @@ -691,11 +647,19 @@ if test x"\$script" != x; then fi if test x"\$verbose" = x"y"; 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=\$?; - fi + yn="x" + while test x"\$yn" != x -a x"\$yn" != xy -a x"\$yn" != xY -a x"\$yn" != xn -a x"\$yn" != xN + do + 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=\$?; + elif test x"\$yn" = xn -o x"\$yn" = xN; then + echo "Unable to decompress \$script ,because of aborting! ";res=\$? + else + echo "Input value is unacceptable,please try again." + fi + done else eval "\"\$script\" \$scriptargs \"\\\$@\""; res=\$? fi