File indexing completed on 2024-04-14 14:08:43

0001 #!/bin/bash
0002 #set -x
0003 #=============================================================================
0004 # SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
0005 # SPDX-FileCopyrightText: 2021 Johnny Jazeix <jazeix@gmail.com>
0006 #
0007 # SPDX-License-Identifier: GPL-3.0-or-later
0008 #=============================================================================
0009 if [ $# != 3 ]; then
0010   echo "Usage: createit.sh [new GCompris activity] \"username\" email"
0011   echo "   e.g.: createit.sh myactivity \"Your Name\" xx@yy.org"
0012   exit 1
0013 fi
0014 
0015 activity=$1
0016 username=$2
0017 email=$3
0018 # Make it camel case
0019 Activity=$(echo ${activity^} | sed 's/-\(.\)/\u\1/g')
0020 activitydir=$1
0021 
0022 template=template
0023 Template=${template^}
0024 templatedir=template
0025 
0026 path=`dirname $0`
0027 
0028 if [ -d $activitydir ]
0029 then
0030   echo "ERROR: Activity $activitydir already present"
0031   exit 1
0032 fi
0033 
0034 cp -r $templatedir $activitydir
0035 
0036 
0037 #retrieve version code
0038 major=`awk '/set\(GCOMPRIS_MAJOR_VERSION / {print substr ($NF, 0, length($NF)-1); exit}' <  ../../CMakeLists.txt`
0039 minor=`awk '/set\(GCOMPRIS_MINOR_VERSION / {print substr ($NF, 0, length($NF)-1); exit}' <  ../../CMakeLists.txt`
0040 patch=`awk '/set\(GCOMPRIS_PATCH_VERSION / {print substr ($NF, 0, length($NF)-1); exit}' <  ../../CMakeLists.txt`
0041 versioncode=$(($major*10000+$minor*100+$patch))
0042 
0043 currentYear=`date +%Y`
0044 
0045 cd $activitydir
0046 mv $template.js $activity.js
0047 mv $template.svg $activity.svg
0048 mv $Template.qml $Activity.qml
0049 if [[ "$OSTYPE" == "darwin"* ]]; then
0050   sed -i '' s/$template/$activity/g *
0051   sed -i '' s/$Template/$Activity/g *
0052   sed -i '' s/"creationversion"/$versioncode/g *
0053   sed -i '' s/"YEAR"/$currentYear/g *
0054   sed -i '' s/"NAME"/"$username"/g *
0055   sed -i '' s/"EMAIL"/$email/g *
0056 else
0057   sed -i s/$template/$activity/g *
0058   sed -i s/$Template/$Activity/g *
0059   sed -i s/"creationversion"/$versioncode/g *
0060   sed -i s/"YEAR"/$currentYear/g *
0061   sed -i s/"NAME"/"$username"/g *
0062   sed -i s/"EMAIL"/$email/g *
0063 fi
0064 cd ..
0065 
0066 #
0067 # The list of activities (keeping it sorted)
0068 #
0069 
0070 # Create the list without comments
0071 grep -v "^#" activities.txt > activities.txt.tmp
0072 echo $activity >> activities.txt.tmp
0073 
0074 # Save the comments
0075 grep "^#" activities.txt > activities.txt.tmp.comment
0076 
0077 # The output of sort depends on the locale so we set C by default
0078 LC_ALL=C
0079 
0080 # Concat both to form the new list
0081 mv activities.txt.tmp.comment activities.txt
0082 sort -u activities.txt.tmp >> activities.txt
0083 
0084 # Remove temp files
0085 rm activities.txt.tmp