(custom-set-variables
;; custom-set-variables was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(auto-compression-mode t nil (jka-compr))
'(case-fold-search t)
'(column-number-mode t)
'(current-language-environment "UTF-8")
'(default-input-method "rfc1345")
'(global-font-lock-mode t nil (font-lock))
'(size-indication-mode t)
'(transient-mark-mode t)
'(truncate-lines t))
(custom-set-faces
;; custom-set-faces was added by Custom -- don't edit or cut/paste it!
;; Your init file should contain only one such instance.
'(linum ((t (:inherit (default default) :background "white" :foreground "black")))))
;;(top . 20) (left . 20)
;;(setq default-frame-alist
;; '((width . 100) (height . 80)
;; (font . "-adobe-courier-medium-r-normal--17-120-100-100-m-100-iso8859-1")))
(put 'dired-find-alternate-file 'disabled nil)
;; Add F12 to toggle line wrap
(setq line-number-mode t)
(setq column-number-mode t)
; turn off tool bar
(if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
(add-hook 'window-configuration-change-hook
(lambda ()
(setq frame-title-format
(concat
invocation-name "@" system-name ": "
(replace-regexp-in-string
(concat "/home/" user-login-name) "~"
(or buffer-file-name "%b"))))))
(put 'upcase-region 'disabled nil)
;;(setq w32-enable-synthesized-fonts t)
;;(set-default-font "-outline-Verdana-normal-r-normal-normal-15-112-96-96-p-*-iso8859-1")
(put 'downcase-region 'disabled nil)
(setq-default ispell-program-name "aspell")
(setq-default indent-tabs-mode nil)
;; repeat last command
(global-set-key [(control z)] 'repeat)
;; repeat last command
(global-set-key [(control j)] 'join-line)
;; Enable backup files.
(setq make-backup-files t)
;; Enable versioning with default values (keep five last versions, I think!)
(setq version-control t)
;; Save all backup file in this directory.
(setq backup-directory-alist (quote ((".*" . "/app/skathirvel/emacs_backups/"))))
;; ===== Set the highlight current line minor mode =====
;; In every buffer, the line which contains the cursor will be fully
;; highlighted
;;(global-hl-line-mode t)
;; show line numbers of left hand side; needs linum.el where .emacs file is
;; I was wondering if there is way to change the color of the line numbers e.g change color/change backgroun
;;:Try M-x customize-face RET linum. Also try M-x global-linum-mode, or append (add-hook ‘find-file-hook (la
;;(add-to-list 'default-frame-alist '(font . "-adobe-courier-bold-r-normal--14-140-75-75-m-90-iso8859-1"))
;;Sets the tab size to four spaces
(setq-default tab-width 2)
(setq default-truncate-lines t)
(set-scroll-bar-mode 'right)
;; Open a file
(global-set-key [(control o)] 'find-file)
;; Close
(global-set-key [(control w)] 'kill-this-buffer)
;; goto-line
(global-set-key [(control l)] 'goto-line)
;; clear buffer
(global-set-key [f1] 'list-bookmarks)
;;close all buffers
;;(global-set-key [(control f1)] 'close-all-buffers)
;; Save
(global-set-key [f2] 'bookmark-set)
(global-set-key [(shift f2)] 'write-file )
(global-set-key [f3] 'query-replace-regexp)
(global-set-key [shift f3] 'isearch-backward)
;; search regex forward
(global-set-key [f4] 'isearch-forward-regexp)
;; search regex backward
(global-set-key [(shift f4)] 'isearch-backward-regexp)
;; Indent
;;(global-set-key [f4] 'indent-region)
(load-file "~/ibuffer.el")
(require 'ibuffer)
;; Term and shell
;; Toggle between two windows
(global-set-key [f5] 'ibuffer)
(global-set-key [f6] 'buffer-menu-other-window)
(global-set-key [f7] 'other-window)
(global-set-key [f8] 'delete-window)
(global-set-key [(shift f8)] 'delete-other-windows)
(global-set-key [f9] 'find-dired)
(global-set-key [(kbd "C-c-o")] 'occur)
;; frames (create and delete)
(global-set-key [f10] 'make-frame-command)
(global-set-key [(shift f10)] 'delete-frame)
(global-set-key [(meta f10)] 'other-frame)
(global-set-key [(shift f7)] 'switch-to-next-buffer)
(global-set-key [(alt f7)] 'toggle-source-header)
(global-set-key [delete] 'delete-char)
(global-set-key [(meta right)] 'forward-word)
(global-set-key [(meta left)] 'backward-word)
(global-set-key [(control home)] 'beginning-of-buffer)
(global-set-key [(control end)] 'end-of-buffer)
(global-set-key [f12] 'toggle-truncate-lines)
(global-set-key [f11] 'revert-buffer)
(global-set-key [(meta ?1)] 'cscope-find-global-definition)
(global-set-key [(meta ?2)] 'cscope-find-functions-calling-this-function)
(global-set-key [(meta ?3)] 'cscope-find-this-symbol)
(global-set-key [(meta ?4)] 'cscope-find-egrep-pattern)
;;(global-set-key [(control ?0)] 'bc-clear )
(defun eshellclear ()
"Clears the shell buffer ala Unix's clear or DOS' cls"
(interactive)
;; the shell prompts are read-only, so clear that for the duration
(let ((inhibit-read-only t))
;; simply delete the region
(delete-region (point-min) (point-max))))
;; To ease the edition of code. It allows me to indent (or unindent) several lines back and forth pressing t
;; (or the Shift and tab key)
;;(set-variable <91>my-tab-width 2)
(defun indent-block()
(interactive)
(shift-region 2)
(setq deactivate-mark nil))
(defun unindent-block()
(interactive)
(shift-region -2)
(setq deactivate-mark nil))
(defun shift-region(numcols)
; my trick to expand the region to the beginning and end of the area selected
; a convenient feature to which I was used, from the Dreamweaver editor
(if (< (point)(mark))
(if (not(bolp)) (progn (beginning-of-line)(exchange-point-and-mark) (end-of-line)
(progn (end-of-line)(exchange-point-and-mark)(beginning-of-line)))
(setq region-start (region-beginning))
(setq region-finish (region-end))
(save-excursion
(if (< (point) (mark)) (exchange-point-and-mark))
(let ((save-mark (mark)))
;; book mark keys
;;(global-set-key [(control ?1)] 'bookmark-bmenu-list )
;;(global-set-key [(control ?2)] 'af-bookmark-toggle )
;;(global-set-key [(control ?3)] 'bookmark-write )
;;(global-set-key [(control ?4)] 'bookmark-load )
;;(global-set-key [(meta ?,)] 'af-bookmark-cycle-forward )
;;(global-set-key [(meta ?.)] 'af-bookmark-cycle-reverse )
;;(global-set-key [(control ?0)] 'af-bookmark-clear-all )
;; book mark keys
;;(global-set-key [(control ?1)] 'bc-list )
;;(global-set-key [(control ?2)] 'bc-set )
;;(global-set-key [(control ?3)] 'bookmark-write )
;;(global-set-key [(control ?4)] 'bookmark-load )
;;(global-set-key [(meta ?.)] 'bc-local-next)
;;(global-set-key [(control meta ?.)] 'bc-next)
;;(global-set-key [(control meta ?,)] 'bc-previous)
(indent-rigidly region-start region-finish numcols))))
(defun indent-or-complete ()
"Indent region selected as a block; if no selection present either indent according to mode,
or expand the word preceding point. "
(interactive)
(if mark-active
(indent-block)
(if (looking-at "\\>")
(hippie-expand nil)
(insert "\t"))))
(defun my-unindent()
"Unindent line, or block if it's a region selected"
(interactive)
(if mark-active
(unindent-block)
(if(not(bolp))(delete-backward-char 2))))
(add-hook 'find-file-hooks (function (lambda ()
(define-key global-map [tab] 'indent-or-complete) ;; Now remember to force tab (C-q-tab) if you want to simp
(define-key global-map [(shift tab)] 'my-unindent)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(global-set-key [(control f5)] 'ebrowse-tree-mode)
(add-to-list 'auto-mode-alist '("BROWSE\\.*" . ebrowse-tree-mode))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Easy bookmarks management
;;
;; Author: Anthony Fairchild
;;
;;;; Keymaping examples
;; (global-set-key [(control f2)] 'af-bookmark-toggle )
;; (global-set-key [f2] 'af-bookmark-cycle-forward )
;; (global-set-key [(shift f2)] 'af-bookmark-cycle-reverse )
;; (global-set-key [(control shift f2)] 'af-bookmark-clear-all )
;; Include common lisp stuff
(require 'cl)
(require 'bookmark)
(defvar af-current-bookmark nil)
;;(defun af-bookmark-make-name ()
;; "makes a bookmark name from the buffer name and cursor position"
;; (concat (buffer-name (current-buffer))
;; " - " (number-to-string (point))))
;; (1+ (count-lines 1 (point)))
(defun af-bookmark-make-name ()
"makes a bookmark name from the buffer name and cursor position"
(concat (buffer-name (current-buffer))
" - " (number-to-string(1+ (count-lines 1 (point))))))
(defun af-bookmark-toggle ()
"remove a bookmark if it exists, create one if it doesnt exist"
(interactive)
(let ((bm-name (af-bookmark-make-name)))
(if (bookmark-get-bookmark bm-name)
(progn (bookmark-delete bm-name)
(message "bookmark removed"))
(progn (bookmark-set bm-name)
(setf af-current-bookmark bm-name)
(message "bookmark set")))))
(defun af-bookmark-cycle (i)
"Cycle through bookmarks by i. 'i' should be 1 or -1"
(if bookmark-alist
(progn (unless af-current-bookmark
(setf af-current-bookmark (first (first bookmark-alist))))
(let ((cur-bm (assoc af-current-bookmark bookmark-alist)))
(setf af-current-bookmark
(if cur-bm
(first (nth (mod (+ i (position cur-bm bookmark-alist))
(length bookmark-alist))
bookmark-alist))
(first (first bookmark-alist))))
(bookmark-jump af-current-bookmark)
;; Update the position and name of the bookmark. We
;; only need to do this when the bookmark has changed
;; position, but lets go ahead and do it all the time
;; anyway.
(bookmark-set-position af-current-bookmark (point))
(let ((new-name (af-bookmark-make-name)))
(bookmark-set-name af-current-bookmark new-name)
(setf af-current-bookmark new-name))))
(message "There are no bookmarks set!")))
(defun af-bookmark-cycle-forward ()
"find the next bookmark in the bookmark-alist"
(interactive)
(af-bookmark-cycle 1))
(defun af-bookmark-cycle-reverse ()
"find the next bookmark in the bookmark-alist"
(interactive)
(af-bookmark-cycle -1))
(defun af-bookmark-clear-all()
"clears all bookmarks"
(interactive)
(setf bookmark-alist nil))
;;If you put this in your .emacs, you can do M-x close-all-buffers. To bind it to a key (for example, C-c x
(defun close-all-buffers ()
(interactive)
(mapc 'kill-buffer (buffer-list)))
(defun sacha/increase-font-size ()
(interactive)
(set-face-attribute 'default
nil
:height
(ceiling (* 1.10
(face-attribute 'default :height)))))
(defun sacha/decrease-font-size ()
(interactive)
(set-face-attribute 'default
nil
:height
(floor (* 0.9
(face-attribute 'default :height)))))
(global-set-key (kbd "C-+") 'sacha/increase-font-size)
(global-set-key (kbd "C--") 'sacha/decrease-font-size)
(require 'dired-x)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Easy bookmarks management ends
;;:Append (global-linum-mode 1) to your .emacs.
;;(load-file "~/linum.el")
;;(require 'linum)
;;(global-linum-mode 1)
(load-file "~/xcscope.el")
(require 'xcscope)
(load-file "~/breadcrumb.el")
(require 'breadcrumb)
(defun date ()
(interactive)
(insert (format-time-string "%A, %B %e, %Y")))
;;(add-to-list 'load-path "/app/skathirvel/tramp-2.1.9/lisp/")
;;(require 'tramp)
;;(setq tramp-default-method "scp")
;;(setq shell-file-name "c:/cygwin/bin/bash.exe")
;;(load "linum.el")
;;(require 'linum)
;;(global-linum-mode 1)
;; (load-file "C:\\Program Files\\gnuserv\\gnuserv.el")
;; (require 'gnuserv)
;;
;; (require 'gnuserv)
;; (setq custom-file "/cygdrive/c/moje/_unix/.emacs-cygwin-mine")
;; (load custom-file)
;;(global-set-key [(control .)] 'enlarge-window-horizontally)
;;(global-set-key [(control ,)] 'shrink-window-horizontally )
;;(global-set-key [(control ?6)] 'enlarge-window )
;;(global-set-key [(control ?7)] 'shrink-window )
(defun copy-buffer-file-name-as-kill (choice)
"Copyies the buffer {name/mode}, file {name/full path/directory} to the kill-ring."
(interactive "cCopy (b) buffer name, (m) buffer major mode, (f) full buffer-file path, (d) buffer-file dir
(let ((new-kill-string)
(name (if (eq major-mode 'dired-mode)
(dired-get-filename)
(or (buffer-file-name) ""))))
(cond ((eq choice ?f)
(setq new-kill-string name))
((eq choice ?d)
(setq new-kill-string (file-name-directory name)))
((eq choice ?n)
(setq new-kill-string (file-name-nondirectory name)))
((eq choice ?b)
(setq new-kill-string (buffer-name)))
((eq choice ?m)
(setq new-kill-string (format "%s" major-mode)))
(t (message "Quit")))
(when new-kill-string
(message "%s copied" new-kill-string)
(kill-new new-kill-string))))
;; When moving to parent directory by `^ Dired by default creates a new buffer for each movement up. The fol
(add-hook 'dired-mode-hook
(lambda ()
(define-key dired-mode-map (kbd "^")
(lambda () (interactive) (find-alternate-file "..")))
; was dired-up-directory
))
(put 'erase-buffer 'disabled nil)
;;(load-file "~/dirtree.el")
(add-to-list 'load-path "/app/skathirvel/.emacs.d/")
;;(eval-after-load "tree-widget"
;; '(if (boundp 'tree-widget-themes-load-path)
;; (add-to-list 'tree-widget-themes-load-path "/app/skathirvel/.emacs.d/tree-widget")))
;;(autoload 'imenu-tree "imenu-tree" "Imenu tree" t)
;;(autoload 'tags-tree "tags-tree" "TAGS tree" t)
;;(autoload 'dirtree "dirtree" "Add directory to tree view" t)
;;(require 'sr-speedbar)
;; Customization examples:
;;
;; To ignore case by default:
;; (setq igrep-options "-i")
;; or:
(setq igrep-case-fold-search t)
;; To search subdirectories by default:
(setq igrep-find t)
;; To search files with the GNU (gzip) zgrep script:
;; (setq igrep-use-zgrep t)
;; or define new igrep commands (this works for zegrep and zfgrep as well):
;; (igrep-define zgrep); M-x zgrep
;; (igrep-find-define zgrep); M-x zgrep-find
;; To search "*.[ch]" files by default in C mode:
(put 'igrep-files-default 'c-mode
(lambda () "*.[ch]"))
;; To disable the default search regex and/or files pattern, except for
;; specific modes:
(setq igrep-regex-default 'ignore)
(setq igrep-files-default 'ignore)
;; To avoid exceeding some shells' limit on command argument length
;; (this only searches files in the current directory):
(setq igrep-find t
igrep-find-prune-clause "-type d \\! -name .")
;;(load-file "~/savehist-20+.el")
;;(savehist-mode 1)
;;(setq savehist-additional-variables '(kill-ring search-ring regexp-search-ring))
;;(setq savehist-file "/app/skathirvel/2006/emacs.savehist.txt")
My emacs file
semaphore and mutex/pthreads
Diff between semaphore and mutex.
Defn-1. Then a mutex is usually used for mutual exclusion of critical paths, while a semaphore is used for inter-thread synchronization and event notifications.
Defn-2. A "mutex" (or "mutual exclusion lock") is a signal that two or more
asynchronous processes can use to reserve a shared resource for exclusive use.
The first process that obtains ownership of the "mutex" also obtains ownership of the shared resource. Other processes must wait for for the first process to release it's ownership of the "mutex" before they may attempt to obtain it.
Finally, a "semaphore" is a sort of "mutex" that is used to signal the availability of a plentiful resource. The source of the resource adds one to the semaphore for each unused resource available. As resources are taken away, the count in the semaphore is decremented (one for each removed resource) until it reaches zero (meaning that no more resources are available). At this
point, any remaining consumers of the resource must wait until the "semaphore" increments above zero, indicating that more resources are available.
Reference:
PThreads Primer
PThreads Manual
Diff between TCP and UDP
diff1=As a connectionless protocol, UDP does not incorporate any connection establishment, teardown, or maintenance logic. For example, a server supporting a UDP application with multiple simultaneous clients will need to allocate less memory to support these clients than would the corresponding TCP application server. Bandwidth throttling and in-order delivery features are properties of TCP, not UDP.
diff2= User Datagram Protocol (UDP)
The User Datagram Protocol (UDP) is a connectionless transport-layer protocol (Layer 4) that belongs to the Internet protocol family. UDP is basically an interface between IP and upper-layer processes. UDP protocol ports distinguish multiple applications running on a single device from one another.
Unlike the TCP, UDP adds no reliability, flow-control, or error-recovery functions to IP. Because of UDP's simplicity, UDP headers contain fewer bytes and consume less network overhead than TCP.
UDP is useful in situations where the reliability mechanisms of TCP are not necessary, such as in cases where a higher-layer protocol might provide error and flow control.
UDP is the transport protocol for several well-known application-layer protocols, including Network File System (NFS), Simple Network Management Protocol (SNMP), Domain Name System (DNS), and Trivial File Transfer Protocol (TFTP).
Core Java KB- Learning Journal
Aug 16 2006; Answers - last edit oct 15 2006
Diff between tcp and udp
The 2 Transport layer protocols are, TCP and UDP. TCP provides connection-oriented, reliable, byte-stream packet delivery, while UDP provides connectionless, unreliable, byte-stream packet delivery. Also in both protocol forms, the data payload are segmented into finite size fixed bytes packets.
What
that means is connection-oriented protocol like TCP establish an end-to-end
link along the intermediate nodes before any data moves. This ESTABLISHED link
of nodes ( routers and switches) provides a secure and traceable pathway when
data is moved in the form of electric signals along the wire over long
distances.
A
connectionless protocol [UDP] doesn't establish paths across the network before
data can flow. Instead, the protocol routes connectionless packets or datagrams
individually at each intermediate node.
- correct data corruption.
- packet arrive out of sequence at destination
- acknowledgements, retransmissions, wait timings
- duplicates
Transmission issue.1=data corruption
Solution.1=do checksum You can compare checksums included with a packet's data payload with a recalculation of the checksum algorithm at the destination to detect corrupted data. You must retransmit corrupted or lost data, so the protocol must provide methods for the destination to signal the source when retransmission is needed.
Transmission issue.2=packet arrive out of sequence at destination
Solution.2=buffer and order the packets correctly. Packetized data can arrive out of sequence, so the protocol must have a way to detect out-of-sequence packets, buffer them, and pass them to the Application layer in the correct order.
Transmission issue.3=duplicates
solution.3=discard dups It must also detect and discard duplicate transmissions.
Transmission issue.4=acknowledgements, retransmissions, wait timings
solution.4=use timers. A collection of timers enables limiting the wait for various acknowledgements, so you can initiate retransmissions or link re-establishment.
Byte-stream protocols don't specifically support data units other than bytes. TCP can't structure bytes of the data payload in a packet, nor can it cope with individual bits. As far as TCP is concerned, it's responsible for transporting an unstructured string of 8-bit bytes.
A connectionless protocol [UDP] doesn't establish paths across the network before data can flow. Instead, the protocol routes connectionless packets or datagrams individually at each intermediate node.
Without an end-to-end link, a connectionless protocol such as UDP isn't reliable. When a UDP packet moves into the network, the sending process can't know whether the packet arrives at its destination unless the Application layer acknowledges this fact. Nor can the protocol detect duplicate or out-of-sequence packets. The standard jargon describes UDP as "unreliable," though a more descriptive term might be "nonreliable." On modern networks, UDP traffic isn't prone to disruption, but you can't really call it "reliable," either.
Questions
and Answers 1. Explain
in context of java - final, finally, finalize2. What
is deadlock,cause of deadlock, steps to avoid to it. 3. Diff
between semaphore and mutex.4. What
is difference between object.wait() and thead.join()?5. Diff
between public static synchronized vs public synchronized6. What
is surrogate primary key? what is candidate key?7. What
is functional dependency? transitive dependency?8. log4j
vs java logging.9. difference
between a.java.sql.statementb. prepared statementc. callable statement10.
a class does not marked as serializable participate in the ejb call as return
object. caller fails with throwing exceptions. how to fix it?a. java.rmi.remote interface.11.
what is difference between java.rmi.remote and java.lang.Serializable.12. new string s;a. s.intern();13.
difference between java == and equals().14.
How do you make the software code you wrote is good?a. junit.b. basic smoke/functional
testing testcases with inputs.15.
what is your preferred OS development environment? what is your preferred
editor vi or emacs?Sed Onliners for reference
-------------------------------------------------------------------------
HANDY ONE-LINERS FOR SED (Unix stream editor) Apr. 26, 2004
compiled by Eric Pement - pemente[at]northpark[dot]edu version 5.4
Latest version of this file is usually at:
http://sed.sourceforge.net/sed1line.txt
http://www.student.northpark.edu/pemente/sed/sed1line.txt
This file is also available in Portuguese at:
http://www.lrv.ufsc.br/wmaker/sed_ptBR.html
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
# triple space a file
sed 'G;G'
# undo double-spacing (assumes even-numbered lines are always blank)
sed 'n;d'
# insert a blank line above every line which matches "regex"
sed '/regex/{x;p;x;}'
# insert a blank line below every line which matches "regex"
sed '/regex/G'
# insert a blank line above and below every line which matches "regex"
sed '/regex/{x;p;x;G;}'
NUMBERING:
# number each line of a file (simple left alignment). Using a tab (see
# note on '\t' at end of file) instead of space will preserve margins.
sed = filename | sed 'N;s/\n/\t/'
# number each line of a file (number on left, right-aligned)
sed = filename | sed 'N; s/^/ /; s/ *\(.\{6,\}\)\n/\1 /'
# number each line of file, but only print numbers if line is not blank
sed '/./=' filename | sed '/./N; s/\n/ /'
# count lines (emulates "wc -l")
sed -n '$='
TEXT CONVERSION AND SUBSTITUTION:
# IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
sed 's/.$//' # assumes that all lines end with CR/LF
sed 's/^M$//' # in bash/tcsh, press Ctrl-V then Ctrl-M
sed 's/\x0D$//' # gsed 3.02.80, but top script is easier
# IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format
sed "s/$/`echo -e \\\r`/" # command line under ksh
sed 's/$'"/`echo \\\r`/" # command line under bash
sed "s/$/`echo \\\r`/" # command line under zsh
sed 's/$/\r/' # gsed 3.02.80
# IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format
sed "s/$//" # method 1
sed -n p # method 2
# IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format
# Can only be done with UnxUtils sed, version 4.0.7 or higher.
# Cannot be done with other DOS versions of sed. Use "tr" instead.
sed "s/\r//" infile >outfile # UnxUtils sed v4.0.7 or higher
tr -d \r outfile # GNU tr version 1.22 or higher
# delete leading whitespace (spaces, tabs) from front of each line
# aligns all text flush left
sed 's/^[ \t]*//' # see note on '\t' at end of file
# delete trailing whitespace (spaces, tabs) from end of each line
sed 's/[ \t]*$//' # see note on '\t' at end of file
# delete BOTH leading and trailing whitespace from each line
sed 's/^[ \t]*//;s/[ \t]*$//'
# insert 5 blank spaces at beginning of each line (make page offset)
sed 's/^/ /'
# align all text flush right on a 79-column width
sed -e :a -e 's/^.\{1,78\}$/ &/;ta' # set at 78 plus 1 space
# center all text in the middle of 79-column width. In method 1,
# spaces at the beginning of the line are significant, and trailing
# spaces are appended at the end of the line. In method 2, spaces at
# the beginning of the line are discarded in centering the line, and
# no trailing spaces appear at the end of lines.
sed -e :a -e 's/^.\{1,77\}$/ & /;ta' # method 1
sed -e :a -e 's/^.\{1,77\}$/ &/;ta' -e 's/\( *\)\1/\1/' # method 2
# substitute (find and replace) "foo" with "bar" on each line
sed 's/foo/bar/' # replaces only 1st instance in a line
sed 's/foo/bar/4' # replaces only 4th instance in a line
sed 's/foo/bar/g' # replaces ALL instances in a line
sed 's/\(.*\)foo\(.*foo\)/\1bar\2/' # replace the next-to-last case
sed 's/\(.*\)foo/\1bar/' # replace only the last case
# substitute "foo" with "bar" ONLY for lines which contain "baz"
sed '/baz/s/foo/bar/g'
# substitute "foo" with "bar" EXCEPT for lines which contain "baz"
sed '/baz/!s/foo/bar/g'
# change "scarlet" or "ruby" or "puce" to "red"
sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g' # most seds
gsed 's/scarlet\|ruby\|puce/red/g' # GNU sed only
# reverse order of lines (emulates "tac")
# bug/feature in HHsed v1.5 causes blank lines to be deleted
sed '1!G;h;$!d' # method 1
sed -n '1!G;h;$p' # method 2
# reverse each character on the line (emulates "rev")
sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'
# join pairs of lines side-by-side (like "paste")
sed '$!N;s/\n/ /'
# if a line ends with a backslash, append the next line to it
sed -e :a -e '/\\$/N; s/\\\n//; ta'
# if a line begins with an equal sign, append it to the previous line
# and replace the "=" with a single space
sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'
# add commas to numeric strings, changing "1234567" to "1,234,567"
gsed ':a;s/\B[0-9]\{3\}\>/,&/;ta' # GNU sed
sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta' # other seds
# add commas to numbers with decimal points and minus signs (GNU sed)
gsed ':a;s/\(^\|[^0-9.]\)\([0-9]\+\)\([0-9]\{3\}\)/\1\2,\3/g;ta'
# add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.)
gsed '0~5G' # GNU sed only
sed 'n;n;n;n;G;' # other seds
SELECTIVE PRINTING OF CERTAIN LINES:
# print first 10 lines of file (emulates behavior of "head")
sed 10q
# print first line of file (emulates "head -1")
sed q
# print the last 10 lines of a file (emulates "tail")
sed -e :a -e '$q;N;11,$D;ba'
# print the last 2 lines of a file (emulates "tail -2")
sed '$!N;$!D'
# print the last line of a file (emulates "tail -1")
sed '$!d' # method 1
sed -n '$p' # method 2
# print only lines which match regular expression (emulates "grep")
sed -n '/regexp/p' # method 1
sed '/regexp/!d' # method 2
# print only lines which do NOT match regexp (emulates "grep -v")
sed -n '/regexp/!p' # method 1, corresponds to above
sed '/regexp/d' # method 2, simpler syntax
# print the line immediately before a regexp, but not the line
# containing the regexp
sed -n '/regexp/{g;1!p;};h'
# print the line immediately after a regexp, but not the line
# containing the regexp
sed -n '/regexp/{n;p;}'
# print 1 line of context before and after regexp, with line number
# indicating where the regexp occurred (similar to "grep -A1 -B1")
sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
# grep for AAA and BBB and CCC (in any order)
sed '/AAA/!d; /BBB/!d; /CCC/!d'
# grep for AAA and BBB and CCC (in that order)
sed '/AAA.*BBB.*CCC/!d'
# grep for AAA or BBB or CCC (emulates "egrep")
sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d # most seds
gsed '/AAA\|BBB\|CCC/!d' # GNU sed only
# print paragraph if it contains AAA (blank lines separate paragraphs)
# HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'
# print paragraph if it contains AAA and BBB and CCC (in any order)
sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;/BBB/!d;/CCC/!d'
# print paragraph if it contains AAA or BBB or CCC
sed -e '/./{H;$!d;}' -e 'x;/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
gsed '/./{H;$!d;};x;/AAA\|BBB\|CCC/b;d' # GNU sed only
# print only lines of 65 characters or longer
sed -n '/^.\{65\}/p'
# print only lines of less than 65 characters
sed -n '/^.\{65\}/!p' # method 1, corresponds to above
sed '/^.\{65\}/d' # method 2, simpler syntax
# print section of file from regular expression to end of file
sed -n '/regexp/,$p'
# print section of file based on line numbers (lines 8-12, inclusive)
sed -n '8,12p' # method 1
sed '8,12!d' # method 2
# print line number 52
sed -n '52p' # method 1
sed '52!d' # method 2
sed '52q;d' # method 3, efficient on large files
# beginning at line 3, print every 7th line
gsed -n '3~7p' # GNU sed only
sed -n '3,${p;n;n;n;n;n;n;}' # other seds
# print section of file between two regular expressions (inclusive)
sed -n '/Iowa/,/Montana/p' # case sensitive
SELECTIVE DELETION OF CERTAIN LINES:
# print all of file EXCEPT section between 2 regular expressions
sed '/Iowa/,/Montana/d'
# delete duplicate, consecutive lines from a file (emulates "uniq").
# First line in a set of duplicate lines is kept, rest are deleted.
sed '$!N; /^\(.*\)\n\1$/!P; D'
# delete duplicate, nonconsecutive lines from a file. Beware not to
# overflow the buffer size of the hold space, or else use GNU sed.
sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P'
# delete all lines except duplicate lines (emulates "uniq -d").
sed '$!N; s/^\(.*\)\n\1$/\1/; t; D'
# delete the first 10 lines of a file
sed '1,10d'
# delete the last line of a file
sed '$d'
# delete the last 2 lines of a file
sed 'N;$!P;$!D;$d'
# delete the last 10 lines of a file
sed -e :a -e '$d;N;2,10ba' -e 'P;D' # method 1
sed -n -e :a -e '1,10!{P;N;D;};N;ba' # method 2
# delete every 8th line
gsed '0~8d' # GNU sed only
sed 'n;n;n;n;n;n;n;d;' # other seds
# delete ALL blank lines from a file (same as "grep '.' ")
sed '/^$/d' # method 1
sed '/./!d' # method 2
# delete all CONSECUTIVE blank lines from file except the first; also
# deletes all blank lines from top and end of file (emulates "cat -s")
sed '/./,/^$/!d' # method 1, allows 0 blanks at top, 1 at EOF
sed '/^$/N;/\n$/D' # method 2, allows 1 blank at top, 0 at EOF
# delete all CONSECUTIVE blank lines from file except the first 2:
sed '/^$/N;/\n$/N;//D'
# delete all leading blank lines at top of file
sed '/./,$!d'
# delete all trailing blank lines at end of file
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' # works on all seds
sed -e :a -e '/^\n*$/N;/\n$/ba' # ditto, except for gsed 3.02*
# delete the last line of each paragraph
sed -n '/^$/{p;h;};/./{x;/./p;}'
SPECIAL APPLICATIONS:
# remove nroff overstrikes (char, backspace) from man pages. The 'echo'
# command may need an -e switch if you use Unix System V or bash shell.
sed "s/.`echo \\\b`//g" # double quotes required for Unix environment
sed 's/.^H//g' # in bash/tcsh, press Ctrl-V and then Ctrl-H
sed 's/.\x08//g' # hex expression for sed v1.5
# get Usenet/e-mail message header
sed '/^$/q' # deletes everything after first blank line
# get Usenet/e-mail message body
sed '1,/^$/d' # deletes everything up to first blank line
# get Subject header, but remove initial "Subject: " portion
sed '/^Subject: */!d; s///;q'
# get return address header
sed '/^Reply-To:/q; /^From:/h; /./d;g;q'
# parse out the address proper. Pulls out the e-mail address by itself
# from the 1-line return address header (see preceding script)
sed 's/ *(.*)//; s/>.*//; s/.*[:<] *//'
# add a leading angle bracket and space to each line (quote a message)
sed 's/^/> /'
# delete leading angle bracket & space from each line (unquote a message)
sed 's/^> //'
# remove most HTML tags (accommodates multiple-line tags)
sed -e :a -e 's/<[^>]*>//g;/zipup.bat
dir /b *.txt | sed "s/^\(.*\)\.TXT/pkzip -mo \1 \1.TXT/" >>zipup.bat
TYPICAL USE: Sed takes one or more editing commands and applies all of
them, in sequence, to each line of input. After all the commands have
been applied to the first input line, that line is output and a second
input line is taken for processing, and the cycle repeats. The
preceding examples assume that input comes from the standard input
device (i.e, the console, normally this will be piped input). One or
more filenames can be appended to the command line if the input does
not come from stdin. Output is sent to stdout (the screen). Thus:
cat filename | sed '10q' # uses piped input
sed '10q' filename # same effect, avoids a useless "cat"
sed '10q' filename > newfile # redirects output to disk
For additional syntax instructions, including the way to apply editing
commands from a disk file instead of the command line, consult "sed &
awk, 2nd Edition," by Dale Dougherty and Arnold Robbins (O'Reilly,
1997; http://www.ora.com), "UNIX Text Processing," by Dale Dougherty
and Tim O'Reilly (Hayden Books, 1987) or the tutorials by Mike Arst
distributed in U-SEDIT2.ZIP (many sites). To fully exploit the power
of sed, one must understand "regular expressions." For this, see
"Mastering Regular Expressions" by Jeffrey Friedl (O'Reilly, 1997).
The manual ("man") pages on Unix systems may be helpful (try "man
sed", "man regexp", or the subsection on regular expressions in "man
ed"), but man pages are notoriously difficult. They are not written to
teach sed use or regexps to first-time users, but as a reference text
for those already acquainted with these tools.
QUOTING SYNTAX: The preceding examples use single quotes ('...')
instead of double quotes ("...") to enclose editing commands, since
sed is typically used on a Unix platform. Single quotes prevent the
Unix shell from intrepreting the dollar sign ($) and backquotes
(`...`), which are expanded by the shell if they are enclosed in
double quotes. Users of the "csh" shell and derivatives will also need
to quote the exclamation mark (!) with the backslash (i.e., \!) to
properly run the examples listed above, even within single quotes.
Versions of sed written for DOS invariably require double quotes
("...") instead of single quotes to enclose editing commands.
USE OF '\t' IN SED SCRIPTS: For clarity in documentation, we have used
the expression '\t' to indicate a tab character (0x09) in the scripts.
However, most versions of sed do not recognize the '\t' abbreviation,
so when typing these scripts from the command line, you should press
the TAB key instead. '\t' is supported as a regular expression
metacharacter in awk, perl, and HHsed, sedmod, and GNU sed v3.02.80.
VERSIONS OF SED: Versions of sed do differ, and some slight syntax
variation is to be expected. In particular, most do not support the
use of labels (:name) or branch instructions (b,t) within editing
commands, except at the end of those commands. We have used the syntax
which will be portable to most users of sed, even though the popular
GNU versions of sed allow a more succinct syntax. When the reader sees
a fairly long command such as this:
sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
it is heartening to know that GNU sed will let you reduce it to:
sed '/AAA/b;/BBB/b;/CCC/b;d' # or even
sed '/AAA\|BBB\|CCC/b;d'
In addition, remember that while many versions of sed accept a command
like "/one/ s/RE1/RE2/", some do NOT allow "/one/! s/RE1/RE2/", which
contains space before the 's'. Omit the space when typing the command.
OPTIMIZING FOR SPEED: If execution speed needs to be increased (due to
large input files or slow processors or hard disks), substitution will
be executed more quickly if the "find" expression is specified before
giving the "s/.../.../" instruction. Thus:
sed 's/foo/bar/g' filename # standard replace command
sed '/foo/ s/foo/bar/g' filename # executes more quickly
sed '/foo/ s//bar/g' filename # shorthand sed syntax
On line selection or deletion in which you only need to output lines
from the first part of the file, a "quit" command (q) in the script
will drastically reduce processing time for large files. Thus:
sed -n '45,50p' filename # print line nos. 45-50 of a file
sed -n '51q;45,50p' filename # same, but executes much faster
If you have any additional scripts to contribute or if you find errors
in this document, please send e-mail to the compiler. Indicate the
version of sed you used, the operating system it was compiled for, and
the nature of the problem. Various scripts in this file were written
or contributed by:
Al Aab # "seders" list moderator
Edgar Allen # various
Yiorgos Adamopoulos
Dale Dougherty # author of "sed & awk"
Carlos Duarte # author of "do it with sed"
Eric Pement # author of this document
Ken Pizzini # author of GNU sed v3.02
S.G. Ravenhall # great de-html script
Greg Ubben # many contributions & much help
-------------------------------------------------------------------------
Unix shell commands I use frequently and accumulated over the years ...
Author: Sakthivel Kathirvel
Created: Apr 2006
Last Updated: Jan 2015
[grep]
grep -rain
grep -Pain
grep -inverse
grep -PairHana
cat -EAT
ls -god
ls -dog */ [dir only]
ls -A .* | grep '^\.' [ list only the hidden files]
ls -got ;
ls -gothic
ls -halt
less -JIN
less -JINSR
zip -rum
unzip -Call
unzip -Cap
find -follow -type -name -maxdepth [ "-follow" the "-type" by "-name" for "-maxdepth" ]
tree -t | grep *log* | less -JIS
top -bd 5 -n 9419
grep -Pvi samplesize\|apache\|log4\|factory\|debug logs.1 | less -JIS
grep no file path ; only file names.
grep -HanaPair object . --include=*.java | awk 'sub(/^.*\//, "")' | less -JIS
grep partial file path names ; only file names.
$ grep -HanaPair object . --include=*.java | awk 'sub(/^.*\/src\/org\/apache\/log4j\/builder\//, "")' | less -JIS
[solaris]
HISTTIMEFORMAT="%h-%d-%y - %H:%M:%S "
shopt -s histappend
PS1="\033[1;34m\]\u@\033[1;0m\]\h:\033[1;46m\$(pwd 2)\033[0m\]\n$ "
scd(){ pushd . > /dev/null; builtin cd "$@";}
alias cd="scd"
alias dt="/usr/openpkg/bin/find ./ -maxdepth 2 -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
alias l="less -JIS"
alias ls="ls -haltF"
[linux]
HISTTIMEFORMAT="%h-%d-%y - %H:%M:%S "
shopt -s histappend
PS1="\033[1;34m\]\u@\033[1;0m\]\h:\033[1;46m\$(pwd 2)\033[0m\]\n$ "
scd(){ pushd . > /dev/null; builtin cd "$@";}
alias cd="scd"
alias dt="find ./ -maxdepth 2 -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
alias l="less -JIS"
alias ls="ls -haltF"
alias li="less -JIS" ; alias l="ls -haltF" ; alias hi='history | li' ; alias di='dirs -v' ; alias pu='pushd `pwd`';
function _dt() { find ./ -maxdepth "$1" -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' ;}; alias dt=_dt
function scd(){ pushd . > /dev/null; builtin cd "$@";} ; alias cd="scd"
function _g() { grep -Pair "$1"; } ; alias g=_g
function _fi() { find -iname "$1"; }; alias fi=_fi
[cygwin]
HISTTIMEFORMAT="%h-%d-%y - %H:%M:%S "
shopt -s histappendec
PS1="\033[1;34m\]\u@\033[1;0m\]\h:\033[1;46m\$(pwd 2)\033[0m\]\n$ "
scd(){ pushd . > /dev/null; builtin cd "$@";}
alias cd="scd"
alias dt="find ./ -maxdepth 2 -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
alias l="less -JIS"
alias ls="ls -haltF"
alias dhs='echo `date` | tee -a c:/history-`date +%F`.txt ; dirs -v | tee -a c:/history-`date +%F`.txt'
[bashrc]
$ less -JIS ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
alias pu='pushd .'
alias di='dirs -v | tee ~/dirs.txt'
alias li='less -JIS'
alias ls='ls -halt'
HISTTIMEFORMAT="%h-%d-%y - %H:%M:%S "
shopt -s histappend
PS1="\033[1;34m\]\u@\033[1;0m\]\h:\033[1;46m\$(pwd 2)\033[0m\]\n$ "
#alias cd="pushd . > /dev/null; cd $1"
scd(){
pushd . > /dev/null;
builtin cd "$@";
}
alias cd="scd"
#more bash shell stuff http://www.hypexr.org/bash_tutorial.php#emacs
[multi file renames]
for f in *txt ; do mv $f `basename $f txt`txt.backup; done
[p4v] p4commands
p4 clients -u
p4 clients -e * [ nameFilter flag limits output to clients whose name matches the nameFilter pattern e.g. -e 'svr-dev-rel*']
p4 clients -u | grep -Pai dcs | cut -d' ' -f 2 | xargs -t -n 1 p4 client -o | grep -Pai ^Access\|^Client
[solaris]
p4 clients -u | cut -d' ' -f 2 | xargs -t -n 1 p4 client -o | /usr/openpkg/bin/grep -Pai ^Host
[linux]
p4 clients -u | cut -d' ' -f 2 | xargs -t -n 1 p4 client -o | grep -Pai ^Host
p4 describe -s 204945
[where core files ]
/app/corefiles/%h.%e.%p
[less]
less [example search pattern = /58=.{10} ; meaning= pattern starting with 58=and any 10 chars that follow. ]
[date]
date +%Y-%m-%d-%H-%M-%S
`date +%F-%I-%M-%S`.txt
echo `hostname`@`date +%m-%d-%Y-%H-%M`
if (profiler) profiler->iTraceStamp("OUT320");
`date +%F-%I-%M-%S`.txt
[.bash_history]
shopt -s histappend ; history -a
# User specific aliases and functions
alias pu='pushd .'
alias di='dirs -v | tee ~/dirs.txt'
alias li='less -JIS'
alias ls='ls -halt'
pushd ~
alias cd="pushd . > /dev/null; cd $1"
[solaris]
HISTTIMEFORMAT="%h-%d-%y - %H:%M:%S "
shopt -s histappend
PS1="\033[1;34m\]\u@\033[1;0m\]\h:\033[1;46m\$(pwd 2)\033[0m\]\n$ "
scd(){ pushd . > /dev/null; builtin cd "$@";}
alias cd="scd"
alias dt="/usr/openpkg/bin/find ./ -maxdepth 2 -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
alias l="less -JIS"
alias ls="ls -haltF"
[linux]
HISTTIMEFORMAT="%h-%d-%y - %H:%M:%S "
shopt -s histappend
PS1="\033[1;34m\]\u@\033[1;0m\]\h:\033[1;46m\$(pwd 2)\033[0m\]\n$ "
scd(){ pushd . > /dev/null; builtin cd "$@";}
alias cd="scd"
alias dt="find ./ -maxdepth 2 -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'"
alias l="less -JIS"
alias ls="ls -haltF"
[xserver]
/usr/X11R6/bin/startxwin.sh
XWin -multiwindow -clipboard -silent-dup-error -dpi 100 2>&1 1>/dev/null & ; DISPLAY=:0.0 ; export DISPLAY
XWin -clipboard -silent-dup-error -dpi 100 -scrollbars -multimonitors 2>&1 1>/dev/null &
XWin -clipboard -silent-dup-error -dpi 100 -scrollbars -multimonitors 2>&1 1>/dev/null &
xhost +
[win 7 ; cygwin ; ]
528 XWin -multiwindow -clipboard -silent-dup-error -dpi 100 2>&1 1>/dev/null &
529 DISPLAY=:0.0 ; export DISPLAY
530 xhost +
[unix process by tree view]
[solaris]
ps -o pid args -H -U 1616
ps -TF -p
ptree -a
/usr/ucb/ps with args ww [ very wide format - show the complete command]
/usr/ucb/ps -ejH
[show threads of process - linux]
[linux]
pstree -hcpaAlG | grep -rainPA10 java.* [ shows process tree]
ps axjf [ shows nice process tree ]
pstree -hcpaAl | grep -rainPA10 gdb/|java.*
pstree -hcpaAl | grep -rainPA10 p4v.*
ps -eLf | grep `id -u` | grep -rain java
ps -wwf [ very wide format - show the complete command]
ps ux
[unix machine info]
[linux]
cat /proc/cpuinfo
cat /proc/meminfo
dmesg
lspci
The newer version of cpuinfo as reflected in this post seems to have the necessary components to differentiate between multi-core cpus.
cpu cores physical id core id.
Physical ID assigns a Unique ID to each CPU.
CPU cores reflects the number of Cores making up the CPU
core Id: identifies the core represented.
cat /proc/cpuinfo | grep physical.*id
cat /proc/cpuinfo | grep core.*id
[solaris]
[netstat]
netstat -pan [ show [aA]ll [n]umeric ports w/ [p]rocess id]
[netcat]
nc -vv -l -p 6080 < "C:\manifest.txtnetcat.bin"
[xterm]
xterm wrap turnon turnoff
To turn auto-wrap off:
to OFF=>
echo -e "/033[?7l"
to turn it on:
to ON=>echo -e "/033[?7h"
xterm start
export DISPLAY=10.212.161.80:0.0; xterm -aw -fg black -bg white -fn -adobe-courier-bold-r-normal--14-140-75-75-m-90-iso8859-1 -sl 3000 -title "`echo $HOSTNAME` DEV. BUILD.SERVER - " -e /bin/bash &
[cygwin window title ]
printf \\033]0\;\%s\\007 "cygwin-left"
printf \\033]0\;\%s\\007 "cygwin-right"
[diff/sdiff ]
sdiff -Bibas -w 100 old.file.txt new.file.txt
diff -Bad -wib -Easy --suppress-common-lines old.file.txt new.file.txt | less -JIS
[win-emacs]
~/xEmacs/XEmacs-21.4.21/i586-pc-win32/xemacs.exe
~/GNu-emacs-21.3/bin/runemacs.exe
C:/Documents and Settings/skathirvel/Application Data/.emacs
"C:\Program Files (x86)\Xming\Xming.exe" :0 -clipboard -multiwindow -dpi 108 -fp c:/windows/fonts
[unix-emacs]
emacs -fn -adobe-courier-medium-r-normal--18-180-75-75-m-110-iso8859-1 &
xlsfonts.exe *adobe-courier-medium-r-normal* | less -JIN
;; disable color crap
(setq-default global-font-lock-mode nil)
set cscope on the PATH
export DISPLAY=10.212.161.80:0.0;export PATH=/app/skathirvel:$PATH;emacs -fn -adobe-courier-medium-r-normal--18-180-75-75-m-110-iso8859-1 &
[make]
make -f ./makefile.simple install | awk '/g/+/+|Installing|cp/{ print $0 }'
[cscope]
>rm -fr cscope.files cscope.out
>find `pwd` /( -iname '*.cpp' -o -iname '*.cc' -o -iname '*.c' -o -iname '*.h' -o -iname '*.hh' -o -iname '*.hpp' /) -follow -print > cscope.files
>/cygdrive/c/users/skathirvel/cscope.exe -b -q -k
[in emacs] M-x cscope-set-initial-directory
[hotkey combinations]
[cscope]
C-c s s Find symbol.
;; C-c s d Find global definition.
;; C-c s g Find global definition (alternate binding).
;; C-c s G Find global definition without prompting.
;; C-c s c Find functions calling a function.
;; C-c s C Find called functions (list functions called
;; from a function).
;; C-c s t Find text string.
;; C-c s e Find egrep pattern.
;; C-c s f Find a file.
;; C-c s i Find files #including a file.
find \( -iname *.a -o -iname *.o \) | xargs -t -n 1 rm -fr ;
find -type f | xargs md5sum > md5sum.txt.`date +%Y%m-%d-%H-%M-%S`
[nm] w/ obj(.o) file]
nm -gl -fposix --demangle some_object_file.o | gawk '{ gsub("/some/directory/path/toafile" ""); print } ' | less -JIN
[nm w/ archive (.a) file]
nm -gopPl -fposix --demangle some_static_lib.a | grep -Pair | less -JIS
ar tv ./some/directory/path/toafile/some_static_lib.a| less -JIS
[g++]
g++ -print-search-dirs | tr ':' '\n'
gcc -E file.c
or
g++ -E file.cpp
will do this for you. The -E switch forces the compiler to stop after the preprocessing phase spitting all it’s got at the moment to standard output.
g++ -E $1 |\
grep '^# [0-9]* "[^"]*"' |\
grep -o '"[^"]*"' |\
grep -o '[^"<>]*' |\
grep -v '^/usr/' |\
sort |\
uniq
[find]
find . -maxdepth 2 -type d -follow
find . -maxdepth 4 -type f -follow -iname *.jar
find -iname * -printf `pwd`/%h/%f//n
find /( -type f -iname /) -printf `pwd`/%h/%f//n | xargs ls -tog | less -JI
find /( -type f -iname *tnt*.in*ing /) -printf `pwd`/%h/%f//n | xargs ls -tog | less -JI
/usr/openpkg/bin/find /( -type f -iname *apache*log4j*in*ing.gz /) -printf `pwd`/%h/%f//n | xargs ls -tog | less -JI
/usr/openpkg/bin/find /( -type f -iname *apache*apacheout*ing.gz /) -printf `pwd`/%h/%f//n | xargs ls -tog | less -JI
find -perm 644 -iname *.cc -type f -printf `pwd`/%h/%f//n
find `pwd` -size +40k -exec wc -l "{}" /; | sort -g -r | awk '{ print "| " $2 " | " $1 " |" }'
/usr/openpkg/bin/find -iname *apache*.log -follow | xargs ls -goth
find /app/skathirvel/2006 -iname *.yml -type f -exec ls -halt "{}" +; < find and sort by time >
find /app/skathirvel/2006 -iname *.yml -type f -exec ls -rhalt "{}" +; < find and reverse sort by time >
find gateway -type f | egrep '\.(c|cc|cpp|h|hh|H|C)$' | grep log4j
find gateway -type f | egrep '\.(c|cc|cpp|h|hh|H|C)$' | grep log4j
[zgrep]
/usr/openpkg/bin/zgrep -ain
grep -Pain 35=d /some/directory/path/toafile/app.log | tr '/01' '|' | less -JI
sed -n '1661928 1662928p' /some/directory/path/toafile/app.log
p4 describe -s 2516943 | sed 's/\(.*\)\(google.com\)\(...\)\(.*\)/\2\3/'
[tree]
ls -goth | grep ^- [ file only] sorted by time
ls -godh */ | grep ^d [dir only]
ls -goSh [ sorted by size]
ls -goth | grep ^- [ file only] sorted by time
[reverse]
ls -gothr | grep ^- [ file only] sorted by time
ls -godhr */ | grep ^d [dir only]
ls -goShr [ sorted by size]
ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^//]*///--/g' -e 's/^/ /' -e 's/-/|/' [ tree display]
find /skathirvel -type d -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g' [ tree display ]
[windows search]
from:sakthivel to:foo date:>12/01/08 date:<12/30/2008 msft
from:sakthivel to:foo date:>01/01/09 date:<02/01/2009 msft
date:>01/01/09 date:<02/01/2009 subject:(gateway rm) folder:inbox
from:foo date:11/2009..12/2009
from:foo date:11/2009..12/2009
from:skathirvel date:11/2009..12/2009
ext:doc MSFT 128
ext:pdf msft 128
[eclipse]
[java] C:\eclipse-standard-kepler-R-win32-installed-sep17-2013\eclipse\eclipse.exe -vm "C:\Program Files (x86)\Java\jre7\bin\java.exe" -data C:/SHAK_JAVA_ECLIPSE_Solution-Echo &
[java] C:\eclipse-jee-kepler-SR2-win32-x86_64\eclipse\eclipse.exe -vm c:\Java\jdk1.7.0_67\bin\java.exe -data C:/SHAK_JAVA_ECLIPSE_Solution-Echo &
[deprecated] C:/eclipse-3.7-java-indigo-win32-installed-jul-12-2011/eclipse/eclipse.exe -vm C:/jdk1.6.0_26/bin/java.exe -data C:/SHAK_JAVA_ECLIPSE_Solution-Echo &
[deprecated] c:/eclipse-java-helios-SR2-win32-installed-May312011/eclipse/eclipse.exe -vm C:/jdk1.6.0_14/bin/java.exe -data C:/SHAK_JAVA_ECLIPSE_Solution-Echo &
[deprecated] C:/eclipse-SDK-3.5.2-win32-mar-2010/eclipse/eclipse.exe -vm C:/jdk1.6.0_14/bin/java.exe -data C:/SHAK_JAVA_ECLIPSE_Solution-Echo &
[deprecated] C:/eclipse-java-galileo-SR1-win32-2009-dec/eclipse/eclipse.exe -vm C:/jdk1.6.0_14/bin/java.exe -data C:/SHAK_JAVA_ECLIPSE_Solution-Echo &
[deprecated]C:/eclipse-jee-ganymede-SR1-win32/eclipse/eclipse.exe -vm c:/jdk1.5.0_15/bin/java.exe -data C:/SHAK_JAVA_ECLIPSE_Solution-Echo &
[cpp]
C:\eclipse-cpp-kepler-R-win32--installed-sep17-2013\eclipse\eclipse.exe -vm "C:\Program Files (x86)\Java\jre7\bin\java.exe" -data C:/SHAK_CPP_ECLIPSE_Solution-Echo &
[deprecated] C:/eclipse-cpp-kepler-R-win32-installed-jul-08-2013/eclipse/eclipse.exe -vm C:/jdk1.7.0_25/bin/java.exe -data C:/SHAK_CPP_ECLIPSE_Solution-Echo &
[deprecated ] C:/eclipse-3.7-cpp-indigo-incubation-win32-installed-jul-12-2011/eclipse/eclipse.exe -vm C:/jdk1.6.0_26/bin/java.exe -data C:/SHAK_CPP_ECLIPSE_Solution-Echo &
[deprecated ] C:/eclipse-cpp-helios-SR2-win32-installed-May312011/eclipse/eclipse.exe -vm C:/jdk1.6.0_14/bin/java.exe -data C:/SHAK_CPP_ECLIPSE_Solution-Echo &
[deprecated ] C:/eclipse-cpp-galileo-SR1-win32-2009-dec/eclipse/eclipse.exe -vm C:/jdk1.6.0_14/bin/java.exe -data C:/SHAK_CPP_ECLIPSE_Solution-Echo &
[deprecated] C:/eclipse-cpp-galileo-win32.zip.dir/eclipse/eclipse.exe -vm C:/jdk1.6.0_14/bin/java.exe -data C:/SHAK_CPP_ECLIPSE_Solution-Echo &
[zip_unzip]
zip -mu -rv9 2009.mar.10.zip * -i *20090310* [ for persist file archive]
zip -mu -rv9 jan.29.09.zip * -i *01*29* [ gateway log files; create a zip file and delete files in the dir]
zip -d oct.10.17.08.zip *10*21* [ delete files inside the zip file]
unzip -Cal oct.10.17.08.zip /*10/*17/* [ list files inside a zip file]
unzip -Cal oct.10.17.08.zip /*10/*17/*.err [ list files inside a zip file]
unzip -Cap oct.10.17.08.zip runtime.err
unzip -qq -d apache-log4j "c:\lib\runtime.jar" [ extract .jar to a directory very quietly]
[tar]
tar cvf ~/apache-log4j.tar /app/ --exclude "/var/log" --exclude "/samples"
[grep]
grep -rain 201=1.*202=30.*541=30.*occ=tgt app.log
grep -rainPA1 class.*Interaface * --include=*.{c cc cpp hh h}
grep -rainPC2 shakdebug * --include=*.{c cc cpp h hh} | less -JINS
$ pstree -hcpaAl | grep -rainPA10 /(gdb/|java.*/)
173: | | |-grep 13345 -rainPA10 (gdb|java.*)
174- | | `-pstree 13344 -hcpaAl
[awk]
$ awk -F'/t' '{ print $29 }' sample.txt [ parse the tab delimited file and print the fields]
[du]
$ du -m --max-depth=1 ~/ | sort -n -k 1
$ du -h --max-depth=1 `pwd`
[locate]
$ /cygdrive/c/2006/locate32_x64-3.1.11.7100/locate configdb | grep apache | grep java
/cygdrive/c/2006/locate32_x64-3.1.11.7100/locate -lDa30 history | li
skathirvel@achdv-skathirev /cygdrive/e/2006
$ updatedb --output=2006.locate.db --localpaths='/cygdrive/e/2006'
skathirvel@achdv-skathirev /cygdrive/e/2007
$ updatedb --output=2007.locate.db --localpaths='e:/2007/'
updatedb --output=/cygdrive/c/2007/2007.locate.db --localpaths='/cygdrive/c/2007 &
$ locate -i --database=/cygdrive/e/2007/2007.locate.db */.pst
Labels:
awk,
eclipse,
perforce,
sed,
shell-scripting,
unix-commands
Unix self extracting shell script stub
#!/bin/sh This Bourne shell script stub program that can be used to install any Java based app in unix-like platforms. When built with a installer builder tool, this bourne shell script becomes an executable self extracting file with application installer (an executable JAR file) that contains the application payload files and platform specific JRE "embedded" to the 'tail' of the script. At runtime, this script performs, among serveral functions, 1. checks if valid JRE is installed on the host box ( needed to run app installer), 2. If not it extracts the JRE that is 'embedded' inside the self extracting shell script and installs it first, 3. resolves the right JRE install path, 4. verify the just installed JRE for integrity 5. perform necessary disk space checks, 6. extract the "embedded" application binary installer JAR file into /tmp directory, 7. Launches the Java based product installer when runs installs the app payload (files and other artifacts). Author : Sakthivel Kathirvel Last updated: Apr 24 2006 initialize() { set +o notify trap handleAbort 2 FIXED_BLOCK_SIZE=1024 DISK_BLOCK_SIZE=512 POSIXLY_CORRECT=1; export POSIXLY_CORRECT pbc=1 # the following file TYPE[S] are defined by builder. Any change to the TYPE number should confirm to the type number defined here. VERIFY_CLASS_TYPE=5 APP_ARCHIVE_TYPE=6 JVM_FILE_TYPE=1 EMBED_JARS_TYPE=3 BIN_FILE_TYPE=7 JVM_INSTALLER_TYPE=4 sv=2 #sv - jvm search&verify result; successful search&verify sets to zero; initializing to non-zero resolve=2 #resolution of matched jvm file result that is required for launching the java app. successful resolution sets to zero; initializing to non-zero verify=2 # verification of a JVM result. successful verification of searched JVM sets to zero; initializing to non-zero install_jvm=2 # result of bundled JVM installation. successful installation sets to zero; initializing to non-zero resolvedJVMVerified=2 #app launcher verifies the embedded resolved JVM file and set the value to 0, if verification is successful. installer launcher does NOT use this. initializing to non-zero. GNU_JVM_TEMP=0 #set to 1 upon the successful installation of bundled JVM; initializing to zero. uimode=2 # the default ui mode of the app is gui which corresponds uimode to non-zero. a console mode sets to zero. [ -z "$disk_space_check_off" ] && disk_space_check_off=0 # disk_space_check_off is not defined, switching it on by default. [ -z "$`date +%F`_HOME" ] && `date +%F`_HOME="$HOME" if [ ! -d "$`date +%F`_HOME" ] ; then mkdir -p "$`date +%F`_HOME" >/dev/null 2>&1 if [ $? -ne 0 ] ; then cls tempLocationErrMesg "$`date +%F`_HOME" cleanupandexit 1 fi fi rand=$$`date '+%j%H%M%S'` rand=`echo "$rand" | sed 's/[a-zA-Z]//g;s/%//g'` if [ `isNumeric $rand` -ne 0 ] ; then rand=$$ fi `date +%F`="$`date +%F`_HOME/`date +%F`$rand" mkdir $`date +%F` >/dev/null 2>&1 if [ $? -ne 0 ] ; then cls tempLocationErrMesg "$`date +%F`" cleanupandexit 1 fi awk 'END{ print "Test file created by installer" >> a ;}' a="$`date +%F`/writecheck" /dev/null if [ -f "$`date +%F`/writecheck" ] ; then rm -f "$`date +%F`/writecheck" else cls tempLocationErrMesg "$`date +%F`" cleanupandexit 1 fi [ -n "$VeryVerbose" ] && dbg "Temp directory used by shell script launcher = $`date +%F`" if [ -n "$LOG" ] ; then [ ! -d `dirname $LOG` ] && LOG=`pwd`/`basename "$LOG"` awk 'END{ s=sprintf("Log file created by Platform installer @%s",b); print s >> a ;}' a="$LOG" b="`date`"/dev/null if [ ! -f "$LOG" ] ; then LOG=/dev/null fi else LOG=/dev/null fi [ `awk 'END{ if(index(a,"-silent") > 0) {print 0; } else { print 2;} }' a="$app_args" /dev/null` -eq 0 ] && SILENT=true [ `awk 'END{ if(index(a,"-console") > 0) {print 0; } else { print 2;} }' a="$app_args" /dev/null` -eq 0 ] && uimode=0 [ -z "$SILENT" ] && setpbmesg [ -z "$pbmesg" ] && pbmesg="Initializing" cls banner } programAborted() { cat << HASTOP Program Aborted. Cleaning up........ HASTOP } handleAbort() { DBG=0 cleanupandexit 1 abort } noJVMFound() { cat << noJVMFoundSTOP This application requires a Java Run Time Environment (JRE) to run. Searching for one on your computer was not successful. Please use the command line switch -javahome to specify a valid JRE. For more help use the option -help. noJVMFoundSTOP } dsCheckFailed() { cat << dsCheckFailedSTOP The directory $`date +%F` does not contain enough space to extract temporary files. Please specify a temporary directory using the -tempdir option. Use the -help option for more information. dsCheckFailedSTOP } cleanupandexit() { pbl if [ \( "$DBG" -ne 1 -a -d "$`date +%F`" \) ] ; then rm -fr "$`date +%F`" fi [ -n "$2" ] && { cls case "$2" in abort) programAborted;; nojvm) noJVMFound;; nospace) dsCheckFailed;; esac } exit $1 } dbg() { if [ "$DBG" -eq 1 ] ; then if [ -n "$LOG" ] ; then echo "$1" >> "$LOG" fi fi } pbl() { [ -z "$SILENT" ] && echo } Timer() { sleep 5 foo=`kill -9 $1 > /dev/null 2>&1` } convert() { echo "ibase=16; $1" | bc } findFullPath() { if [ -x "./$0" ] ; then INSTALLER_PATH="`pwd`/$0" elif [ -x "$0" ] ; then INSTALLER_PATH="$0" fi dbg "INSTALLER_PATH="$INSTALLER_PATH"" } banner() { [ -z "$SILENT" ] && { cat << BSTOP $pbmesg........ BSTOP } } pbclr() { [ -z "$SILENT" ] && { awk ' END { printf("%c",13); printf("%s"," "); i=length(pbmesg); for (k=1 ; k <= i; k++ ) printf("%c",32); }' pbmesg="$pbmesg" /dev/null` case ${num} in "") echo 0;; *) echo 1;; esac else echo 1 fi } extractAll() { findFullPath [ -z "$`date +%F`_HOME" ] && `date +%F`_HOME=`pwd` SILENT=true initialize OFFSET=0 FIXED_BLOCK_SIZE=1024 if [ ! -x "$INSTALLER_PATH" ] ; then dbg "Can't locate the installer archive. Extraction failed." cleanupandexit 100 fi I=0 while [ $I -lt $FILEINDEXCOUNT ] ; do II=`awk 'END{ s=sprintf("$FILEINDEX%s", I); print s }' I=$I /dev/null` eval II=$II dbg "$II" SIZE=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[3] }' II=$II /dev/null` OFFSET=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[4] }' II=$II /dev/null` NAME=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[5] }' II=$II /dev/null` SIZE=`convert $SIZE` OFFSET=`convert $OFFSET` NAME="$`date +%F`/$NAME" dbg "NAME=$NAME SIZE=$SIZE OFFSET=$OFFSET" checkDiskSpace "$SIZE" "$`date +%F`" "$NAME" [ $disk_space_check -ne 0 ] && { DBG=0 cleanupandexit 1 nospace } extractAFile I=`expr $I + 1` done echo "$I files extracted in the directory $`date +%F`" } extractAFile() { [ $VeryVerbose ] && dbg "extracting the file $NAME of SIZE=$SIZE at OFFSET=$OFFSET" if [ "$SIZE" -le "$FIXED_BLOCK_SIZE" ] ; then BOFFSET=`expr $OFFSET / "$FIXED_BLOCK_SIZE"` dd if="$INSTALLER_PATH" of="$`date +%F`/filePadded" bs="$FIXED_BLOCK_SIZE" skip="$BOFFSET" count=1 > /dev/null 2>&1 dd if="$`date +%F`/filePadded" of="$NAME" bs="$SIZE" count=1 > /dev/null 2>&1 rm -f "$`date +%F`/filePadded" else BOFFSET=`expr $OFFSET / "$FIXED_BLOCK_SIZE"` BLOCKS=`expr $SIZE / "$FIXED_BLOCK_SIZE"` BLOCKS=`expr $BLOCKS + 1` dd if="$INSTALLER_PATH" of="$`date +%F`/filePadded" bs="$FIXED_BLOCK_SIZE" skip="$BOFFSET" count=$BLOCKS > /dev/null 2>&1 dd if="$`date +%F`/filePadded" of="$NAME" bs="$SIZE" count=1 > /dev/null 2>&1 rm -f "$`date +%F`/filePadded" fi } extractJVMFiles() { if [ -f "$`date +%F`/jvmfit" ] ; then c=`wc -l "$`date +%F`/jvmfit" | awk '{ print $1 }'` I=1 while [ $I -le $c ] ; do II=`sed -n -e "${I}p" $`date +%F`/jvmfit` SIZE=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[3] }' II=$II /dev/null` OFFSET=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[4] }' II=$II /dev/null` NAME=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[5] }' II=$II /dev/null` SIZE=`convert $SIZE` OFFSET=`convert $OFFSET` NAME="$`date +%F`/$NAME" extractAFile if [ -f "$NAME" ] ; then sed "s/ //;s/^[ ]*//;s/[ ]*$//" "$NAME" >> "$NAME.sed" 2>/dev/null rm -f "$NAME" mv $NAME.sed $NAME echo "$NAME" >> "$`date +%F`/jvmlist" fi I=`expr $I + 1` done fi [ $VeryVerbose ] && { dbg "reading jvm list..." ; if [ -f "$`date +%F`/jvmlist" ] ; then cat "$`date +%F`/jvmlist" >> $LOG 2>/dev/null; fi } } extractVerifyJar() { I=0 while [ $I -lt $FILEINDEXCOUNT ] ; do II=`awk 'END{ s=sprintf("$FILEINDEX%s", I); print s }' I=$I /dev/null` eval II=$II TYPE=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[1]; }' II=$II /dev/null` TYPE=`convert $TYPE` if [ "$TYPE" -eq "$VERIFY_CLASS_TYPE" ] ; then SIZE=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[3] }' II=$II /dev/null` OFFSET=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[4] }' II=$II /dev/null` NAME=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[5] }' II=$II /dev/null` SIZE=`convert $SIZE` OFFSET=`convert $OFFSET` NAME="$`date +%F`/$NAME" extractAFile break fi I=`expr $I + 1` done } makeJVMFit() { I=0 while [ $I -lt $FILEINDEXCOUNT ] ; do II=`awk 'END{ s=sprintf("$FILEINDEX%s", I); print s }' I=$I /dev/null` eval II=$II TYPE=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[1]; }' II=$II /dev/null` TYPE=`convert $TYPE` if [ "$TYPE" -eq "$JVM_FILE_TYPE" ] ; then echo $II >> $`date +%F`/jvmfit fi I=`expr $I + 1` done } writetab() { awk ' BEGIN { processingTag=0 } $0 == "/:" { if (beginprocessingTag == 1) beginprocessingTag=0 ; next } $0 == tag { beginprocessingTag=1; next } { if (beginprocessingTag == 1) { print $0 >> tab; next } } END { } ' tab="$2" tag="$3" "$1" } searchAndVerify() { pbclr pbmesg="Searching JVM" dbg "--------------------------------------------------------------------------------------------" dbg "Searching a JVM using $1" if [ -f "$`date +%F`/pathHint" ] ; then rm -f "$`date +%F`/pathHint" fi JVM_EXE=`awk ' BEGIN { FS=":" } /^JVM_EXE/ { print $2; exit }' "$1" 2>/dev/null` JVM_EXE=`echo "$JVM_EXE" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//;s/\"//g'` if [ -z "$JVM_EXE" ] ; then [ $VeryVerbose ] && dbg "value of JVM_EXE is an empty string in JVM FILE="$JVM_FILE". Trying next JVM File." return else [ $VeryVerbose ] && dbg "value of JVM_EXE=$JVM_EXE in JVM FILE=$JVM_FILE" fi writetab "$1" "$`date +%F`/pathHint" "PATH_HINT:" if [ -f "$`date +%F`/pathHint" ] ; then [ $VeryVerbose ] && { dbg "using path hints in the JVM file $1"; } pathHintc=`wc -l "$`date +%F`/pathHint" | awk '{ print $1 }'` pathHintcc=1 while [ $pathHintcc -le $pathHintc ] ; do pbc=`expr $pbc + 1` pb PathHint=`sed -n -e "${pathHintcc}p;s/^[ ]*//;s/[ ]*$//" "$`date +%F`/pathHint"` if [ -f "$1.fr" ] ; then rm -f "$1.fr" fi [ $VeryVerbose ] && dbg "using the pathHint=$PathHint." if [ -d "$PathHint" ] ; then for x in $PathHint ; do if [ -x "$x/$JVM_EXE" ] ; then echo "$x/$JVM_EXE" >> "$1.fr.shellxpansion" fi if [ -x "$x/jre/$JVM_EXE" ] ; then echo "$x/jre/$JVM_EXE" >> "$1.fr.shellxpansion" fi done [ $VeryVerbose ] && { dbg "reading find result from shell expansion..." ; cat "$1.fr.shellxpansion" >> $LOG 2>/dev/null; } fi find $PathHint/$JVM_EXE > "$1.fr.findcommand" 2>/dev/null if [ $? -eq 0 ] ; then if [ -f "$1.fr.findcommand" ] ; then [ $VeryVerbose ] && { dbg "reading find result from find command..." ; cat "$1.fr.findcommand" >> $LOG 2>/dev/null; } frc=`wc -l "$1.fr.findcommand" | awk '{ print $1 }'` frcc=1 while [ $frcc -le $frc ] ; do frl=`sed -n -e "${frcc}p" "$1.fr.findcommand"` grep "$frl" "$1.fr.shellxpansion" 1>/dev/null 2>&1 if [ $? -ne 0 ] ; then echo "$frl" >> "$1.fr.shellxpansion" fi frcc=`expr $frcc + 1` done fi fi if [ -f "$1.fr.findcommand" ] ; then rm -f "$1.fr.findcommand" fi if [ -f "$1.fr.shellxpansion" ] ; then mv "$1.fr.shellxpansion" "$1.fr" rm -f "$1.fr.shellxpansion" fi if [ -f "$1.fr" ] ; then [ $VeryVerbose ] && { dbg "reading find result after merging..." ; cat "$1.fr" >> $LOG 2>/dev/null; } frc=`wc -l "$1.fr" | awk '{ print $1 }'` frcc=1 while [ $frcc -le $frc ] ; do frl=`sed -n -e "${frcc}p" "$1.fr"` jvm_exe=`echo $JVM_EXE | sed 's/\//\\\\\//g'` VerifyJVM "$1" "$frl" if [ $verify -eq 0 ] ; then J=`echo "$frl" | sed "s/${jvm_exe}//"` J=`echo "$J" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//'` echo "JVM_HOME:$J" >> "$1" RESOLVED_JVM="$1" sv=0 dbg "Verification passed for $frl using the JVM file $1." rm -f "$1.fr" return else dbg "Verification failed for $frl using the JVM file $1." fi frcc=`expr $frcc + 1` done else [ $VeryVerbose ] && { dbg "find result is empty for the pathhint=$PathHint"; } fi pathHintcc=`expr $pathHintcc + 1` done else dbg "path hint is not specified in the JVM file $1" fi } VerifyJVM() { pbclr pbmesg="Verifying JVM" pb [ ! -f "$`date +%F`/Verify.jar" ] && extractVerifyJar awk ' BEGIN { begin=0; i=1 } $0 == "/:" { if (begin == 1) begin=0 ; next; } $0 == tag { begin=1; next; } { if (begin== 1) { item[i]=$0; i++; next; } } END { for (k=1; k < i; k++) print item[k] >> tab; } ' tab="$`date +%F`/sp" tag="JVM_PROPERTIES:" "$1" 2>/dev/null if [ -f "$`date +%F`/sp" ] ; then spc=`wc -l "$`date +%F`/sp" | awk '{ print $1 }'` spcc=1 systemprops= while [ $spcc -le $spc ] ; do spl=`sed -n -e "${spcc}p" "$`date +%F`/sp"` spl=`echo "$spl" | sed 's/\"//g'` systemprops=`awk 'END { i=index(spl,"="); s=substr(spl,1,i-1); ss=sprintf("%s %s", sp, s); print ss; } ' spl="$spl" sp="$systemprops" /dev/null` spcc=`expr $spcc + 1` done jvm_classpath= cp_switch=`awk 'BEGIN{ FS=":"} $1 == tag { print $2; exit; }' tag=CLASSPATH $1` cp_switch=`echo "$cp_switch" | sed 's/\"//g'` jvm_classpath=`awk 'BEGIN { FS=":" } $1 == tag { i=index($0,":"); s=substr($0,i+1); print s; exit; }' tag=JVM_CLASSPATH $1` if [ -z "$jvm_classpath" ] ; then dbg "Verifying... $2 $cp_switch $`date +%F`/Verify.jar Verify $systemprops" eval "$2" $cp_switch "$`date +%F`/Verify.jar" Verify $systemprops 1>"$`date +%F`/jvmout" 2>/dev/null& bgpid=$! Timer $bgpid& wait $bgpid 1>/dev/null 2>&1 else jb=`awk 'BEGIN { FS=":" } $1 == tag { i=index($0,":"); s=substr($0,i+1); print s; exit; }' tag=JVM_EXE $1 2>/dev/null` jb=`echo "$jb" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//'` jb=`echo "$jb" | sed 's/\//\\\\\//g'` JVM_HOME=`echo "$2" | sed "s/${jb}//"` eval jvm_classpath="$jvm_classpath" dbg "Verifying... $2 $cp_switch $jvm_classpath:$`date +%F`/Verify.jar Verify $systemprops" eval "$2" $cp_switch "$jvm_classpath":"$`date +%F`/Verify.jar" Verify $systemprops 1>"$`date +%F`/jvmout" 2>/dev/null& bgpid=$! Timer $bgpid& wait $bgpid 1>/dev/null 2>&1 JVM_HOME= fi if [ -f "$`date +%F`/jvmout" ] ; then spc=`wc -l "$`date +%F`/sp" | awk '{ print $1 }'` spcc=1 systemprops= while [ $spcc -le $spc ] ; do spl=`sed -n -e "${spcc}p" "$`date +%F`/sp"` spl=`echo $spl | sed 's/\"//g'` jvmfilevalue=`awk 'END { i=index(spl,"="); s=substr(spl,i+1); print s } ' spl="$spl" sp="$systemprops" /dev/null` jvmoutc=`expr $spcc + 1` jvmout=`sed -n -e "${jvmoutc}p" "$`date +%F`/jvmout"` verify=`awk ' END { exactMatch=1 verify=2 len = length(jvmfilevalue) for (k = len ; k >len-3 ; k--) { char=substr(jvmfilevalue, k, 1); s = sprintf("%s%s", s,char); } if (length(s) == length("...")) { if ( index(s, "...") == 1) { exactMatch=0 } } if (exactMatch == 1) { if ( (length(jvmfilevalue) == length(jvmout)) && (index(jvmfilevalue, jvmout) == 1) ) verify=0 } else { jvmfilevalue_prefix=substr(jvmfilevalue, 1, len-3) if (index(jvmout,jvmfilevalue_prefix) == 1 ) verify=0 } if (length(VeryVerbose) > 0) { printf("jvm system property specified in jvm file=%s\n",jvmfilevalue) >> ilog printf("jvm system property from running Verify diagnostics on the JVM=%s\n",jvmout) >> ilog if (verify == 0) { if (exactMatch == 1) { print "exact match of system property succeeded" >> ilog } else { print "non-exact match of system property succeeded" >> ilog } } else { if (exactMatch == 1) { print "exact match of system property failed" >> ilog } else { print "non-exact match of system property failed" >> ilog } } } print verify } ' jvmout="$jvmout" jvmfilevalue="$jvmfilevalue" VeryVerbose="$VeryVerbose" ilog="$LOG" /dev/null` if [ $verify -ne 0 ] ; then break fi spcc=`expr $spcc + 1` done else dbg "$`date +%F`/jvmout does not exist. JVM Verification process may have failed." fi else dbg "system properties are not specified in "$1"" fi rm -f "$`date +%F`/sp" rm -f "$`date +%F`/jvmout" } searchParitions() { for i in $1 ; do find ${i} -type d \ \( -name '*[jJ][dD][kK]*' \ -o -name '*[jJ][rR][eE]*' \ -o -name '*[jJ][aA][vV][aA]*' \ -o -name '*[jJ]2[rR][eE]*' \ -o -name '*[jJ]2[sS][eE]*' \ \) >> "$`date +%F`/searchParitionsResult" 2>/dev/null done } writesptab() { sed 's/^[ ]*//;s/[ ]*$//' "$1" >> "$1.tmp" 2>/dev/null mv "$1.tmp" "$1" awk ' BEGIN { begin=0; i=1} $0 == "/:" { if (begin == 1) begin=0 ; next; } $0 == tag { begin=1; next; } { if (begin== 1) { item[i]=$0; i++; next; } } END { for (k=1; k < i; k++) { s=sprintf("%s%s;",s,item[k]); } s=sprintf("%s%s",s,JF); print s >> tab } ' JF="$1" tab="$`date +%F`/sp" tag="JVM_PROPERTIES:" "$1" 2>/dev/null } verifyJavaHome() { if [ -f "$`date +%F`/jvmlist" ] ; then jvmlc=`wc -l "$`date +%F`/jvmlist" | awk '{ print $1 }'` cc=1 while [ $cc -le $jvmlc ] ; do JVM_FILE=`sed -n -e "${cc}p" "$`date +%F`/jvmlist" 2>/dev/null` if [ -f "$JVM_FILE" ] ; then JVM_EXE=`awk ' BEGIN { FS=":" } /^JVM_EXE/ { print $2; exit }' "$JVM_FILE"` JVM_EXE=`echo "$JVM_EXE" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//;s/\"//g'` if [ -z "$JVM_EXE" ] ; then [ $VeryVerbose ] && dbg "value of JVM_EXE is an empty string in JVM FILE="$JVM_FILE". Trying next JVM File" continue else [ $VeryVerbose ] && dbg "value of JVM_EXE=$JVM_EXE in JVM FILE="$JVM_FILE"" fi if [ -x "$JAVA_HOME/$JVM_EXE" ] ; then [ $VeryVerbose ] && dbg "Verifying $JAVA_HOME using the JVM file $JVM_FILE" VerifyJVM "$JVM_FILE" "$JAVA_HOME/$JVM_EXE" if [ $verify -eq 0 ] ; then J="$JAVA_HOME" J=`echo "$J" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//'` echo "JVM_HOME:$J" >> "$JVM_FILE" RESOLVED_JVM="$JVM_FILE" sv=0 dbg "Verification passed for $JAVA_HOME using the JVM file $JVM_FILE." return else dbg "Verification failed for $JAVA_HOME using the JVM file $JVM_FILE" fi fi fi cc=`expr $cc + 1` done else [ $VeryVerbose ] && dbg "jvm files not specified. Verification cannot be performed for JVM specfied using $JAVA_HOME" fi } checkEnvironment() { dbg "Checking the environment variables specifed in the JVM files to find the JVM..." if [ -f "$`date +%F`/jvmlist" ] ; then checkEnvlc=`wc -l "$`date +%F`/jvmlist" | awk '{ print $1 }'` checkEnvcc=1 while [ $checkEnvcc -le $checkEnvlc ] ; do checkEnvJvmFile=`sed -n -e "${checkEnvcc}p" "$`date +%F`/jvmlist" 2>/dev/null` for pathVariable in `echo $PATH|sed 's/:/ /g'` do if [ -x "$pathVariable/java" ] ; then VerifyJVM "$checkEnvJvmFile" "$pathVariable/java" if [ $verify -eq 0 ] ; then pathVariable=`echo $pathVariable | sed 's/\/bin//g'` echo "JVM_HOME:$pathVariable" >> "$checkEnvJvmFile" RESOLVED_JVM="$checkEnvJvmFile" sv=0 dbg "Verification passed for $pathVariable/$checkEnvJvmExe using the JVM file $checkEnvJvmFile." return fi fi done checkEnvJvmExe=`awk ' BEGIN { FS=":" } /^JVM_EXE/ { print $2; exit }' "$checkEnvJvmFile" 2>/dev/null` checkEnvJvmExe=`echo "$checkEnvJvmExe" | sed 's/^[ ]*//;s/[ ]*$//'` if [ -z "$checkEnvJvmExe" ] ; then [ $VeryVerbose ] && dbg "value of JVM_EXE is an empty string in JVM FILE="$checkEnvJvmFile". Trying next JVM File." checkEnvcc=`expr $checkEnvcc + 1` continue else [ $VeryVerbose ] && dbg "value of JVM_EXE=$JVM_EXE in JVM FILE=$checkEnvJvmFile" fi if [ -f "$`date +%F`/platformHint" ] ; then rm -f "$`date +%F`/platformHint" fi writetab "$checkEnvJvmFile" "$`date +%F`/platformHint" "PLATFORM_HINT:" if [ -f "$`date +%F`/platformHint" ] ; then [ $VeryVerbose ] && dbg "using platform hints or environment variables in the JVM file $checkEnvJvmFile" platformHintlc=`wc -l "$`date +%F`/platformHint" | awk '{ print $1 }'` platformHintcc=1 while [ $platformHintcc -le $platformHintlc ] ; do platformHintLine=`sed -n -e "${platformHintcc}p;s/^[ ]*//;s/[ ]*$//" "$`date +%F`/platformHint" | sed 's/\(.*\)/$\1/'` eval platformHintEvaled=$platformHintLine if [ -n "$platformHintEvaled" ] ; then if [ -x "$platformHintEvaled/$checkEnvJvmExe" ] ; then dbg "A jvm found at $platformHintEvaled/$checkEnvJvmExe" VerifyJVM "$checkEnvJvmFile" "$platformHintEvaled/$checkEnvJvmExe" if [ $verify -eq 0 ] ; then platformHintEvaled=`echo "$platformHintEvaled" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//'` echo "JVM_HOME:$platformHintEvaled" >> "$checkEnvJvmFile" RESOLVED_JVM="$checkEnvJvmFile" sv=0 dbg "Verification passed for $platformHintEvaled/$checkEnvJvmExe using the JVM file $checkEnvJvmFile." return else dbg "Verification failed for $platformHintEvaled/$checkEnvJvmExe using the JVM file $checkEnvJvmFile." fi fi else dbg "$platformHintLine is not defined in the shell environment specifed in the JVM FILE `basename $checkEnvJvmFile`" fi platformHintcc=`expr $platformHintcc + 1` done else dbg "platform hints or environment variables are not specified in the JVM file $checkEnvJvmFile" fi checkEnvcc=`expr $checkEnvcc + 1` done else [ $VeryVerbose ] && dbg "jvm files not specified in the launcher. Environment Variables cannot be checked." fi } searchJVM() { makeJVMFit extractJVMFiles [ "$JAVA_HOME" ] && { dbg "command line switch -javahome is specified. Verifying the JVM with the JVM files specifed with the launcher." verifyJavaHome if [ $sv -eq 0 ] ; then return else dbg "JVM specified with -javahome cannot be verified with the JVM files specified with the launcher. Environment Variables will be checked next..." fi } checkEnvironment if [ $sv -eq 0 ] ; then return else dbg "No JVM can be found using the shell environment variable. Searching JVM will continue with Path Hints specified in the JVM Files..." fi JVM_FILE= if [ -f "$`date +%F`/jvmlist" ] ; then jvmlc=`wc -l "$`date +%F`/jvmlist" | awk '{ print $1 }'` cc=1 while [ $cc -le $jvmlc ] ; do JVM_FILE=`sed -n -e "${cc}p" "$`date +%F`/jvmlist" 2>/dev/null` if [ -f "$JVM_FILE" ] ; then searchAndVerify "$JVM_FILE" if [ $sv -eq 0 ] ; then dbg "jvm found and verification passed for $JVM_FILE." break fi fi cc=`expr $cc + 1` done else dbg "jvm files not specified. Searching a JVM cannot be performed." fi } aggregatecp() { aggregatecpc=`wc -l "$1" | awk '{ print $1 }'` aggregatecpcc=1 while [ $aggregatecpcc -le $aggregatecpc ] ; do aggregatecpl=`sed -n -e "${aggregatecpcc}p" "$1" 2>/dev/null` aggregatecpl=`echo "$aggregatecpl" | sed 's/\"//g' 2>/dev/null` AGGREGATECP=`awk ' END { s=sprintf("%c%s%c",34,b,34); s=sprintf("%s:%s",a,s); printf s }' a="$AGGREGATECP" b="$aggregatecpl" /dev/null` aggregatecpcc=`expr $aggregatecpcc + 1` done echo "$AGGREGATECP" } extractArchiveJar() { [ -n "$VeryVerbose" ] && dbg "Installer JAR archive is embedded. Extracting ..." I=0 while [ $I -lt $FILEINDEXCOUNT ] ; do II=`awk 'END{ s=sprintf("$FILEINDEX%s", I); print s }' I=$I /dev/null` eval II=$II TYPE=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[1]; }' II=$II /dev/null` TYPE=`convert $TYPE` if [ "$TYPE" -eq "$APP_ARCHIVE_TYPE" ] ; then SIZE=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[3] }' II=$II /dev/null` OFFSET=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[4] }' II=$II /dev/null` NAME=`awk 'END{ split(II,FIELDS, ":"); print FIELDS[5] }' II=$II /dev/null` SIZE=`convert $SIZE` OFFSET=`convert $OFFSET` NAME="$`date +%F`/$NAME" checkDiskSpace "$SIZE" "$`date +%F`" "$NAME" [ $disk_space_check -ne 0 ] && cleanupandexit 1 nospace pbclr pbmesg="Extracting Installation Archive" pb extractAFile INSTALLER_ARCHIVE="$NAME" break fi I=`expr $I + 1` done } extractEmbeddedJar() { embeddedJarc=0 while [ $embeddedJarc -lt $FILEINDEXCOUNT ] ; do FI_KEY=`awk 'END{ s=sprintf("$FILEINDEX%s", I); print s }' I=$embeddedJarc /dev/null` eval FI_VALUE=$FI_KEY TYPE=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[1]; }' a=$FI_VALUE /dev/null` TYPE=`convert $TYPE` if [ "$TYPE" -eq $EMBED_JARS_TYPE ] ; then SIZE=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[3] }' a=$FI_VALUE /dev/null` OFFSET=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[4] }' a=$FI_VALUE /dev/null` NAME=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[5] }' a=$FI_VALUE /dev/null` SIZE=`convert $SIZE` OFFSET=`convert $OFFSET` NAME="$`date +%F`/$NAME" dbg "extracting embedded jars in the archive." checkDiskSpace "$SIZE" "$`date +%F`" "$NAME" [ $disk_space_check -ne 0 ] && cleanupandexit 1 nospace extractAFile EMBEDDED_JARS=`awk ' END { s=sprintf("%c%s%c",34,b,34); s=sprintf("%s:%s",a,s); printf s }' a="$EMBEDDED_JARS" b="$NAME" /dev/null` fi embeddedJarc=`expr $embeddedJarc + 1` done } parseJavaArgs() { awk '$0 !~ /^-/ && /.*,.*/{ if (length($0) > 1 ) { t=split($0,FIELDS,",") if (t == 2) print FIELDS[2]; } } /^-/{ printf("%s\n",$0); }' | sed 's/\\//g;s/)//;s/^[ ]*//;s/[ ]*$//;s/^\"//;s/\"$//;s/@\(.*\)@\(.*\)/\1=\2/' >> "$`date +%F`/javaargs" } aggregateJavaArgs() { #/dev/null` -ne 1 ] ; then javaArgsResolved=`awk '{ split(A, FIELDS,"="); if ( index($0, FIELDS[1]) == 1 ) { i=index($0, ":") ; if ( i > 1 ) { s=substr($0, i+1); if (length(FIELDS[2]) > 0) { s=sprintf("%s%s",s, FIELDS[2]); } print s; exit; } } }' A="$javaArgsl" "$1"` if [ -n "$javaArgsResolved" ] ; then [ -n "$VeryVerbose" ] && dbg "Java Argument `echo "$javaArgsl" | cut -d= -f1` is resolved to $javaArgsResolved in the JVM FILE $1" else dbg "Java argument `echo "$javaArgsl" | cut -d= -f1` is not defined in the JVM file $1." fi else javaArgsResolved="$javaArgsl" [ -n "$VeryVerbose" ] && dbg "using literal Java Argument $javaArgsResolved" fi if [ -n "$javaArgsResolved" ] ; then JAVA_ARGS=`awk 'END{ printf("%s %s", a, b); }' a="$javaArgsResolved" b="$JAVA_ARGS" /dev/null` fi javaArgscc=`expr $javaArgscc + 1` done } resolveRuntimeJavaArgs() { [ -n "$VeryVerbose" ] && dbg "resolving runtime java args" jaFile=`modifyFileName "$INSTALLER_PATH" ja` if [ -f "$jaFile" ] ; then cat "$jaFile" | sed 's/%IF_EXISTS%//' | parseJavaArgs else dbg "Run time Java arguments are not specified." fi } resolveBuildTimeJavaArgs() { [ -n "$VeryVerbose" ] && dbg "resolving buildtime java args" if [ -n "$JAVA_ARGS_UNRESOLVED" ] ; then echo "$JAVA_ARGS_UNRESOLVED" | sed 's/%IF_EXISTS%//g;s/) */+/g;s/\(-[^ .]*\)/\1+/g' | tr '+' '\012' | sed 's/^[ ]*//;s/[ ]*$//' | parseJavaArgs [ \( -f "$`date +%F`/javaargs" -a -n "$VeryVerbose" \) ] && cp "$`date +%F`/javaargs" "$`date +%F`/javaargs.buildtime" else dbg "Build time Java arguments are not specified." fi } modifyFileName() { installerDir=`dirname "$1"` installerDir=`echo "$installerDir" | sed 's/\//\\\\\//g'` awk 'END { t=split(a,FIELDS,"."); if ( t > 1 ) { for (i=1; i<=t-1;i++) s=sprintf("%s.%s",s,FIELDS[i]); } else { s=a; } print s; }' a=`basename "$1"` /dev/null | sed "s/^\.//;s/\.$//;s/\(.*\)/${installerDir}\/\1.${2}/" } processCommandLineCP() { if [ `awk 'END{ if (index(a,"@") == 1) print 0 ; else print 1; }' a="$1" /dev/null` -eq 0 ] ; then file=`awk 'END{ s=substr(a, 2); print s; }' a="$1" /dev/null` [ -f "$file" ] && CommandLineCP=`aggregatecp "$file"` else CommandLineCP=`awk 'END{ t=split(a,FIELDS,":"); for ( i=1; i<=t; i++) { if ( length(FIELDS[i]) > 0 ) { quotedCPItem=sprintf("%c%s%c",34,FIELDS[i],34); s=sprintf("%s:%s",s,quotedCPItem); } } printf s; }' a="$1" /dev/null` fi echo "$CommandLineCP" | sed 's/^://' } resolveLaunchCommand() { if [ -f "$1" ] ; then JVM_HOME=`awk 'BEGIN { FS=":" } $1 == tag { i=index($0,":"); s=substr($0,i+1); print s; exit; }' tag=JVM_HOME "$1" 2>/dev/null` JVM_HOME=`echo "$JVM_HOME" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//'` [ ! -d "$JVM_HOME" ] && { dbg "JavaHome is not resolved correctly in the jvm file $1. Failed to launch the application." return } JVM_EXE=`awk 'BEGIN { FS=":" } $1 == tag { i=index($0,":"); s=substr($0,i+1); print s; exit; }' tag=JVM_EXE "$1" 2>/dev/null` JVM_EXE=`echo "$JVM_EXE" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//;s/\"//g'` [ -z "$JVM_EXE" ] && { dbg "Javaexe is not resolved correctly or empty in the jvm file $1. Failed to launch the application." return } CLASSPATH_SWITCH=`awk 'BEGIN{ FS=":"} $1 == tag { print $2; exit; }' tag=CLASSPATH "$1" 2>/dev/null` CLASSPATH_SWITCH=`echo "$CLASSPATH_SWITCH" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//;s/\"//g'` [ -z $CLASSPATH_SWITCH ] && { dbg "Classpath switch is not specified in the jvm file $1. Failed to launch the application." return } if [ -n "$CP_P" ] ; then PREPEND_CLASSPATH=`processCommandLineCP "$CP_P"` else dbg "-cp:p operand is empty" fi if [ -n "$CP_A" ] ; then APPEND_CLASSPATH=`processCommandLineCP "$CP_A"` else dbg "-cp:a operand is empty" fi cp1File=`modifyFileName "$INSTALLER_PATH" cp1` [ -f "$cp1File" ] && { CP1=`aggregatecp "$cp1File"` dbg "classpath specified in the $cp1File=$CP1" } JVM_CLASSPATH=`awk 'BEGIN { FS=":" } $1 == tag { i=index($0,":"); s=substr($0,i+1); print s; exit; }' tag=JVM_CLASSPATH "$1" 2>/dev/null` cpFile=`modifyFileName "$INSTALLER_PATH" cp` [ -f "$cpFile" ] && { CP=`aggregatecp "$cpFile"` dbg "classpath specified in the $cpFile=$CP" } if [ -z "$APPLICATION_ARCHIVE" ] ; then dbg "Installer JAR archive is not embedded." APPLICATION_ARCHIVE= elif [ "$APPLICATION_ARCHIVE" = EMBED ] ; then extractArchiveJar if [ -f "$INSTALLER_ARCHIVE" ] ; then archiveSize=`wc -c "$INSTALLER_ARCHIVE" | awk '{ if ( $1 ~ /^[0-9]/ ) print $1 ; else print 0; }' 2>/dev/null` if [ $archiveSize -ne $SIZE ] ; then archiveSize=`ls -l "$INSTALLER_ARCHIVE" | awk '{ if ( $5 ~ /^[0-9]/ ) print $5 ; else print 0; }' 2>/dev/null` if [ $archiveSize -ne $SIZE ] ; then dbg "Extracted Installer JAR archive file size incorrect. archive may be corrupt. Failed to launch the application." return else APPLICATION_ARCHIVE="$INSTALLER_ARCHIVE" fi else APPLICATION_ARCHIVE="$INSTALLER_ARCHIVE" fi else dbg "Error extracting Installer JAR archive from shell script wrapper. Failed to launch the application." return fi elif [ -n "$APP_ORIG_HOME" ] ; then if [ -f "$APP_ORIG_HOME"/"$APPLICATION_ARCHIVE" ] ; then dbg "Installer JAR archive is not embedded. Copying from $APP_ORIG_HOME/$APPLICATION_ARCHIVE" rclSize=`wc -c "$APP_ORIG_HOME/$APPLICATION_ARCHIVE" | awk '{ if ( $1 ~ /^[0-9]/ ) print $1 ; else print 0; }' 2>/dev/null` checkDiskSpace "$rclSize" "$`date +%F`" "$APP_ORIG_HOME/$APPLICATION_ARCHIVE" [ $disk_space_check -ne 0 ] && cleanupandexit 1 nospace cp "$APP_ORIG_HOME/$APPLICATION_ARCHIVE" "$`date +%F`/$APPLICATION_ARCHIVE" if [ $? -eq 0 ] ; then INSTALLER_ARCHIVE="$`date +%F`/$APPLICATION_ARCHIVE" else dbg "Error copying the Installer JAR archive from the CD media to temp location on the host machine. Failed to launch the application." return fi else dbg "Installer JAR archive is not located in the CD media location. Failed to launch the application." return fi else dbg "CD media location is not defined and Installer JAR archive cannot be located. Failed to launch the application." return fi [ -n "$INSTALLER_ARCHIVE" ] && INSTALLER_ARCHIVE=`awk 'END { s=sprintf("%c%s%c",34,a,34); print s; }' a="$INSTALLER_ARCHIVE" /dev/null` extractEmbeddedJar cp2File=`modifyFileName "$INSTALLER_PATH" cp2` [ -f "$cp2File" ] && { CP2=`aggregatecp "$cp2File"` dbg "classpath specified in the $cp2File=$CP2" } spFile=`modifyFileName "$INSTALLER_PATH" sp` [ -f "$spFile" ] && { runtimespc=`wc -l "$spFile" | awk '{ print $1 }'` runtimespcc=1 while [ $runtimespcc -le $runtimespc ] ; do runtimespl=`sed -n -e "${runtimespcc}p" "$spFile" 2>/dev/null` RUNTIME_SYSTEMPROP=`awk 'END{ s=sprintf("%s -D%s ",a,b); print s; }' a="$RUNTIME_SYSTEMPROP" b="$runtimespl" /dev/null` runtimespcc=`expr $runtimespcc + 1` done dbg "java runtime system properties specified in $spFile file = $RUNTIME_SYSTEMPROP" } resolveBuildTimeJavaArgs "$1" # javaArgsc=`wc -l "$2" | awk '{ print $1 }'` javaArgscc=1 while [ $javaArgscc -le $javaArgsc ] ; do javaArgsl=`sed -n -e "${javaArgscc}p" "$2"` javaArgsl=`echo "$javaArgsl" | sed 's/^[ ]*//;s/[ ]*$//'` if [ `awk 'END { print index(a,"-") }' a="$javaArgsl" resolveRuntimeJavaArgs "$1" # /dev/null` eval FI_VALUE=$FI_KEY TYPE=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[1]; }' a=$FI_VALUE /dev/null` TYPE=`convert $TYPE` if [ "$TYPE" -eq $JVM_INSTALLER_TYPE ] ; then SIZE=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[3] }' a=$FI_VALUE /dev/null` OFFSET=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[4] }' a=$FI_VALUE /dev/null` NAME=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[5] }' a=$FI_VALUE /dev/null` SIZE=`convert $SIZE` OFFSET=`convert $OFFSET` NAME="$`date +%F`/$NAME" dbg "Extracting bundled JRE..." pbclr pbmesg="Extracting Bundled JRE" pb checkDiskSpace "$SIZE" "$`date +%F`" "$NAME" [ $disk_space_check -ne 0 ] && cleanupandexit 1 nospace extractAFile break fi installJVMc=`expr $installJVMc + 1` done if [ ! -f "$NAME" ] ; then dbg "$NAME is not found. Error extracting bundled JRE. Failed to launch the application." return else [ $VeryVerbose ] && dbg "extracting bundled JRE successful." fi whereAmI=`pwd` mkdir "$`date +%F`/_bundledJRE_" >/dev/null 2>&1 checkDiskSpace "$NAME" "$`date +%F`" [ $disk_space_check -ne 0 ] && cleanupandexit 1 nospace cd "$`date +%F`/_bundledJRE_" dbg "installing bundled JRE..." pbclr pbmesg="Installing Bundled JRE" pb "$NAME" -qq >/dev/null 2>&1 if [ $? -ne 0 ] ; then cd "$whereAmI" dbg "Error installing bundled JRE. Failed to launch the application." rm -f "$NAME" return else cd "$whereAmI" [ $VeryVerbose ] && dbg "installing bundled JRE successful." rm -f "$NAME" fi chmod -R 744 "$`date +%F`/_bundledJRE_" > /dev/null 2>&1 if [ -f "$`date +%F`/_bundledJRE_/jvm" ] ; then sed "s/ //;s/^[ ]*//;s/[ ]*$//" "$`date +%F`/_bundledJRE_/jvm" >> "$`date +%F`/_bundledJRE_/jvm.sed" 2>/dev/null mv "$`date +%F`/_bundledJRE_/jvm.sed" "$`date +%F`/_bundledJRE_/jvm" else dbg "Invalid bundled JRE. jvm file is missing. Installation of bundled JRE is not successful." return fi JVM_EXE=`awk 'BEGIN { FS=":" } /^JVM_EXE/ { print $2; exit }' "$`date +%F`/_bundledJRE_/jvm" 2>/dev/null` if [ -z "$JVM_EXE" ] ; then dbg "value of JVM_EXE is an empty string in JVM FILE=$`date +%F`/_bundledJRE_/jvm. Bundled JRE jvm file is incorrect. Installation of bundled JRE is not successful." return else [ $VeryVerbose ] && dbg "value of JVM_EXE=$JVM_EXE in JVM FILE=$`date +%F`/_bundledJRE_/jvm" fi JVM_EXE=`echo "$JVM_EXE" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//;s/\"//g'` if [ -x "$`date +%F`/_bundledJRE_/$JVM_EXE" ] ; then [ $VeryVerbose ] && dbg "Verifying $`date +%F`/_bundledJRE_/$JVM_EXE using the JVM file $`date +%F`/_bundledJRE_/jvm" VerifyJVM "$`date +%F`/_bundledJRE_/jvm" "$`date +%F`/_bundledJRE_/$JVM_EXE" if [ $verify -eq 0 ] ; then J="$`date +%F`/_bundledJRE_" J=`echo "$J" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//'` echo "JVM_HOME:$J" >> "$`date +%F`/_bundledJRE_/jvm" RESOLVED_JVM="$`date +%F`/_bundledJRE_/jvm" GNU_JVM_TEMP=1 install_jvm=0 dbg "Verification passed for $`date +%F`/_bundledJRE_ using the JVM file $`date +%F`/_bundledJRE_/jvm." return else dbg "Verification failed for $`date +%F`/_bundledJRE_ using the JVM file $`date +%F`/_bundledJRE_/jvm" fi else dbg "$`date +%F`/_bundledJRE_/$JVM_EXE does not exist. Bundled JRE is not a working JVM. Installation of bundled JRE is not successful." return fi } checkDiskSpace() { [ "$disk_space_check_off" -eq 1 ] && { disk_space_check=0 dbg "disk space checking turned off/skipped". return } disk_space_check=2 # disk space check result; successful check sets it to 0; initializing to non-zero value cdsBlocksRequired=reset #will be assigned to a numeric value; initializing to a non-numeric value cdsAvailable=reset #will be assigned to a numeric value; initializing to a non-numeric value mkdir "$`date +%F`/emptydir" # Linux reports the default block-size in 1024 bytes units. Forcing it to report in 512 bytes units. du --block-size=$DISK_BLOCK_SIZE "$HOME" 2>/dev/null 1>&2 if [ $? -eq 0 ] ; then cdsDefaultBlocksAllocated=`du --block-size=$DISK_BLOCK_SIZE "$`date +%F`/emptydir" | awk '{ if ( $1 ~ /^[0-9]/ ) print $1 ; else print 0; }' 2>/dev/null` else cdsDefaultBlocksAllocated=`du "$`date +%F`/emptydir" | awk '{ if ( $1 ~ /^[0-9]/ ) print $1 ; else print 0; }' 2>/dev/null` fi [ $VeryVerbose ] && dbg "default blocks allocated by the filesystem=$cdsDefaultBlocksAllocated" rm -fr "$`date +%F`/emptydir" if [ -f "$1" ] ; then dbg "checking disk space on the parition $2 for $1" [ ! -x "$1" ] && chmod 744 "$1" >/dev/null 2>&1 "$1" -t >/dev/null 2>&1 [ $? -ne 0 ] && { dbg "Bundled JRE is not binary compatible with host OS/Arch or it is corrupt. Testing bundled JRE failed." return } cdsUnZipFileSize=`"$1" -c | wc -c | awk '{ if ( $1 ~ /^[0-9]/ ) print $1 ; else print 0; }' 2>/dev/null` [ $VeryVerbose ] && dbg "Unziped file size = $cdsUnZipFileSize" [ "$cdsUnZipFileSize" -eq 0 ] && { dbg "Error calculating the uncompressed size of bundled JRE or it is corrupt. Installation of bundled JRE failed." return } cdsFilesCount=`"$1" -t | wc -l | awk '{ if ( $1 ~ /^[0-9]/ ) print $1 ; else print 0; }' 2>/dev/null` [ $VeryVerbose ] && dbg "Unziped file count = $cdsFilesCount" [ "$cdsFilesCount" -eq 0 ] && { dbg "Error calculating the file count of bundled JRE or it is corrupt. Installation of bundled JRE failed." return } cdsBlocksRequired=`echo \("$cdsUnZipFileSize" \/ \("$DISK_BLOCK_SIZE" - \("$DISK_BLOCK_SIZE" \* 1\/100\)\)\) + \("$cdsFilesCount" \* "$cdsDefaultBlocksAllocated" \) | bc` elif [ `isNumeric $1` -eq 0 ] ; then [ -n "$3" ] && dbg "checking disk space on the parition $2 for $3" cdsBlocksRequired=`echo "$1" \/ \($DISK_BLOCK_SIZE - \($DISK_BLOCK_SIZE \* 1/100\)\) + "$cdsDefaultBlocksAllocated" | bc` else dbg "Internal Disk space check error. Size of file to be copied or extracted to the host file system is reported incorrectly." return fi if [ `isNumeric $cdsBlocksRequired` -ne 0 ] ; then dbg "Error calculating required file blocks. " [ $VeryVerbose ] && dbg "required 512 blocks for $3 = $cdsBlocksRequired" return else dbg "$cdsBlocksRequired 512 bytes disk blocks required." fi [ -z "$FREE_BLOCKS_COLUMN" ] && FREE_BLOCKS_COLUMN=4 if [ -n "$FREE_DISK_BLOCKS" ] ; then cdsAvailable="$FREE_DISK_BLOCKS" else # gnu df by default reports the free blocks in 1K size, forcing it to report to 512 sizes df -P --block-size="$DISK_BLOCK_SIZE" "$2" 2>/dev/null 1>&2 if [ $? -eq 0 ] ; then # Linux df is POSIX complaint cdsAvailable=`df -P --block-size="$DISK_BLOCK_SIZE" "$2" | awk ' NR == 2 { print $A }' A="$FREE_BLOCKS_COLUMN" 2>/dev/null` else df -P "$2" 2>/dev/null 1>&2 # If POSIX complaint if [ $? -eq 0 ] ; then cdsAvailable=`df -P "$2" | awk ' NR == 2 { print $A }' A="$FREE_BLOCKS_COLUMN" 2>/dev/null` # Is Solaris xpg4 available elif [ -x /usr/xpg4/bin/df ] ; then cdsAvailable=`/usr/xpg4/bin/df -P "$2" | awk ' NR == 2 { print $A }' A="$FREE_BLOCKS_COLUMN" 2>/dev/null` else # if it comes this far, guess the column 4 of df as free-available blocks. This may be incorrect. cdsAvailable=`df "$2" | awk '{ print $A }' A="$FREE_BLOCKS_COLUMN" 2>/dev/null` fi fi fi if [ `isNumeric $cdsAvailable` -ne 0 ] ; then dbg "Disk space check error. free disk [ of 512 bytes ] blocks cannot be found or incorrectly reported by df command on disk parition containing the directory $2." dbg "Please specify free disk [ of 512 bytes ] blocks on the disk partition containing the directory $2 by setting the environment variable FREE_DISK_BLOCKS" dbg "and run the installer again." [ $VeryVerbose ] && dbg "available 512 blocks in the partition containing the directory $2 = $cdsAvailable" return else dbg "$cdsAvailable $DISK_BLOCK_SIZE bytes disk blocks available on the partition $2" fi if [ $cdsAvailable -gt $cdsBlocksRequired ] ; then dbg "Disk space check on the parition $2 succeeded." disk_space_check=0 else if [ `expandDiskPartition $2 $cdsBlocksRequired $cdsAvailable` -ne 0 ] ; then dbg "$2 partition expanded successfully." disk_space_check=0 else dbg "Insufficient disk space in the disk parition containing the directory $2. $cdsBlocksRequired 512 bytes file blocks required. $cdsAvailable 512 bytes file blocks only is available." dbg "Free up the parition or specify a different parition to write temporary files using the command line switch -tempdirif [ -f "$`date +%F`/javaargs" ] ; then awk 'L[$0]++ == 0' "$`date +%F`/javaargs" >> "$`date +%F`/javaargs.nodups" ; rm -f "$`date +%F`/javaargs" aggregateJavaArgs "$1" "$`date +%F`/javaargs.nodups" # [ "$DBG" -ne 1 ] && rm -f "$`date +%F`/javaargs.nodups" else dbg "Warning: internal error parsing Java arguments. Launcher command may be missing Java Arguments." fi GNU_JVM_FILE="$1" GNU_JVM_HOME="$JVM_HOME" GNU_LAUNCHER_FILE="$INSTALLER_PATH" GNU_TEMP_DIR="$`date +%F`_HOME" if [ -n "$APP_ORIG_HOME" ] ; then MEDIA_DIR="$APP_ORIG_HOME" else MEDIA_DIR=`dirname "$INSTALLER_PATH"` fi [ -z "$LOG" ] && LOG=/dev/null APP_STDERR=">$`date +%F`/APP_STDERR" # make sure APP_STDERR is always assigned. [ \( -z "$SILENT" -a -n "$CONSOLE_ON" \) ] && APP_STDERR="&1" # do re-direction if necessary. if [ "$uimode" -eq 0 ] ; then APP_STDOUT="&1" else APP_STDOUT=">$LOG" # make sure APP_STDOUT is always assigned. [ \( -z "$SILENT" -a -n "$CONSOLE_ON" \) ] && APP_STDOUT="&1" # do re-direction if necessary. fi resolve=0 else dbg "resolved jvm file cannot be found. Failed to launch the application." fi } installBundledJRE() { [ $VeryVerbose ] && dbg "installing bundled JRE..." installJVMc=0 while [ $installJVMc -lt $FILEINDEXCOUNT ] ; do FI_KEY=`awk 'END{ s=sprintf("$FILEINDEX%s", I); print s }' I=$installJVMc ." dbg "Temporary files will be cleanedup after the installation." fi fi } executeLauncher() { [ $VeryVerbose ] && dbg "running inner launcher". [ $VeryVerbose ] && dbg "original command line args $@" [ "$FILEINDEXCOUNT" -ne 1 ] && { dbg "Error extracting inner launcher. Failed to launch the application." return } TYPE=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[1]; }' a=$FILEINDEX0 /dev/null` TYPE=`convert $TYPE` if [ "$TYPE" -eq $BIN_FILE_TYPE ] ; then SIZE=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[3] }' a=$FILEINDEX0 /dev/null` OFFSET=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[4] }' a=$FILEINDEX0 /dev/null` NAME=`awk 'END{ split(a,FIELDS, ":"); print FIELDS[5] }' a=$FILEINDEX0 /dev/null` SIZE=`convert $SIZE` OFFSET=`convert $OFFSET` NAME="$`date +%F`/$NAME.embedded" extractAFile fi INNER_LAUNCHER="$NAME" if [ -f "$INNER_LAUNCHER" ] ; then archiveSize=`wc -c "$INNER_LAUNCHER" | awk '{ if ( $1 ~ /^[0-9]/ ) print $1 ; else print 0; }'` if [ $archiveSize -ne $SIZE ] ; then archiveSize=`ls -l "$INNER_LAUNCHER" | awk '{ if ( $5 ~ /^[0-9]/ ) print $5 ; else print 0; }'` if [ $archiveSize -ne $SIZE ] ; then dbg "Error extracting inner launcher. Archive may be corrupt. Failed to launch the application." return fi fi else dbg "Inner launcher cannot be found. Failed to launch the application." return fi MEDIA_LOCATION=`dirname $INSTALLER_PATH` runInnerLauncher=`awk 'END{ s=sprintf("%s -orig %s %s", c, b, a); print s; }' a="$@" b="$MEDIA_LOCATION" c="$INNER_LAUNCHER" /dev/null` chmod 744 "$INNER_LAUNCHER" dbg "running inner launcher=$runInnerLauncher" eval "$runInnerLauncher" exit 0 } tempLocationErrMesg() { cat << END Temporary directory, $1 does not exist and cannot be created. The current user may not have the necessary permission to write to the directory. Please specify another temporary directory with the option -tempdir. Use the -help option for more information. END } help() { cat << STOP Usage : `basename $0` [OPTIONS] [APPLICATION_ARGUMENTS] Where OPTIONS include: -javahomeJRE home which points to directory containing bin/java. -tempdir /dev/null` if [ "$mode" -ge 1 ] ; then main "$@" fi } _XPG=1 # to maintain backward compatibility with bourne shell on IRIX. See IRIX man pages of sh for more details. BIN_SH=xpg4 # for True64 to use POSIX compliant shell. mode "$@"Temporary directory to be used by the launcher. -cp:a Append to the launcher's classpath. -cp:p Prepend to the launcher's classpath. -log Log debug messages to . -extract Extracts the contents of the archive. -nospacecheck Turns off the launcher disk space checking. -version Returns launcher version and exits. -help Prints this help message and exits STOP } VerifyResolvedJVM() { dbg "Verifying resolved JVM" makeJVMFit extractJVMFiles verifedJVMFile=`cat "$`date +%F`/jvmlist" | xargs awk '/^JVM_HOME:.+/{ print FILENAME; exit }' 2>/dev/null` #Verify the resolved JVM file if [ -f "$verifedJVMFile" ] ; then JVM_HOME=`awk 'BEGIN { FS=":" } $1 == tag { i=index($0,":"); s=substr($0,i+1); print s; exit; }' tag=JVM_HOME "$verifedJVMFile" 2>/dev/null` JVM_HOME=`echo "$JVM_HOME" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//'` [ ! -d "$JVM_HOME" ] && { dbg "JVM_HOME is not found in the jvm file $verifedJVMFile." return } JVM_EXE=`awk 'BEGIN { FS=":" } $1 == tag { i=index($0,":"); s=substr($0,i+1); print s; exit; }' tag=JVM_EXE "$verifedJVMFile" 2>/dev/null` JVM_EXE=`echo "$JVM_EXE" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//;s/\"//g'` [ -z "$JVM_EXE" ] && { dbg "Javaexe is not found or empty in the jvm file $verifedJVMFile." return } VerifyJVM "$verifedJVMFile" "$JVM_HOME/$JVM_EXE" if [ $verify -eq 0 ] ; then RESOLVED_JVM="$verifedJVMFile" resolvedJVMVerified=0 dbg "Verification passed for $JVM_HOME/$JVM_EXE using the JVM file $verifedJVMFile." else dbg "Verification failed for $JVM_HOME/$JVM_EXE using the JVM file $verifedJVMFile." fi else dbg "resolved jvm file cannot be found. Try to launch the application by searching a JVM..." fi } executeExternalInstructions() { if [ -f "$1" ] ; then SILENT=true initialize LOG=`awk '/^LOG/ { i=index($0,"="); s=substr($0,i+1); print s; exit }' "$1" 2>/dev/null` [ -n "$LOG" ] && { touch "$`date +%F`/$LOG" if [ -f "$`date +%F`/$LOG" ] ; then LOG="$`date +%F`/$LOG" DBG=1 else LOG= fi } action=`awk '/^ACTION/ { i=index($0,"="); s=substr($0,i+1); print s; exit }' "$1" 2>/dev/null` if [ -n "$action" ] ; then if [ "$action" = "SEARCHJVM" ] ; then dbg "searching JVM" awk '/^JVMFILE[0-9]+/ { i=index($0,"="); s=substr($0,i+1); print s >> f; }' f="$`date +%F`/jvmlist" "$1" 2>/dev/null if [ -f "$`date +%F`/jvmlist" ] ; then jvmFileslc=`wc -l "$`date +%F`/jvmlist" | awk '{ print $1 }' 2>/dev/null` if [ "$jvmFileslc" -gt 0 ] ; then VERIFY_JAR=`awk '/^VERIFY_JAR/ { i=index($0,"="); s=substr($0,i+1); print s ; }' "$1" 2>/dev/null` if [ -f "$VERIFY_JAR" ] ; then cp "$VERIFY_JAR" "$`date +%F`/." if [ -f "$`date +%F`/Verify.jar" ] ; then jvmFilescc=1 while [ "$jvmFilescc" -le "$jvmFileslc" ] ; do JVM_FILE=`sed -n -e "${jvmFilescc}p" "$`date +%F`/jvmlist" 2>/dev/null` if [ -f "$JVM_FILE" ] ; then sed "s/ //;s/^[ ]*//;s/[ ]*$//" "$JVM_FILE" >> "$JVM_FILE.sed" 2>/dev/null rm -f "$JVM_FILE" mv "$JVM_FILE.sed" "$JVM_FILE" fi jvmFilescc=`expr "$jvmFilescc" + 1` done checkEnvironment if [ $sv -eq 0 ] ; then dbg "jvm found using an environment variable and verfication passed for $JVM_FILE." JVM_HOME=`awk '/^JVM_HOME/ { i=index($0,":"); s=substr($0,i+1); print s ; }' "$RESOLVED_JVM" 2>/dev/null` echo 1 echo "$JVM_HOME" echo "$RESOLVED_JVM" else jvmFilescc=1 while [ "$jvmFilescc" -le "$jvmFileslc" ] ; do JVM_FILE=`sed -n -e "${jvmFilescc}p" "$`date +%F`/jvmlist" 2>/dev/null` if [ -f "$JVM_FILE" ] ; then searchAndVerify "$JVM_FILE" if [ "$sv" -eq 0 ] ; then dbg "jvm found and verfication passed for $JVM_FILE." JVM_HOME=`awk '/^JVM_HOME/ { i=index($0,":"); s=substr($0,i+1); print s ; }' "$RESOLVED_JVM" 2>/dev/null` echo 1 echo "$JVM_HOME" echo "$RESOLVED_JVM" break fi fi jvmFilescc=`expr "$jvmFilescc" + 1` done fi else dbg "Error copying Verify.jar . JVM Verification can't be performed." fi else dbg "Verify class is missing . JVM Verification can't be performed." fi else dbg "JVM files are not specified. JVM search can't be performed." fi else dbg "JVM file list is missing. JVM search can't be performed." fi elif [ "$action" = "INSTALL_JVM" ] ; then dbg "Installing JVM" BUNDLED_JRE=`awk '/^BUNDLED_JRE/ { i=index($0,"="); s=substr($0,i+1); print s; exit }' "$1" 2>/dev/null` if [ -f "$BUNDLED_JRE" ] ; then dbg "Bundled JRE file is = $BUNDLED_JRE" DESTINATION_DIR=`awk '/^DESTINATION_DIR/ { i=index($0,"="); s=substr($0,i+1); print s; exit }' "$1" 2>/dev/null` if [ -n "$DESTINATION_DIR" ] ; then dbg "Destination directory is = $DESTINATION_DIR" touch "$DESTINATION_DIR/iswritable" 2>/dev/null 1>&2 if [ \( $? -eq 0 \) -a \( -f "$DESTINATION_DIR/iswritable" \) ] ; then dbg "Beginning to install bundled JRE." rm -f "$DESTINATION_DIR/iswritable" whereAmI=`pwd` mkdir "$DESTINATION_DIR" >/dev/null 2>&1 checkDiskSpace "$BUNDLED_JRE" "$DESTINATION_DIR" if [ "$disk_space_check" -eq 0 ] ; then cd "$DESTINATION_DIR" dbg "installing bundled JRE..." "$BUNDLED_JRE" -qq >/dev/null 2>&1 if [ $? -ne 0 ] ; then cd "$whereAmI" dbg "Error installing bundled JRE. Failed to launch the application." else cd "$whereAmI" dbg "Installing bundled JRE successful." fi chmod -R 744 "$DESTINATION_DIR" > /dev/null 2>&1 J="$DESTINATION_DIR" J=`echo "$J" | sed 's/^[ ]*//;s/[ ]*$//;s/^[ ]*//;s/[ ]*$//'` echo "JVM_HOME:$J" >> "$DESTINATION_DIR/jvm" if [ -f "$DESTINATION_DIR/jvm" ] ; then echo "$DESTINATION_DIR/jvm" else dbg "Installation of bundled JRE failed." fi else dbg "diskspace check failed.Installation of bundled JRE failed." fi else dbg "Install Destination directory for bundled JRE is non-writable. Installation of bundled JRE failed." fi else dbg "Install Destination directory for bundled JRE is missing. Installation of bundled JRE failed. " fi else dbg "Bundled JRE file $BUNDLED_JRE is missing. Installation of bundled JRE failed." fi else dbg "unknown ACTION TAG" fi else dbg "ACTION TAG is missing in the input instructions file. JVM search can't be performed." fi cleanupandexit 0 else dbg "Input instructions file missing. JVM Service operation failed." fi } handleApplicationExitStatus() { [ "$applicationExitStatus" ] && [ \( -z "$SILENT" -a "$applicationExitStatus" -ne 0 \) ] && { pbl [ "$VeryVerbose" ] && applicationExitStatusMesg="The application is aborted with exit code $applicationExitStatus." cat << handleApplicationExitStatusSTOP $applicationExitStatusMesg handleApplicationExitStatusSTOP [ -f "$`date +%F`/APP_STDERR" ] && cat "$`date +%F`/APP_STDERR" } } main() { sh_args="$@" VERSION=1.0.0.20028 DBG=0 while [ $# -gt 0 ] ; do case "$1" in --) shift; break;; -javahome) JAVA_HOME="$2"; shift;; -log) DBG=1;LOG="$2"; shift;; -tempdir) `date +%F`_HOME="$2"; shift;; -silent) SILENT=true; app_args="-silent"; shift;; -orig) APP_ORIG_HOME="$2"; shift;; -nospacecheck) disk_space_check_off=1; shift;; -freediskblocks) FREE_DISK_BLOCKS="$2"; shift;; -javaconsole) CONSOLE_ON=true;; -cp:p) CP_P="$2"; shift;; -cp:a) CP_A="$2"; shift;; -extract) extractAll; exit;; -in) inputFile=`echo "$2" | sed -e 's/^\"//;s/\"$//'`; executeExternalInstructions "$inputFile"; exit;; -help) help; exit;; -version) echo $VERSION; exit;; *) app_args=`awk 'END{ s=sprintf("%s \"%s\"",A,B); print s;}' A="$app_args" B="$1"
Subscribe to:
Comments (Atom)