source: flair-src/tags/0.3.3/scripts/clone_demo.sh@ 435

Last change on this file since 435 was 405, checked in by Sanahuja Guillaume, 3 years ago

adapt demos for clone demos script

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/bin/bash
2
3function info () {
4 echo -e "\033[32m$1\033[0m"
5}
6
7function warn () {
8 echo -e "\033[33m$1\033[0m"
9}
10
11function err () {
12 echo -e "\033[31m$1\033[0m"
13 exit 1
14}
15
16#arg 1 cmake file
17#arg 2 old project name
18#arg 3 new project name
19function parse_cmakefile () {
20 echo
21 info "parsing ${1}"
22 dir=$(dirname ${1})
23
24 #rename cpp and h files from cmakelist
25 cat ${1} | grep cpp | grep $2 | while read file; do
26 #remove \r
27 file=$(echo $file | sed 's/\r//')
28 new_file=$(echo ${file/$2/$3})
29
30 mv ${dir}/${file} ${dir}/${new_file}
31 echo renamed $file to $new_file
32
33 file=$(echo ${file/cpp/h})
34 if [ -f ${dir}/${file} ]; then
35 new_file=$(echo ${file/$2/$3})
36 mv ${dir}/${file} ${dir}/${new_file}
37 echo renamed $file to $new_file
38 fi
39
40 done
41
42 #replace old project refeerence to new project un cmakelists
43 sed -i "s/${2}/${3}/g" ${1}
44 echo "changed reference of $2 to $3"
45}
46
47#arg 1 cpp file
48#arg 2 old project name
49#arg 3 new project name
50function parse_source_file () {
51 echo
52 info "parsing ${1}"
53 sed -i "s/${2}/${3}/g" ${1}
54 echo "changed reference of $2 to $3"
55}
56
57if [ "${2}" = "" ]; then
58 err "usage clone_demo.sh path_to_source_demo destination_demo_name"
59fi
60
61if ! [ -f ${1}/CMakeLists.txt ]; then
62 err "${1} directory does not contain CMakeLists.txt"
63fi
64
65if [ -d ${2} ];then
66 err "output ${2} directory already exists"
67fi
68
69echo cloning ${1} to ${2}
70cp -r ${1} ./${2}
71cd ./${2}
72
73#get old project name from top cmakelists
74old_project=$(cat ./CMakeLists.txt | grep -i project\( | cut -d "(" -f2 | cut -d ")" -f1)
75
76echo "old project name is" $old_project
77
78#search all CMakeLists.txt, sort by depth and loop
79find -name "CMakeLists.txt" -printf '%h\0%d\0%p\n' | sort -t '\0' -n | awk -F '\0' '{print $3}' | while read cmakefile; do
80 parse_cmakefile $cmakefile ${old_project} ${2}
81done
82
83
84#find all cpp files
85find ${dir} -name "*.cpp" | while read file; do
86 parse_source_file $file ${old_project} ${2}
87done
88
89#find all h files
90find ${dir} -name "*.h" | while read file; do
91 parse_source_file $file ${old_project} ${2}
92done
93
94#find all sh files
95find ${dir} -name "*.sh" | while read file; do
96 parse_source_file $file ${old_project} ${2}
97done
Note: See TracBrowser for help on using the repository browser.