Mercurial > repos > gga > genenotebook_genenotebook_build
annotate find_free_port.sh @ 1:f415e44e71de draft
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit a04f273adbc0ebb95bf42bf5bad8b41ba7aba91d
author | gga |
---|---|
date | Mon, 03 Apr 2023 15:01:52 +0000 |
parents | 22f22c3e81bf |
children |
rev | line source |
---|---|
0
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
1 #!/bin/bash |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
2 |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
3 set -e |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
4 |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
5 # This script finds a free port on the local machine in the 7000-65000 interval |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
6 # Should work in biocontainers derived from conda |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
7 # Taken from https://unix.stackexchange.com/a/358101 |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
8 |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
9 if command -v ss &> /dev/null |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
10 then |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
11 ss -alnut | awk ' |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
12 $2 == "LISTEN" { |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
13 if ($5 ~ "[.:][0-9]+$") { |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
14 split($5, a, /[:.]/); |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
15 port = a[length(a)]; |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
16 p[port] = 1 |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
17 } |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
18 } |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
19 END { |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
20 for (i = 7000; i < 65000 && p[i]; i++){}; |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
21 if (i == 65000) {exit 1}; |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
22 print i |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
23 } |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
24 ' |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
25 elif command -v netstat &> /dev/null |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
26 then |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
27 netstat -aln | awk ' |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
28 $6 == "LISTEN" { |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
29 if ($4 ~ "[.:][0-9]+$") { |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
30 split($4, a, /[:.]/); |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
31 port = a[length(a)]; |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
32 p[port] = 1 |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
33 } |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
34 } |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
35 END { |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
36 for (i = 7000; i < 65000 && p[i]; i++){}; |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
37 if (i == 65000) {exit 1}; |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
38 print i |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
39 } |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
40 ' |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
41 else |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
42 echo "This tool requires one of 'netstat' of 'ss' commands." |
22f22c3e81bf
planemo upload for repository https://github.com/galaxy-genome-annotation/galaxy-tools/tree/master/tools/genenotebook commit 12282c16658b37858f49944796fd95515ef0fc0b
gga
parents:
diff
changeset
|
43 fi |