new helpers :D
This commit is contained in:
parent
e7c63c9462
commit
7c48d06fe3
86
mark.sh
Executable file
86
mark.sh
Executable file
@ -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
|
||||
27
tun.sh
27
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user