#!/bin/sh ## ## SCRIPT: 02_extractFromSelf_code_forCat2tarfile_ofNautScrDirs.sh ## ## PURPOSE: This code extracts all the bytes after the bottom of this script --- ## after the 'exit' statement. Puts the bytes into a temp file. ## ## The code is the top part of a 'self-extracting install file'. ## ## To do the extraction of code from the data following the code, ## the code uses 'tail -n +LINENUM', where LINENUM is the ## number of lines to the bottom of this script, **PLUS 1**. ## ******* ## ******* NOTE!!! If you edit this script, check that LINENUM is set properly. ## ******* (After 2012may25, should be set automatically ## ******* by a 'grep -an' technique.) ## ## This script is meant to be concatenated with a gzipped tar file ## --- making a self-extracting script file. ## (The installer/user must assure that the new file is executable, ## say with chmod 755.) ## ## Example of making the self-extracting script file ## (continued onto a couple of lines): ## ## cat 02_extractFromSelf_code_forCat2tarfile_ofNautScrDirs.sh \ ## pkg_NautilusScriptsFE_yyyymmmdd.tar.gz \ ## > extractFromSelf_NautilusScriptsFE_yyyymmmdd.sh ## ## ***** NOTE: The INSTALLDIR variable below may one day have to be changed ## from ## $HOME/.gnome2/nautilus-scripts ## to ## $HOME/.gnome3/nautilus-scripts ## (or $HOME/.config/caja/scripts for the MATE desktop environment, ## in early 2012) ## ---------------------------------------------------------------------- ## To install on another machine, after downloading, use commands: ## ## 1) chmod 755 extractFromSelf_NautilusScriptsFE_yyyymmmdd.sh ## ## 2) ./extractFromSelf_NautilusScriptsFE_yyyymmmdd.sh ## ## That new, concatenated 'extractFromSelf' script file, when run, as ## indicated by steps 2 and 3 above, is supposed to extract the bytes of ## the tar-gzipped file and put it into a temp file, in /tmp. ## ## Then the 'extractFromSelf' script ungzips and untars the tar-gzipped file ## into an install directory --- $HOME/.gnome2/nautilus-scripts --- of ## the user running the 'extractFromSelf' script. ############################################################################## ## Started: 2010may02 As a rough outline. ## Changed: 2010aug22 Touched up for 2010aug22 release. ## Changed: 2010sep02 Touched up for 2010sep02 release. ## Changed: 2010sep06 Touched up for 2010sep06 release. ## Changed: 2010sep06 Touched up for 2010sep08 release. ## Changed: 2011may02 Touched up for 2011may02 release. ## Changed: 2011may17 Added copy of "${INSTALLDIR}/.set_DIR_NautilusScripts.shi" ## to "${DIR_DOTFREEDOM2}/set_DIR_NautilusScripts.shi" ## Added statements to make the INSTALLDIR subdirs. ## Changed: 2012mar01 Re-orged comments above. Touched up a few comments below. ## Changed: 2012may25 Added code to automatically set LINENUM. ## FOR DISPLAY, in a terminal, of the following statements as they execute: set -x #################################################################### ## We set the target INSTALLDIR for this application --- a directory ## on a user/installer's host. ALL of the following statements ## are generally independent of the release of Nautilus Scripts FE, ## but you should CHECK THEM before using this script. #################################################################### # INSTALLDIR="$HOME/.config/caja/scripts" INSTALLDIR="$HOME/.gnome2/nautilus-scripts" ############################################## ## Make the INSTALLDIR sub-directories, if the ## sub-directories do not exist. ############################################## DIR_HOMEGNOME="$HOME/.gnome2" if test ! -d "$DIR_HOMEGNOME" then mkdir "$DIR_HOMEGNOME" chmod 755 "$DIR_HOMEGNOME" fi DIR_HOMEGNOME_NS="${DIR_HOMEGNOME}/nautilus-scripts" if test ! -d "$DIR_HOMEGNOME_NS" then mkdir "$DIR_HOMEGNOME_NS" chmod 755 "$DIR_HOMEGNOME_NS" fi ############################################## ## If an FE Nautilus Script subdirectory like ## 'AUDIOtools' already exists in the install dir, ## exit. ############################################## if test -d "${DIR_HOMEGNOME_NS}/AUDIOtools" then echo " It appears that some previous 'feNautilusScripts' subdirectories (like AUDIOtools) already exist in the Nautilus scripts directory $DIR_HOMEGNOME_NS Aborting the install --- exiting the install script. Rename (or remove) the 'nautilus-scripts' directory --- for example, rename to 'nautilus-scripts_OLD_bkup' --- OR move the old FE Nautilus Scripts subdirectories and files out of the 'nautilus-scripts' directory. " read ANY_KEY_to_exit exit fi ####################################################### ## The following several statements are to extract the ## bottom of this self-extracting script file after the ## 'exit' statement (a tar file is to be concatenated ## after the 'exit' statement of this script) ## --- into a file like ## /tmp/TEMP_{appname}_tarfile.tgz ####################################################### OUTFILE="/tmp/TEMP_NautilusScriptsFE_tarfile.tgz" if test -f "$OUTFILE" then rm "$OUTFILE" fi ###################################################### ###################################################### ## NOTE!!! After all editing is done to this file, *** ## LINENUM var should be set to the number of lines to ## the 'exit' line of this file, PLUS ONE. *********** ## *************************************************** ## I.e. LINENUM should be the number of lines including ## the empty line after the last 'exit' line. I.e. there ## should be a line-feed immiediately after 'exit'. ## *************************************************** ## From 2012may25, LINENUM is set automatically by ## 'grep -an' and 'cut', according to the last line of ## this script, which contains only 'exit'. ###################################################### ###################################################### # LINENUM=216 # 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 ## installer/user 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 (bytes) of the extracted file. ## Is it the same size as reported for the original gzipped tar file?? ls -l "$OUTFILE" ## Check the table of contents ('t') of the extracted file. tar ztvf "$OUTFILE" ########################################################### ## EXTRACT the temp tar.gz file into the install directory. ########################################################### cd "$INSTALLDIR" if test -d "$INSTALLDIR" then tar zxvf "$OUTFILE" else read ANY_KEY_to_exit exit fi ############################################## ## Make the $HOME/.freedomenv/feNautilusScripts/ ## sub-directories --- for the ## 'set_DIR_NautilusScripts.shi' file, if the ## sub-directories do not exist. ## Copy the '.shi' file into that dir. ############################################## DIR_DOTFREEDOM="$HOME/.freedomenv" if test ! -d "$DIR_DOTFREEDOM" then mkdir "$DIR_DOTFREEDOM" chmod 755 "$DIR_DOTFREEDOM" fi DIR_DOTFREEDOM2="${DIR_DOTFREEDOM}/feNautilusScripts" if test ! -d "$DIR_DOTFREEDOM2" then mkdir "$DIR_DOTFREEDOM2" chmod 755 "$DIR_DOTFREEDOM2" fi if test -f "${DIR_DOTFREEDOM2}/set_DIR_NautilusScripts.shi" then rm "${DIR_DOTFREEDOM2}/set_DIR_NautilusScripts.shi" fi cp "${INSTALLDIR}/.set_DIR_NautilusScripts.shi" \ "${DIR_DOTFREEDOM2}/set_DIR_NautilusScripts.shi" read ANY_KEY_to_exit exit