-
Notifications
You must be signed in to change notification settings - Fork 2
/
run_examples.sh
executable file
·39 lines (34 loc) · 1.53 KB
/
run_examples.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# Exit if any command failed.
set -e
cargo build --examples --all-features
# Cargo builds each example and places it under the examples folder.
# If the example is called `my_example.rs`, the generated executable will be named `my_example`.
# But, the examples folder contains other files that start with `my_example` but contain a random string afterwards.
# So for example if we have:
# examples/example1.rs
# examples/example2.rs
# We will have:
# ./target/debug/examples/example1
# ./target/debug/examples/example1-random-string
# ./target/debug/examples/example1-random-string
# ./target/debug/examples/example2
# ./target/debug/examples/example2-random-string
# ./target/debug/examples/example2-random-string
# We only want to execute the ones that don't have a random string in their name.
# So we filter the executable files in the examples directory using grep to not list
# the files that contain a random string. Luckily, these files all have `-` in their name.
find target/debug/examples/ -regex ".*/[0-9a-zA-Z_]+$" | while read -r example
do
# In order for the generated executable to be able to create a TUN/TAP device,
# and perform other functionalities related to network administration,
# it must have the CAP_NET_ADMIN capability. So we set the CAP_NET_ADMIN in both
# its Effective and Permitted sets, hence the "cap_net_admin=ep".
# For more info read:
# * man capabilities
# * man setcap
# * man cap_from_text
sudo setcap "cap_net_admin=ep" "$example"
echo "Running $(basename -- "$example")..."
$example
done