convert.sh 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. if [ -n "$1" ] && [ -e $1 ]; then
  3. file=$1
  4. else
  5. echo " ** Input File : $1 does not exist"
  6. echo " ** Please specify the correct dependencies file"
  7. echo " ** Usage : bash <path-to-script> <path-to-dependencies-file> [<path-to-local-manifest>]"
  8. exit 1
  9. fi
  10. if [ -n "$2" ]; then
  11. manifest_path="$2"
  12. elif [ -e .repo ]; then
  13. mkdir -p .repo/local_manifests
  14. manifest_path=".repo/local_manifests/roomservice.xml"
  15. else
  16. echo " ** Manifest file to create not specified."
  17. echo " ** And .repo folder does not exist in $PWD"
  18. echo " ** Either run the script from root of your source or specify a custom path+filename"
  19. echo " ** Usage : bash <path-to-script> <path-to-dependencies-file> [<path-to-local-manifest>]"
  20. exit 1
  21. fi
  22. if [ -e $manifest_path ]; then
  23. sed -i 's@</manifest>@@g' $manifest_path
  24. else
  25. echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > $manifest_path
  26. echo "<manifest>" >> $manifest_path
  27. fi
  28. vars=( "remote" "repository" "target_path" "branch" "revision")
  29. for i in ${!vars[@]} ; do
  30. value=$(grep "${vars[$i]}" "$file" | cut -d '"' -f4)
  31. if [ "$value" != "" ]; then
  32. declare -a ${vars[$i]}"_val"="( $value )"
  33. fi
  34. done
  35. for i in {0..5}; do
  36. if [ "${repository_val[$i]}" != "" ] && [ "${target_path_val[$i]}" != "" ]; then
  37. target_path="path=\"${target_path_val[$i]}\""
  38. repository=" name=\"${repository_val[$i]}\""
  39. if [ "${remote_val[$i]}" != "" ]; then
  40. remote_for_repo=" remote=\"${remote_val[$i]}\""
  41. fi
  42. if [ "${branch_val[$i]}" != "" ]; then
  43. revision=" revision=\"${branch_val[$i]}\""
  44. elif [ "${revision_val[$i]}" != "" ]; then
  45. revision=" revision=\"${revision_val[$i]}\""
  46. fi
  47. echo " <project $target_path$repository$remote_for_repo$revision />" >> $manifest_path
  48. fi
  49. done
  50. echo "</manifest>" >> $manifest_path