diff --git a/cmd.sh b/cmd.sh new file mode 100755 index 0000000..d482aca --- /dev/null +++ b/cmd.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo $1 +echo $2 + +echo $3 +echo $4 diff --git a/mark.sh b/mark.sh new file mode 100755 index 0000000..b2795e4 --- /dev/null +++ b/mark.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +scriptName=$(basename $0) +version=0.1 +original="" +sources="" +verbose=0 +tmpFilename='.tmp.compile_commands.json' +srcOriginalPath="../../git/src" + +function print { + verbose=$1 + message=$2 + if [[ $verbose -eq 1 ]]; then + echo "[V] $message" + fi +} + +function usage { + echo " + Usage: $scriptName [OPTIONS] + Options: + [-o|--original] - location of a original compile_commands.json (e.g. -o /tmp/test/compile_commands.json) + [-s|--sources] - location of your sources directory (e.g. /external_chr/src/) + [-g|--gitsrc] - location of an original src directory; default ../../git/src/ (relative to build/Release) + " +} + +function about { + echo " + ${scriptName} ver.${version} + This script's purpose to deal with external sources of a project for which compile commands + are generated. + for usage examples call + ${scriptName} [-h|--help] + " +} + +while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do + case $1 in + -a | --about) + about + exit + ;; + -h | --help) + usage + exit + ;; + -o | --original) + shift + original=$1 + ;; + -s | --sources) + shift + sources=$1 + ;; + -g | --gitsrc) + shift + srcOriginalPath=$1 + ;; + -v | --verbose) + verbose=1 + ;; + esac + shift +done + +print $verbose "original=$original && sources=$sources" + +cp $original $tmpFilename + +buildDirectory=$(grep directory $original | head -n 1 | cut -d ':' -f 2 | cut -d '"' -f 2) + +print $verbose "buildDirectory=$buildDirectory" + +if command -v pv &>/dev/null; then + pv $tmpFilename | sed "s|${srcOriginalPath}|${sources}|g" >${sources}/compile_commands.json +else + echo "pv was not found on PATH so just wait..." + sed "s|${srcOriginalPath}|${sources}|g" $tmpFilename + cp $tmpFilename ${sources}/compile_commands.json +fi + +print $verbose "original compile_commands src path ($srcOriginalPath) was changed to $sources" + +rm $tmpFilename diff --git a/tun.sh b/tun.sh index 6e63028..af74bae 100755 --- a/tun.sh +++ b/tun.sh @@ -3,13 +3,15 @@ scriptName=$(basename $0) version=0.1 idx=0 killFlag=0 +localServiceIp="192.168.105.100" +remoteIp="172.26.123.156" endpoint="192.168.105.100" user="$USER" cacheFile=.tunLast -privateKeyLoc="~/.ssh/id_ecdsa" +privateKeyLoc="~/.ssh/id_ed25519" override=0 debug=0 - +local="R" fromPort=0 toPort=0 @@ -17,13 +19,11 @@ function killTunnel { if [[ debug -eq 1 ]]; then printf "killTunnel %d\n" $toPort fi - pkill -f "ssh -i ${privateKeyLoc} -fNL 0.0.0.0:$toPort:" - iptables -D INPUT -p tcp --dport $toPort -j ACCEPT 2>/dev/null + pkill -f "ssh -i ${privateKeyLoc} -fN${local} $toPort:" } function openTunnel { - ssh -i ${privateKeyLoc} -fNL 0.0.0.0:$toPort:${endpoint}:$fromPort ${user}@localhost - iptables -A INPUT -p tcp --dport $toPort -j ACCEPT 2>/dev/null + ssh -i ${privateKeyLoc} -fN${local} $toPort:${endpoint}:$fromPort ${user}@${remoteIp} } function parsePort { @@ -43,6 +43,7 @@ function usage { -k | --kill Try to kill defined tunnels, if missing will try to create them -p | --port FROM:TO Define new port forwarding rule, if in format FROM:TO - will create tunnel from port FROM on defined endpoint to port TO on local + -u | --user USERNAME Define the user name on behalf of who will try to connect to remote target " } @@ -61,6 +62,14 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in about exit ;; + -u | --user ) + shift; + user=$1 + ;; + -l | --local ) + local="L" + remoteIp="localhost" + ;; -k | --kill ) killFlag=1 ;; @@ -80,6 +89,10 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in esac; shift; done if [[ "$1" == '--' ]]; then shift; fi +if [[ ${debug} -eq 1 ]]; then + about +fi + if [[ ${#port[@]} -gt 0 ]]; then printf "PORT TO OPEN: %s\n" ${port[@]} fi @@ -103,5 +116,5 @@ done printf "%s\\n" "${port[@]}" > ${cacheFile} if [[ ${debug} -eq 1 ]]; then - netstat -lnptu | grep ssh + ps aux | grep "ssh -i ${privateKeyLoc}" | grep -v grep fi