.bash_profile 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # ============================== DATAD / DATADD ==============================
  2. # [DATAD] Quick source shortcuts for NetScaler data scripts | Usage: datad / datadd / ddd | Example: datad
  3. alias ddd="source /home/CITRITE/manjeshn/manscript/datad.sh"
  4. alias datad="source /home/CITRITE/manjeshn/manscript/datad.sh"
  5. alias datadd="source /home/CITRITE/manjeshn/manscript/datadd.sh"
  6. # ============================== CONFETCH TOOLING =============================
  7. # [CONFETCH] Wrapper + viewers for config fetch tooling | Usage: conFetch / show / showd | Example: conFetch <args>
  8. alias show="python /home/CITRITE/manjeshn/manscript/show.py"
  9. alias showd="python /home/CITRITE/manjeshn/manscript/showd.py"
  10. alias conFetch="python /home/CITRITE/manjeshn/manscript/conFetch_Wrapper.py"
  11. # ============================== BIGCAP ==============================
  12. # [BIGCAP] Run bigcap helper script (packet/capture helper) | Usage: bigcap <args> | Example: bigcap -h
  13. alias bigcap="python /home/CITRITE/manjeshn/manscript/bigcap.py"
  14. # ============================== DISPOSABLE TOYS (dT) ==============================
  15. # [DT] Run disposableToys dt utility | Usage: dt <args> | Example: dt --help
  16. alias dt="python /home/CITRITE/manjeshn/manscript/disposableToys/Project_dT/dt.py"
  17. # ============================== PARV TSHOOT STYLE ==============================
  18. # [LS OVERRIDE] List files in long + reverse + all + human readable | Usage: ls <path> | Example: ls /var/log
  19. alias ls="ls -lrha"
  20. # ============================== ALLNEWNSLOG ==============================
  21. # [ALLNEWNSLOG] Iterate collector*/var/nslog/newnslog* and run nsconmsg | Usage: allnewnslog <duration> | Example: allnewnslog 300
  22. alias allnewnslog='function _allnewnslog() { base_dir="$(pwd | sed '\''s|\(.*collector[^/]*\)/.*|\1|'\'')"; find "$base_dir/var/nslog/" -maxdepth 1 -type d -name "newnslog*" -print0 | while IFS= read -r -d "" i; do echo -e "\033[1;33m------------------------ $i ------------------------\033[0m"; nsconmsg -K "$i" -d "$1" -s disptime=1; done; }; _allnewnslog'
  23. # ============================== DIRECTORY SHORTCUTS ==============================
  24. # [CD SHORTCUTS] Faster directory traversal | Usage: .. / ... / .2 etc | Example: ... (go up 2 levels)
  25. alias ..="cd .."
  26. alias ...="cd ../../"
  27. alias ....="cd ../../../"
  28. alias .....="cd ../../.././"
  29. alias .1="cd .."
  30. alias .2="cd ../../"
  31. alias .3="cd ../../../"
  32. alias .4="cd ../../../../"
  33. # ============================== HISTORY / CLEAR ==============================
  34. # [HISTORY] Quick shell history shortcuts | Usage: h / gh <pattern> | Example: gh nslog
  35. alias h='history'
  36. alias gh="history | grep "
  37. alias c="clear"
  38. # ============================== COLORIZED GREP / LESS ==============================
  39. # [GREP COLOR] Case-insensitive grep with persistent color | Usage: zzgrep <pattern> <file> | Example: zzgrep error ns.log
  40. alias zzgrep='grep -i --color=always'
  41. # [LESS COLOR] View ANSI-colored output safely in less | Usage: <cmd> | zzless | Example: cat out.txt | zzless
  42. alias zzless='less -R'
  43. # ============================== CSV COLUMN COUNTER ==============================
  44. # [COUNTCOL] Print column index and first row values from CSV | Usage: countcol < file.csv | Example: head -1 a.csv | countcol
  45. alias countcol="awk -F, '{for(i=1;i<=NF;i++) { print i, \$i } exit}'"
  46. # ============================== FASTFIND FUNCTION ==============================
  47. # [FASTFIND] Case-insensitive filename search under current dir | Usage: fastfind <token> | Example: fastfind nslog
  48. fastfind () {
  49. find . -iname "*$1*" 2>/dev/null
  50. }
  51. # =============== APPENDED SECTION: PCAP SSLKEYS INJECTOR ===============
  52. # [PCAP TLS INJECTOR] Inject TLS secrets into captures using editcap | Usage: pcap-inject <ssl_keys> <pcap> [out.pcapng] | Example: pcap-inject sslkeys.log in.pcap out.pcapng
  53. # [PCAP-SSL] Convenience alias for editcap TLS secret injection mode | Usage: pcap-ssl ... | Example: pcap-ssl "tls,sslkeys.log" in.pcap out.pcapng
  54. alias pcap-ssl='editcap --inject-secrets tls'
  55. # [PCAP-INJECT] Safe wrapper: validates inputs + prevents overwrite + creates .pcapng | Usage: pcap-inject <ssl_keys_file> <input_pcap> [output_pcapng] | Example: pcap-inject keys.log trace.pcap
  56. pcap-inject() {
  57. if [ $# -ne 2 ] && [ $# -ne 3 ]; then
  58. echo "Usage: pcap-inject <ssl_keys_file> <input_pcap> [output_pcapng]"
  59. echo "If output_pcapng is omitted, uses input name with .pcapng extension"
  60. return 1
  61. fi
  62. local ssl_keys="$1"
  63. local input_pcap="$2"
  64. local output_pcapng="${3:-}"
  65. # [VALIDATION] Ensure SSL keys + PCAP exist before running editcap | Usage: automatic | Example: missing file => error
  66. if [ ! -f "$ssl_keys" ]; then
  67. echo -e "\033[31m? ERROR: SSL keys file not found: $ssl_keys\033[0m"
  68. return 1
  69. fi
  70. if [ ! -f "$input_pcap" ]; then
  71. echo -e "\033[31m? ERROR: Input PCAP not found: $input_pcap\033[0m"
  72. return 1
  73. fi
  74. # [OUTPUT NAME] Default output is input basename + .pcapng | Usage: omit 3rd arg | Example: foo.pcap => foo.pcapng
  75. if [ -z "$output_pcapng" ]; then
  76. if [[ "$input_pcap" == *.* ]]; then
  77. output_pcapng="${input_pcap%.*}.pcapng"
  78. else
  79. output_pcapng="${input_pcap}.pcapng"
  80. fi
  81. fi
  82. # [OVERWRITE GUARD] Prompt if output exists to avoid clobbering | Usage: automatic | Example: choose 'n' to abort
  83. if [ -f "$output_pcapng" ]; then
  84. read -rp "$(echo -e "\033[33m?? Output file '$output_pcapng' exists. Overwrite? (y/n) \033[0m")" confirm
  85. if [[ ! "$confirm" =~ [yY] ]]; then
  86. echo -e "\033[33mAborted by user\033[0m"
  87. return 1
  88. fi
  89. fi
  90. # [EXECUTION] Inject secrets and write output (pcap/pcapng supported) | Usage: automatic | Example: editcap --inject-secrets "tls,keys.log" in.pcap out.pcapng
  91. editcap --inject-secrets "tls,$ssl_keys" "$input_pcap" "$output_pcapng"
  92. # [RESULT] Print success/failure + basic output metadata | Usage: automatic | Example: shows size on success
  93. if [ $? -eq 0 ]; then
  94. echo -e "\n\033[32m? SUCCESS: Created $output_pcapng\033[0m"
  95. echo " Input PCAP: $input_pcap"
  96. echo " SSL Keys: $ssl_keys"
  97. echo " Output Size: $(du -h "$output_pcapng" 2>/dev/null | awk '{print $1}')"
  98. else
  99. echo -e "\n\033[31m? FAILED: editcap returned error status\033[0m"
  100. echo " Command: editcap --inject-secrets tls,$ssl_keys $input_pcap $output_pcapng"
  101. return 1
  102. fi
  103. }
  104. # ============================== PCAP-INJECT AUTO-COMPLETION ==============================
  105. # [AUTOCOMPLETE] Tab-complete keys/pcap/output args for pcap-inject | Usage: type 'pcap-inject <TAB>' | Example: pcap-inject ssl<TAB>
  106. _pcap-inject-completion() {
  107. local cur prev
  108. COMPREPLY=()
  109. cur="${COMP_WORDS[COMP_CWORD]}"
  110. prev="${COMP_WORDS[COMP_CWORD-1]}"
  111. case $COMP_CWORD in
  112. 1) # [COMPLETE ARG1] SSL keys file completion | Matches: *.sslkeys/*.keys/*.log | Example: keys<TAB>
  113. COMPREPLY=( $(compgen -f -X '!*@(sslkeys|keys|log)' -- "$cur") )
  114. ;;
  115. 2) # [COMPLETE ARG2] Input capture completion | Matches: *.pcap/*.cap/*.pcapng/*.trace | Example: in.p<TAB>
  116. COMPREPLY=( $(compgen -f -X '!*@(pcap|cap|pcapng|trace)' -- "$cur") )
  117. ;;
  118. 3) # [COMPLETE ARG3] Output file completion | Any filename | Example: out.pcapng<TAB>
  119. COMPREPLY=( $(compgen -f -- "$cur") )
  120. ;;
  121. esac
  122. }
  123. # [SHELL OPT] Enable extended glob needed for the completion filters | Usage: automatic | Example: older shells ignore safely
  124. shopt -s extglob 2>/dev/null
  125. # [REGISTER] Bind completion function to pcap-inject | Usage: automatic | Example: completion works in bash
  126. complete -F _pcap-inject-completion pcap-inject 2>/dev/null
  127. # [LOAD BANNER] Friendly message showing injector loaded | Usage: automatic on shell load | Example: appears on new terminal
  128. echo -e "\033[36m>> PCAP TLS Injector loaded. Use 'pcap-inject' <<\033[0m"
  129. # ============================== AUTO-UPDATE BASH_PROFILE ==============================
  130. # [AUTO-UPDATE] Pull the latest .bash_profile from git | Usage: automatic on shell load
  131. _auto_update_profile() {
  132. # [LOCAL TESTING GUARD] Bypass update if DISABLE_PROFILE_UPDATE=1
  133. if [ "$DISABLE_PROFILE_UPDATE" = "1" ]; then
  134. echo -e "\033[1;33m>> Auto-update skipped (DISABLE_PROFILE_UPDATE=1) <<\033[0m"
  135. return 0
  136. fi
  137. local remote_url="https://git.4parv.in/parv.ashwani/.bash_profile/raw/main/.bash_profile"
  138. local local_file="$HOME/.bash_profile"
  139. local tmp_file="/tmp/.bash_profile_new"
  140. # [GUARD] Prevent infinite loops if the new profile sources itself
  141. if [ "$_PROFILE_UPDATE_RUN" = "1" ]; then
  142. return 0
  143. fi
  144. export _PROFILE_UPDATE_RUN="1"
  145. # [FETCH] Download quietly with a 2-second timeout to avoid shell hangs
  146. if curl -sL --connect-timeout 2 -m 2 "$remote_url" -o "$tmp_file" 2>/dev/null; then
  147. # [CHECK] If file has content and differs from the local version
  148. if [ -s "$tmp_file" ] && ! cmp -s "$local_file" "$tmp_file" 2>/dev/null; then
  149. echo -e "\033[1;35m>> New .bash_profile detected on Git! Updating... <<\033[0m"
  150. # Backup current profile and overwrite with new
  151. cp "$local_file" "${local_file}.bak" 2>/dev/null
  152. cp "$tmp_file" "$local_file"
  153. # Clean up temp file before sourcing to keep environment clean
  154. rm -f "$tmp_file" 2>/dev/null
  155. # Apply the newly downloaded profile immediately
  156. source "$local_file"
  157. return 0
  158. fi
  159. fi
  160. # Clean up if no update was needed or curl failed
  161. rm -f "$tmp_file" 2>/dev/null
  162. }
  163. # Run the update check
  164. _auto_update_profile