• Source
    1. #!/bin/bash
    2.  
    3. # Created by Naresh Mehta (https://www.naresh.se/)
    4. #
    5. # This is a script which launches multiple liso devices based on the information
    6. # given in the file lisoSimSetup.csv. There are option parameters that can be passed
    7. # to the script to launch only a specific set of devices from specific rows
    8.  
    9. csvFile="lisoSimSetup.csv"
    10. startRow=1
    11. stopRow=
    12. count=0
    13. startForking=0
    14. generatedPath=
    15. firstExecute=0
    16. resetDevices=0
    17.  
    18. function help {
    19. echo "Helper script to launch Liso Device Simulators"
    20. echo ""
    21. echo "Usage:"
    22. echo " $0 [-f <file>] [-s startRow] [-q stopRow] [-r]"
    23. exit 1
    24. }
    25.  
    26. function createWorkingDirectory {
    27. generatedPath=$workingDir"/"$room_name
    28.  
    29. if [[ ( "$resetDevices" -eq 1 ) ]]
    30. then
    31. rm -rf $generatedPath
    32. fi
    33.  
    34. mkdir -p $generatedPath
    35. }
    36.  
    37. function createFSStructure {
    38. pushd .
    39. cd $generatedPath
    40. cat > settings.json << EOF
    41. {
    42.   "public": {
    43.   "role": "DEVICE",
    44.   "runMode": "DEVICE",
    45.   "applicationPort": $port,
    46.   "applicationVersion": "v1.31"
    47.   },
    48.   "platform": "linux",
    49.   "macAddress": "$macAddress",
    50.   "evokoHomeIpAddress": "$eh_ipaddr_port",
    51.   "simulation": true,
    52.   "lisoIpAddress": "127.0.0.1:$port",
    53.   "activeInterface": "ethernet",
    54.   "workingDirectory": "$generatedPath"
    55. }
    56. EOF
    57.  
    58. mkdir -p liso_files
    59. cd liso_files
    60.  
    61. cat > configuration.conf << EOF
    62. {"room_id":"$room_id","ip_address_number":"$eh_ipaddr_port","room_name":"$room_name"}
    63. EOF
    64. popd
    65. }
    66.  
    67. function launchProcesses {
    68. (( count = count + 1 ))
    69. if [[ ( "$count" -eq "$startRow" ) ]]
    70. then
    71. (( startForking = 1))
    72. fi
    73. if [[ ( "$startForking" -eq 1 ) ]]
    74. then
    75. createWorkingDirectory $workingDir $room_name
    76. createFSStructure $generatedPath $port $macAddress $room_name $room_id $eh_ipaddr_port
    77.  
    78. # Now that everything is setup, we will simply launch the processes one at a time
    79. PWD=`pwd`
    80. pushd .
    81. cd ..
    82.  
    83. if [[ ( "$firstExecute" -eq 0 ) ]]
    84. then
    85. if [[ ( "$resetDevices" -eq 1 ) ]]
    86. then
    87. meteor reset
    88. fi
    89. gnome-terminal -x meteor --settings $generatedPath/settings.json --port $port &
    90. (( firstExecute = 1 ))
    91. sleep 2m
    92. else
    93. export MONGO_URL=$mondoDBURL
    94. gnome-terminal -x meteor --settings $generatedPath/settings.json --port $port &
    95. sleep 40s
    96. fi
    97. popd
    98. # (
    99. # cd ..
    100. # meteor --settings $generatedPath/settings.json --port $port
    101. # )
    102. fi
    103. if [[ ( "$count" -eq "$stopRow" ) ]]
    104. then
    105. (( startForking = 0))
    106. fi
    107. }
    108.  
    109. while getopts ":f:s:q:r" o; do
    110. case "${o}" in
    111. f)
    112. csvFile=${OPTARG}
    113. ;;
    114. s)
    115. startRow=${OPTARG}
    116. ;;
    117. q)
    118. stopRow=${OPTARG}
    119. ;;
    120. r)
    121. resetDevices=1
    122. ;;
    123. *)
    124. help
    125. ;;
    126. esac
    127. done
    128. shift $((OPTIND-1))
    129.  
    130. IFS=,
    131. [ ! -f $csvFile ] && { echo "$csvFile file not found"; exit 1; }
    132. while read port macAddress room_id room_name eh_ipaddr_port workingDir mondoDBURL
    133. do
    134. if [[ ! ( "$port" =~ ^\# ) && ! ( -z "$port" ) ]]
    135. then
    136. launchProcesses $port $macAddress $room_id $room_name $eh_ipaddr_port $workingDir $startRow $stopRow $mondoDBURL
    137. fi
    138. done < $csvFile