#!/bin/sh ## ## SCRIPT: 02_extractFromSelf_code_forCat2tarfile_ofTkGooiesDirs.sh ## ## PURPOSE: This code extracts all the bytes after the bottom of this script --- ## after the last 'exit' statement. This code puts those bytes into a ## temp file. ## Then this code ungzips and untars that temp file, into a ## specified install directory. Also this code puts a couple of ## 'script include' files (.shi, .tki) in a $HOME/.freedomenv ## subdirectory. And this code puts a link to a startup script ## in a $HOME/apps/bin directory. ## ## This code is intended to be the top part of a ## 'self-extracting install file'. ## ## METHOD: To do the extraction of data following this code, ## the code uses 'tail -n +$LINENUM', where LINENUM is the ## number of lines to the bottom of this script, **PLUS 1**. ## ## The value of LINENUM is set automatically by looking for ## the word 'exit' on a line by itself. That should be the ## last line of this script and the only such 5-character line. ## This code uses the following code to set LINENUM. ## LINENUM=`grep -an '^exit$' "$0" | cut -d: -f1` ## LINENUM=`expr $LINENUM + 1` ## ## See the code below for other details of the self-extracting ## and package-installing process. ## ## HOW TO MAKE THE 'SELF-EXTRACTING INSTALL FILE': ## ## This script is meant to be concatenated with a '.tar.gz' ## gzipped tar file --- by a package-maker person --- ## --- to make a 'self-extracting install file'. ## ## Example of the 'cat' command that the 'package-maker' ## can use to make the 'self-extracting install file': ## ## (The command is continued onto a couple of lines.) ## ## cat 02_extractFromSelf_code_forCat2tarfile_ofTkGooieDirs.sh \ ## pkg_tkGooies_linux_yyyymmmdd.tar.gz \ ## > extractFromSelf_tkGooies_linux_yyyymmmdd.sh ## ## The 'cat' output file is this script --- with a ## '.tar.gz' file concatenated. ## ## **** BEFORE MAKING THE SELF-EXTRACTING INSTALL FILE, ## **** CHECK THAT the appropriate RELEASE-DATE is set in the ## **** 'INSTALLDIR' variable below. ## (We could have this script prompt the package-maker ## for the release date to be used, but, for now, ## we avoid making prompts from this script.) ## ## HOW THE USER-INSTALLER USES THE 'SELF-EXTRACTING INSTALL FILE': ## ## To install on another computer system, after downloading, ## the user-installer can 'cd' to the download directory and ## use commands like: ## ## 1) chmod 755 extractFromSelf_tkGooies_linux_yyyymmmdd.sh ## ## (if installer-user needs to make the script executable) ## ## 2) ./extractFromSelf_tkGooies_linux_yyyymmmdd.sh ## ## More details of the download and install process are available on the ## web page 'tkGooies_FE_download.htm' at www.freedomenv.com/TkGooies. ## ## The concatenated 'extractFromSelf' file, when run, ## is supposed to extract the bytes of the tar-gzipped file that was ## put at the bottom of the self-extracting script code. ## The script puts the extracted bytes into a temp file, in /tmp. ## The bytes should be the bytes of a tar-gzipped file. ## ## Then the 'extractFromSelf' script ungzips and untars the tar-gzipped file ## into an install directory --- say, $HOME/apps/tkGooies_linux. ## ############################################################################## ## MAINTENANCE HISTORY: ## Started: 2015feb07 may02 As a rough outline. ## Changed: 2015 ############################################################################## ## FOR DISPLAY, in a terminal, of the following statements as they execute: set -x ################################################# ## Make the $HOME/apps dir for the user-installer, ## if none exists, at his/her machine. ################################################# DIR_HOMEAPPS="$HOME/apps" if test ! -d "$DIR_HOMEAPPS" then mkdir "$DIR_HOMEAPPS" chmod 755 "$DIR_HOMEAPPS" fi ############################################## ## If the dir $HOME/apps is not writable, exit ## --- something is wrong. Probably the user ## has a $HOME/apps dir with wrong permissions. ############################################## if test ! -w "$DIR_HOMEAPPS" then echo " No write permission to directory $DIR_HOMEAPPS. Exiting. " read ANY_KEY_to_exit exit fi #################################################################### ## We set the target INSTALLDIR for this application **********!!! ## --- a directory on a user/installer's host. **********!!! ## ## ** CHECK THIS STATEMENT (esp. release ID) **********!!! ## ** before using this script. **********!!! #################################################################### # INSTALLDIR="${DIR_HOMEAPPS}/tkGooies_2015feb08" INSTALLDIR="${DIR_HOMEAPPS}/tkGooies_linux_2015mar09" ############################################## ## If the $INSTALLDIR directory already exists, ## exit. ############################################## if test -d "$INSTALLDIR" then echo " The install directory $INSTALLDIR already exits. Aborting the install --- exiting the install script. Rename or remove the existing directory. " read ANY_KEY_to_exit exit fi ############################################## ## Make the $INSTALLDIR for the user, ## if none exists. ############################################## if test ! -d "$INSTALLDIR" then mkdir "$INSTALLDIR" chmod 755 "$INSTALLDIR" fi ################################################# ## The following several statements are to extract ## the data following the 'exit' statement of ## this script (a tar file concatenated to this ## script) --- at user install time --- ## into a file like ## /tmp/TEMP_[appname]_tarfile.tgz ################################################# OUTFILE="/tmp/TEMP_tkGooies_tarfile.tgz" if test -f "$OUTFILE" then rm "$OUTFILE" fi ###################################################### ###################################################### ## This is the code that extracts the bytes after ## the 'exit' statement at the bottom of this script, ## and puts those bytes into $OUTFILE. ## *************************************************** ## ## The OLD WAY of doing this (before using 'grep -an') ## was to use a text editor to determine the number of ## lines to the 'exit' line at the bottom of this file. ## Then the LINENUM var would be set to that number ## PLUS ONE. ## ## NOTE: LINENUM should be the number of lines including ## the empty line after the last 'exit' line. I.e. there ## should be a line-feed immediately after 'exit'. ###################################################### ###################################################### # LINENUM=326 # tail -n +$LINENUM "$0" > "$OUTFILE" LINENUM=`grep -an '^exit$' "$0" | cut -d: -f1` LINENUM=`expr $LINENUM + 1` tail -n +$LINENUM "$0" > "$OUTFILE" ############################################################# ## The following several statements are to help the ## user-installer check the validity & contents of the ## extracted tar-gzipped install file. ############################################################# ## Check the file type of the extracted file. ## Is it recognized as a gzipped tar?? file "$OUTFILE" ## Show the size (in bytes) of the extracted file. ## Is it the same size as reported, on the download web page, ## for the package-maker's gzipped tar file?? ls -l "$OUTFILE" ## Check the table of contents ('t') of the extracted ## '.tgz' file. tar ztvf "$OUTFILE" ########################################################### ## EXTRACT the temp '.tgz' file into the install directory. ## ## If for some reason the INSTALLDIR did not get created ## (above), indicate to the user-installer that he/she can ## press any key to exit this process. ########################################################### if test -d "$INSTALLDIR" then cd "$INSTALLDIR" tar zxvf "$OUTFILE" else read ANY_KEY_to_exit exit fi ############################################## ## Make the $HOME/.freedomenv/tkGooies/ dir ## and the $HOME/.freedomenv/common/ dir ## for the 'set_FEDIR.shi' file ## and the 'set_feDIR.tki' file, ## if the dirs do not exist. ## Copy the '.shi' & '.tki' files into the dirs. ############################################## DIR_DOTFREEDOM="$HOME/.freedomenv" if test ! -d "$DIR_DOTFREEDOM" then mkdir "$DIR_DOTFREEDOM" chmod 755 "$DIR_DOTFREEDOM" fi DIR_DOTFREEDOM1="${DIR_DOTFREEDOM}/common" if test ! -d "$DIR_DOTFREEDOM1" then mkdir "$DIR_DOTFREEDOM1" chmod 755 "$DIR_DOTFREEDOM1" fi DIR_DOTFREEDOM2="${DIR_DOTFREEDOM}/tkGooies" if test ! -d "$DIR_DOTFREEDOM2" then mkdir "$DIR_DOTFREEDOM2" chmod 755 "$DIR_DOTFREEDOM2" fi ## To avoid possibly changing '.shi' and '.tki' files of the same ## name, in the 'common' directory, that are used by other FE ## systems, we comment the copy to the 'common' directory, for now. # cp "${INSTALLDIR}/includes_sh/set_FEDIR.shi" "$DIR_DOTFREEDOM1" # cp "${INSTALLDIR}/includes_tk/set_feDIR.tki" "$DIR_DOTFREEDOM1" cp "${INSTALLDIR}/includes_sh/set_FEDIR.shi" "$DIR_DOTFREEDOM2" cp "${INSTALLDIR}/includes_tk/set_feDIR.tki" "$DIR_DOTFREEDOM2" ####################################################### ## Make the $HOME/apps/bin/ dir, if none exists. ## And make a soft-link to the application ## startup executable (script) in that 'bin' dir. ###################################################### DIR_APPS_BIN="$HOME/apps/bin" if test ! -d "$DIR_APPS_BIN" then mkdir "$DIR_APPS_BIN" chmod 755 "$DIR_APPS_BIN" fi STARTSCRIPT="tkGooies_start.sh" if test -f "${DIR_APPS_BIN}/$STARTSCRIPT" then rm "${DIR_APPS_BIN}/$STARTSCRIPT" fi ln -s -f "${INSTALLDIR}/scripts/$STARTSCRIPT" "${DIR_APPS_BIN}/$STARTSCRIPT" ########################################################### ## In case the installer-user is executing the ## 'self-extracting install script' in a window that will ## close when this script ends, the following 'read' ## statement will keep the window from closing --- and it ## will indicate to the user-installer that he/she can ## press any key to exit this process. ########################################################### read ANY_KEY_to_exit ############################################################# ## This is the 'exit' statement that the 'grep -an' statement ## above uses to determine the line number of the ## bottom of this script. ############################################################# exit