3 ### Prepare: set global variables ###
5 SCRIPTDIR="`cd \`dirname $0\`/; pwd`"
7 LIBDIR=/share/tizen-web-ui-fw
13 # Parse commandline options, and export option variables
15 # Created by Youmin Ha <youmin.ha@samsung.com>
18 # - Set option_list array like below:
19 # option_list=( "--prelink" "--foo=" )
20 # - Add this inc by following code:
21 # . ${TOPDIR}/inc/parseopt.inc
23 # After including parseopt.inc, argc and argv are set, excluding options in option_list.
30 if test ! -n "${option_list}"; then
31 local option_list=( ); # available option list, starting --
36 while [ "$idx" -lt "$argc" ];
38 local arg=${argv[${idx}]}
41 for _valid_option in ${option_list[@]}
43 #echo "...for valid option:$_valid_option"
44 #echo " ...check arg:${arg:0:${#_valid_option}}"
45 if [[ "$_valid_option" == "${arg:0:${#_valid_option}}" ]]; then
46 #echo "...found valid option:$_valid_option"
47 if [ ${_valid_option:${#_valid_option}-1} == "=" ]; then
48 eval "export ${arg#--}"
50 eval "export ${arg#--}=1"
53 # pull remained options
54 let "tmp_idx = $idx + 1"
55 while [ "$tmp_idx" -lt "${#argv[@]}" ]
57 argv[$tmp_idx-1]="${argv[$tmp_idx]}"
58 let "tmp_idx = $tmp_idx + 1"
60 unset argv[${#argv[@]}-1]
65 if [ ! -n "$__changed" ]; then
73 option_list=( "--copylib" "--type=" )
77 INSTALL_DIR=${argv[1]}
78 if [ ! -n "$INSTALL_DIR" ]; then
81 DESTDIR="$INSTALL_DIR/$APP_NAME"
84 # Print usage and exit #
88 if [ -n "$1" ]; then local ERRMSG=$1; else local ERRMSG="Invalid arguments"; fi
91 if [ -n "$1" ]; then EXITCODE=1; echo "ERROR: $ERRMSG"; echo ""; fi
94 echo "Usage: $0 <--copylib> <--type=[w3c|tizen]> <app-name> <install-dir>"
96 echo " app-name : Your application name. If whitespace is contained, wrap it "
97 echo " by quote mark."
98 echo " install-dir : Directory which the template code directory with name of"
99 echo " app-name is created in."
100 echo " <install-dir>/<app-name>/ directory will be created."
101 echo " --copylib : When this option is used, all libs and resources will be "
102 echo " copied into template directory, and all templates will refer"
103 echo " those copied libs."
104 echo " --type=[w3c|tizen]"
105 echo " Set type of application template. If no --type= option is given,"
106 echo " the type is set to tizen by default."
117 if [ ! -n "$APP_NAME" ]; then usage "No app-name is given."; fi
118 if [ ! -d "$INSTALL_DIR" ]; then usage "No install-dir is found; $INSTALL_DIR"; fi
119 if [ -e "$DESTDIR" ]; then usage "$DESTDIR already exists."; fi
123 ### Copy template files into installation directory ###
124 function copy_template
126 local libpath="${PREFIX}${LIBDIR}"
127 local tplpath=$libpath/template
129 # Check if this script is in src script
130 if [ -e "${SCRIPTDIR}/../build/tizen-web-ui-fw" ]; then
131 libpath="${SCRIPTDIR}/../build/tizen-web-ui-fw"
132 tplpath=${SCRIPTDIR}/../src/template
135 echo "Copying template files into $DESTDIR..."
136 mkdir -p $DESTDIR || usage "ERROR: Failed to create directory: $DESTDIR"
137 find $tplpath/ -maxdepth 1 -type f | xargs -i cp -a {} $DESTDIR/ || usage "ERROR: Failed to copy templates" ;
138 if [[ ! -n "$type" ]]; then
141 if [[ -n "$type" && -d "$tplpath/$type" ]]; then # Copy type-specific files
142 cp -a $tplpath/$type/* $DESTDIR/ || usage "ERROR: Failed to copy templates"
145 # copy lib if --copylib option is given
146 if [ -n "$copylib" ]; then
147 echo "Copying libs into $DESTDIR..."
148 cp -a ${libpath} ${DESTDIR}/ || usage "ERROR: Failed to copy libs"
149 DATA_FRAMEWORK_ROOT="data-framework-root=\"tizen-web-ui-fw\""
150 LIBDIR="tizen-web-ui-fw/latest/js" # This new value is used by replace_template()
151 else # otherwise, just set libdir
152 LIBDIR="file://${PREFIX}${LIBDIR}/template"
157 ### Replace filename & keywords ###
158 function replace_template
160 echo "Replacing contents of template files..."
162 local replace_keywords=( "APP_NAME" "LIBDIR" "DATA_FRAMEWORK_ROOT")
164 local in_file_path_list=`find $DESTDIR -name '*.in' -type f -print`
165 for in_file_path in ${in_file_path_list[@]}; do
166 for keyword in "${replace_keywords[@]}"; do
167 eval "local val=\$$keyword"
168 #echo "keyword=$keyword, val=$val"
169 sed -i -e "s#@$keyword@#$val#g" $in_file_path
172 rename 's/\.in//' $DESTDIR/*