Blame view

scripts/setup_submodules 2.45 KB
b5d9e433   Peter M. Groen   Fixed License Hea...
1
  #!/bin/bash 
59367614   Peter M. Groen   Install script..
2
3
4
5
6
  # =================
  # = Do not chenge.
  # =================
  GIT_URL_SUBS="http://gitlab.osdev.nl/open_source"
  TOP_REPO="-1"
b5d9e433   Peter M. Groen   Fixed License Hea...
7
8
9
10
11
12
13
14
15
  
  function print_usage_exit() {
      echo "Usage $0 -i|--install|-u|--update"
      echo "	-i or --install  Install the submodules mentioned in the submodules.list" 
      echo "	-u or --update   Update the submodules mentioned in the submodules.list"
      echo " "
      exit 1
  }
  
59367614   Peter M. Groen   Install script..
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  function check_top_or_sub() {
      # This function checks if we're the top-repository.
      # In that case we need the submodules.. If we're already a submodule, 
      # we simply exit this script with a message
      if [ -d ./.git ]; then
          return 1
      elif [ -d ../.git ]; then
          if [ -f ../.submodules ]; then
              echo "Seems like we're already a submodule. Nothing to do here."
              return 0
          fi
      fi
      return 0
  }
  
  function check_working_dir() {
      # Check if we're in the top-level directory of our repository.
      if [ -f ./scripts/submodules.list ]; then
          # We're good to go
          return 1
      fi
      return 0
  }
  
b5d9e433   Peter M. Groen   Fixed License Hea...
40
  function read_submodules() {
59367614   Peter M. Groen   Install script..
41
42
      if [ -e ./scripts/submodules.list ]; then
          source ./scripts/submodules.list
b5d9e433   Peter M. Groen   Fixed License Hea...
43
44
45
46
47
48
      fi
  }
  
  function add_submodules() {
      for SUB_MODULE in ${SUB_MODULES}
      do
59367614   Peter M. Groen   Install script..
49
50
          git submodule add -f ${GIT_URL_SUBS}/${SUB_MODULE} ${SUB_MODULE}
          git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS}/${SUB_MODULE}
b5d9e433   Peter M. Groen   Fixed License Hea...
51
52
53
54
55
56
57
58
59
60
61
62
63
64
      done
  }
  
  function get_submodules() {
      git submodule update --init --recursive
  }
  
  function update_submodules() {
      git submodule update --recursive
  }
  
  # =============================================================================
  # ==        T H E   M A I N   E N T R Y   O F   T H I S   S C R I P T        ==
  # =============================================================================
59367614   Peter M. Groen   Install script..
65
66
67
68
69
70
71
72
73
74
75
76
  RESULT=check_top_or_sub()
  if [ $RESULT -eq 0 ]; then
      echo "Seems like we're a submodule already or not part of a repository."
      exit 0
  fi
  
  RESULT=check_working_dir()
  if [ $RESULT -eq 0 ]; then
      echo "Go to the top of this repository and type : scripts/setup_submodules [-i|--install]"
      exit 0
  fi
  
b5d9e433   Peter M. Groen   Fixed License Hea...
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
  read_submodules
  
  case "$1" in
      -i*|--install*)
          echo "Installing submodules for this repository ( ${PWD} )"
          add_submodules
          get_submodules
          ;;
      -u*|--update*)
          echo "Update submodules : ${SUB_MODULES}"
          update_submodules
          ;;
      *)
          echo "No parameters found..."
          print_usage_exit
          ;;
  esac