3c2128b8ae9c14e86bd39c0b0bbca1a0a85d34d6
[p2p-testing-infrastructure.git] / ControlScripts / clients / swift / start_swift_seeder.sh
1 #!/bin/bash
2 #
3 # 2010 Calin-Andrei Burloiu, calin.burloiu@gmail.com
4 #
5 # Bash script used to start a swift instance
6 # The script
7 #  * changes current working directory to TorrentsAndData
8 #  * starts a swift session
9 #  * at the end deletes the downloaded data
10 #
11 # If you run this script manually, you must run it from the P2P-Testing-Infrastructure/ControlScripts folder
12 #
13
14 # Read the global configuration file
15 # Check if the global configuration file exists
16 if [ ! -e globalconfig ]; then
17         echo "Warning: The global config file globalconfig does not exist."
18 else
19         source globalconfig
20 fi
21
22 # Read the node-specific configuration file (TORRENT_FILE)
23 # Check if the node-specific configuration file exists
24 if [ ! -e ../ClientWorkingFolders/TmpLogs/node_config ]; then
25         echo "Warning: The global config file ../ClientWorkingFolders/TmpLogs/node_config does not exist."
26 else
27         source ../ClientWorkingFolders/TmpLogs/node_config
28 fi
29
30 # convert host_id and veid to veth IP address in 10.0.0.0/8 network
31 host_veid_to_eth_ip()
32 {
33         host_id=$1
34         veid=$2
35         ip_part1=$(($veid / 100))
36         ip_part2=$(($veid % 100))
37         id=$(echo "$host_id" | awk '{printf "%d", $1;}')
38         echo "10.$ip_part1.$id.$ip_part2"
39 }
40
41 # convert p2p-next-${host_id}-${veid} hostname to veth IP address
42 hostname_to_ip()
43 {
44         hostname=$1
45
46         veid=${hostname##*-}
47 tmp=${hostname%-*}
48         host_id=${tmp##*-}
49
50         host_veid_to_eth_ip $host_id $veid
51 }
52
53 OWN_IP=$(hostname_to_ip $(hostname))
54 cd "$WORKING_FOLDER_REL_PATH"/TorrentsAndData
55 DATA_PATH=$(pwd)
56
57 cd $SWIFT_ABS_PATH
58
59 #echo ./swift -f "${DATA_PATH}"/"${TORRENT_FILE}" -l ${OWN_IP}:6881 -p > ~/deb
60 ./swift -f "${DATA_PATH}"/"${TORRENT_FILE}" -l ${OWN_IP}:6881 -p