helper.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. # Function to create a directory
  7. create_directory() {
  8. dir_name="issue-$1"
  9. mkdir -p "$dir_name"
  10. echo "Created directory: $dir_name"
  11. # Unzip files if unzip option is enabled
  12. if [ "$unzip" = true ]; then
  13. if [ -d "$dir_name" ]; then
  14. # /opt/wabt/bin/wasm2wat --enable-all $dir_name/PoC.wasm -o $dir_name/PoC.wast
  15. for zipfile in "$dir_name"/*.zip; do
  16. if [ -f "$zipfile" ]; then
  17. echo "Unzipping $zipfile in $dir_name"
  18. unzip -o "$zipfile" -d "$dir_name"
  19. rm $zipfile
  20. # /opt/wabt/bin/wasm2wat --enable-all PoC.wasm -o PoC.wast
  21. fi
  22. done
  23. fi
  24. fi
  25. }
  26. # Initialize unzip option to false
  27. unzip=false
  28. # Parse options
  29. while getopts ":x" opt; do
  30. case $opt in
  31. x)
  32. unzip=true
  33. ;;
  34. \?)
  35. echo "Invalid option: -$OPTARG" >&2
  36. exit 1
  37. ;;
  38. esac
  39. done
  40. # Remove the parsed options from the arguments
  41. shift $((OPTIND - 1))
  42. # Check if at least one argument is provided
  43. if [ $# -lt 1 ]; then
  44. echo "Usage: $0 [-x] <num1> [num2]"
  45. exit 1
  46. fi
  47. num1=$1
  48. # Changes work directories to issues
  49. cd issues
  50. # If only one argument is provided
  51. if [ $# -eq 1 ]; then
  52. create_directory "$num1"
  53. else
  54. # Extract the second argument
  55. num2=$2
  56. # Check if the second argument is greater than the first
  57. if [ "$num2" -lt "$num1" ]; then
  58. echo "Second number must be greater than or equal to the first number."
  59. exit 1
  60. fi
  61. # Generate directories from num1 to num2
  62. for ((i = num1; i <= num2; i++)); do
  63. create_directory "$i"
  64. done
  65. fi