Blame view

scripts/setup_submodules 2.56 KB
0bf1b2f7   Peter M. Groen   Fixed script.
1
  #!/bin/bash
59367614   Peter M. Groen   Install script..
2
  # =================
0bf1b2f7   Peter M. Groen   Fixed script.
3
  # = Do not change.
59367614   Peter M. Groen   Install script..
4
5
  # =================
  GIT_URL_SUBS="http://gitlab.osdev.nl/open_source"
e0b1fe64   Peter M. Groen   Fixed script.
6
  FUNC_RESULT=""
b5d9e433   Peter M. Groen   Fixed License Hea...
7
  
e0b1fe64   Peter M. Groen   Fixed script.
8
9
  function print_usage_exit() 
  {
b5d9e433   Peter M. Groen   Fixed License Hea...
10
11
12
13
14
15
16
      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
  }
  
e0b1fe64   Peter M. Groen   Fixed script.
17
18
  function check_top_or_sub() 
  {
59367614   Peter M. Groen   Install script..
19
20
21
      # 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
e0b1fe64   Peter M. Groen   Fixed script.
22
23
24
25
26
      if [ -e ./.git ]; then
  	    FUNC_RESULT="1"
          return
      elif [ -e ../.git ]; then
          if [ -e ../.submodules ]; then
59367614   Peter M. Groen   Install script..
27
              echo "Seems like we're already a submodule. Nothing to do here."
e0b1fe64   Peter M. Groen   Fixed script.
28
29
              FUNC_RESULT="0"
              return
59367614   Peter M. Groen   Install script..
30
31
          fi
      fi
e0b1fe64   Peter M. Groen   Fixed script.
32
33
      FUNC_RESULT="0"
      return
59367614   Peter M. Groen   Install script..
34
35
  }
  
e0b1fe64   Peter M. Groen   Fixed script.
36
37
  function check_working_dir() 
  {
59367614   Peter M. Groen   Install script..
38
39
40
      # Check if we're in the top-level directory of our repository.
      if [ -f ./scripts/submodules.list ]; then
          # We're good to go
e0b1fe64   Peter M. Groen   Fixed script.
41
42
          FUNC_RESULT="1"
          return
59367614   Peter M. Groen   Install script..
43
      fi
e0b1fe64   Peter M. Groen   Fixed script.
44
45
      FUNC_RESULT="0"
      return
59367614   Peter M. Groen   Install script..
46
47
  }
  
e0b1fe64   Peter M. Groen   Fixed script.
48
49
  function read_submodules() 
  {
59367614   Peter M. Groen   Install script..
50
51
      if [ -e ./scripts/submodules.list ]; then
          source ./scripts/submodules.list
b5d9e433   Peter M. Groen   Fixed License Hea...
52
53
54
      fi
  }
  
e0b1fe64   Peter M. Groen   Fixed script.
55
56
  function add_submodules() 
  {
b5d9e433   Peter M. Groen   Fixed License Hea...
57
58
      for SUB_MODULE in ${SUB_MODULES}
      do
e0b1fe64   Peter M. Groen   Fixed script.
59
60
          git submodule add -f ${GIT_URL_SUBS}/${SUB_MODULE}.git ${SUB_MODULE}
          git config submodule.${SUB_MODULE}.url ${GIT_URL_SUBS}/${SUB_MODULE}.git
b5d9e433   Peter M. Groen   Fixed License Hea...
61
62
63
      done
  }
  
e0b1fe64   Peter M. Groen   Fixed script.
64
65
  function get_submodules() 
  {
b5d9e433   Peter M. Groen   Fixed License Hea...
66
67
68
      git submodule update --init --recursive
  }
  
0bf1b2f7   Peter M. Groen   Fixed script.
69
70
  function update_submodules() 
  {
b5d9e433   Peter M. Groen   Fixed License Hea...
71
72
73
74
75
76
      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        ==
  # =============================================================================
e0b1fe64   Peter M. Groen   Fixed script.
77
78
  check_top_or_sub
  if [ "${FUNC_RESULT}" == "0" ]; then
59367614   Peter M. Groen   Install script..
79
80
81
82
      echo "Seems like we're a submodule already or not part of a repository."
      exit 0
  fi
  
e0b1fe64   Peter M. Groen   Fixed script.
83
84
  check_working_dir
  if [ "${FUNC_RESULT}" == "0" ]; then
59367614   Peter M. Groen   Install script..
85
86
87
88
      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...
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
  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