Sometimes to share a tool with others, but also need to provide more documents;
If sharing a compressed package also have to teach each other how to extract, execute which script, feel the need to transfer more content is inconvenient;
A few shell scripts and files packaged into a "separate executable", the other party received this file, only need to execute this file, you can extract, execute the corresponding script, relatively convenient;
#!/bin/bash- #===============================================================================# # File:shell_pack.SH# # USAGE:./shell_pack.SH# # DESCRIPTION: # # OPTIONS:---# REQUIREMENTS:---# BUGS:---# NOTES:---# AUTHOR:LWQ (28120), [email protected]# ORGANIZATION: # CREATED:Geneva/ A/ - Geneva: -: onPM cst# REVISION:---#===============================================================================#= = = FUNCTION ================================================================# name:usage# Description:display usage information.#===============================================================================functionusage () {Cat<<-EOT Usage: $0-P Package-s script file1 file2 file3. Options:-h|Help Display This message-p|Package the output package name-s|Script the script would run when unpack package and the all files what are want to Packeot} #----------End offunctionUsage----------#-----------------------------------------------------------------------# Handle command line arguments#----------------------------------------------------------------------- whileGetopts": hp:s:"opt Do Case$optinchh|HELP) usage; Exit0 ;; P|package) package_name=$OPTARG;; S|script) install_script=$OPTARG;; \? )Echo-E"\ Option does not exist: $OPTARG \ n"The usage; exit1 ;; Esac#---End of Case--- DoneShift$ ($OPTIND-1))if[[-Z $package _name]]; Then Echo "package_name can ' t not be empty"Usage Exitfiif[[-Z $package _name]]; Then Echo "Install_script can ' t not be empty"Usage ExitfiFiles=[Email Protected]generate_wrapper_script () {Local Install_script=$1Local Wrapper_script=$2 Cat<<-'EOT'>$wrapper _script#!/bin/SHEcho "begin ..."Unpackdir=/tmp/$ (basename$0) _unpackRM-RF $unpackdir2>/dev/NULLmkdir-P $unpackdirEcho "Unpacking ..."sed '1,/^ #__SCRIPTEND__/d'$0|TarZXF--C $unpackdirif[$?-ne0]; Then Echo "Unpack package failed."Exit1fiEcho ""Echo "Installing ..."CD $unpackdirEOTCat<<-eor >>$wrapper _scriptchmod+x $install _script./$install _scripteorCat<<-'EOE'>>$wrapper _scriptif[$?-ne0]; Then Echo "install failed."Exit2elif[-D $unpackdir]; Then RM-RF $unpackdirfiEcho "install OK, enjoy!"Exit0#__SCRIPTEND__EOE}tarfile=Package_content_$$.tgzwrapfile=wrap_$$.SHEcho-E"start packing. \ n"Tarzcvf $tarfile $files $install _scriptgenerate_wrapper_script $install _script $wrapfileCat$wrapfile $tarfile >$package _namechmod+x $package _nameEcho-E"\noutput: $package _name\n"RM-F $tarfileRM-F $wrapfile
The contents of the file are saved to shell_pack.sh, using the method Example:
./shell_pack.sh-p logcat_install-s logcat_install.sh logcat_all.sh logcat_wrapper.sh vmstat2
The executable file "Logcat_install" will be generated, and when executing Logcat_install, the tar.gz file within its own file will be decompressed and the key script executed logcat_install.sh
〖linux〗 simply package the shell and some files into a separate "executable file"