Blame view

scripts/setup_submodules 5.6 KB
c00d100f   Steven de Ridder   Added submodule s...
1
2
3
4
5
6
  #!/bin/bash
  
  # ===============================================
  # == Setting some environment variables
  # ===============================================
  GIT_URL_SUBS="http://gitlab.osdev.nl/open_source"
09e13681   Steven de Ridder   Adjusted script t...
7
8
9
10
  GIT_URL_SUBS_CLOSED="http://gitlab.osdev.nl/closed_source"
  
  OPEN_REPOS=("mqtt-cpp" "transqueue" "orm" "network" "jobscheduler" "global" "dbconnector" "logutils" "pugixml" "qt-mqtt" "iputils" "crypter" "qt-bluetooth" "versioning" "cmake")
  
c00d100f   Steven de Ridder   Added submodule s...
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
  FUNC_RESULT="-1"
  
  # Name          : print_usage_exit()
  # Description   : Print the way this script is intended to be used and exit.
  # Parameters    : None.
  # Returns       : err_code 1 to the Operating System
  # --------------------------------------------------------------------------------------
  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
  }
  
  # Name          : check_top_or_sub
  # Description   : Determine if we're running in a "single" lib-build or part of a
  #                 "meta"-repository ( submodule ). 
  # Parameters    : None
  # Returns       : Updates the value FUNC_RESULT.
  #                 -1 - We're neither a git-repo or submodule.
  #                  0 - We're a submodule
  #                  1 - We're a top-repo ( Single library )
  # --------------------------------------------------------------------------------------
  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 [ -e ./.git ]; then
  	    FUNC_RESULT="1"
          return
      elif [ -e ../.git ]; then
          if [ -e ../.submodules ]; then
              echo "Seems like we're already a submodule. Nothing to do here."
              FUNC_RESULT="0"
              return
          fi
      fi
      FUNC_RESULT="-1"
      return
  }
  
  # Name          : check_working_dir
  # Description   : If we're in the top of our repo, we can run this script further.
  # Parameters    : None.
  # Returns       : Updates the value FUNC_RESULT.
  #                 -1 - Not used.
  #                  0 - We're not on the top-level
  #                  1 - We're at the top-level. Good to go.
  # --------------------------------------------------------------------------------------
  function check_working_dir() 
  {
      FUNC_RESULT="-1"
      # Check if we're in the top-level directory of our repository.
      if [ -f ./scripts/submodules.list ]; then
          # We're good to go
          FUNC_RESULT="1"
          return
      fi
      FUNC_RESULT="0"
      return
  }
  
  # Name          : read_submodules
  # Description   : Read the list of submodules needed for this project
  # Parameters    : None
  # Returns       : Updates the value FUNC_RESULT
  #                 0 - Module list was not found
  #                 1 - Module list was found and read.
  # --------------------------------------------------------------------------------------
  function read_submodules() 
  {
      FUNC_RESULT="-1"
      if [ -e ./scripts/submodules.list ]; then
          source ./scripts/submodules.list
          FUNC_RESULT="1"
          return
      fi
  
      echo "Submodules list not found...."
      FUNC_RESULT="0"
      return
  }
  
  # Name          : add_submodules
  # Description   : Configure the repo to add the submodules.
  # Parameters    : None.
  # Returns       : None.
  # --------------------------------------------------------------------------------------
  function add_submodules() 
  {
      echo -e "Adding SubModule(s)."
      for SUB_MODULE in ${SUB_MODULES}
      do
          echo -e "< ${SUB_MODULE} >"
09e13681   Steven de Ridder   Adjusted script t...
108
109
          if [[ "${OPEN_REPOS[*]}" =~ "${SUB_MODULE}" ]];
          then
b7390482   Steven de Ridder   modified CMakeLis...
110
              git submodule add -f ${GIT_URL_SUBS}/${SUB_MODULE}.git submodules/${SUB_MODULE}
09e13681   Steven de Ridder   Adjusted script t...
111
112
              git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS}/${SUB_MODULE}.git
          else
b7390482   Steven de Ridder   modified CMakeLis...
113
              git submodule add -f ${GIT_URL_SUBS_CLOSED}/${SUB_MODULE}.git submodules/${SUB_MODULE}
09e13681   Steven de Ridder   Adjusted script t...
114
115
              git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS_CLOSED}/${SUB_MODULE}.git
          fi
c00d100f   Steven de Ridder   Added submodule s...
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
      done
  }
  
  # Name          : get_submodules
  # Description   : Actually get the submodules from gitlab and add them.
  # Parameters    : None
  # Returns       : None
  # --------------------------------------------------------------------------------------
  function get_submodules() 
  {
      git submodule update --init --recursive
  }
  
  # Name          : update_submodules
  # Description   : Update the submodules already added.
  # Parameters    : None 
  # Returns       : None
  # --------------------------------------------------------------------------------------
  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        ==
  # =============================================================================
  check_top_or_sub
  if [ "${FUNC_RESULT}" == "0" ]; then
      echo "Seems like we're a submodule already or not part of a repository."
      exit 0
  fi
  
  check_working_dir
  if [ "${FUNC_RESULT}" == "0" ]; then
      echo "Go to the top of this repository and type : scripts/setup_submodules [-i|--install]"
      exit 0
  fi
  
  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