assemble_blocks.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/bin/bash
  2. blocks_dir=blocks
  3. docker_dir=docker
  4. template_dir=templates
  5. docker_file=Dockerfile
  6. gogs_config_file=conf.tmp
  7. gogs_config=config
  8. gogs_init_file=$docker_dir/init_gogs.sh
  9. fig_file=fig.yml
  10. fig_config=fig
  11. gogs_init_template=$template_dir/init_gogs.sh.tpl
  12. if [ "$#" == 0 ]; then
  13. blocks=`ls $blocks_dir`
  14. if [ -z "$blocks" ]; then
  15. echo "No Blocks available in $blocks_dir"
  16. else
  17. echo "Available Blocks:"
  18. for block in $blocks; do
  19. echo " $block"
  20. done
  21. fi
  22. exit 0
  23. fi
  24. for file in $gogs_config_file $fig_file; do
  25. if [ -e $file ]; then
  26. echo "Deleting $file"
  27. rm $file
  28. fi
  29. done
  30. for dir in $@; do
  31. current_dir=$blocks_dir/$dir
  32. if [ ! -d "$current_dir" ]; then
  33. echo "$current_dir is not a directory"
  34. exit 1
  35. fi
  36. if [ -e $current_dir/$docker_file ]; then
  37. echo "Copying $current_dir/$docker_file to $docker_dir/$docker_file"
  38. cp $current_dir/$docker_file $docker_dir/$docker_file
  39. fi
  40. if [ -e $current_dir/$gogs_config ]; then
  41. echo "Adding $current_dir/$gogs_config to $gogs_config_file"
  42. cat $current_dir/$gogs_config >> $gogs_config_file
  43. echo "" >> $gogs_config_file
  44. fi
  45. if [ -e $current_dir/$fig_config ]; then
  46. echo "Adding $current_dir/$fig_config to $fig_file"
  47. cat $current_dir/fig >> $fig_file
  48. echo "" >> $fig_file
  49. fi
  50. done
  51. echo "Creating $gogs_init_file"
  52. sed "/{{ CONFIG }}/{
  53. r $gogs_config_file
  54. d
  55. }" $gogs_init_template > $gogs_init_file
  56. if [ -e $gogs_config_file ]; then
  57. echo "Removing temporary GoGS config"
  58. rm $gogs_config_file
  59. fi