Skip to content

Commit

Permalink
update script
Browse files Browse the repository at this point in the history
  • Loading branch information
sokil committed Nov 29, 2018
1 parent a543eec commit 4ec31a6
Showing 1 changed file with 43 additions and 15 deletions.
58 changes: 43 additions & 15 deletions update_db.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,62 @@
#!/usr/bin/env bash

CURRENT_DIR=$(dirname $(readlink -f $0))
PKG_ISOCODES_DIR=$CURRENT_DIR/build/iso-codes
PKG_ISOCODES_DIR="${CURRENT_DIR}/build/iso-codes"
PKG_ISOCODES_REPO="https://salsa.debian.org/iso-codes-team/iso-codes.git"
MESSAGES_DIR=$CURRENT_DIR/messages
DATABASES_DIR=$CURRENT_DIR/databases

if [[ -z $1 ]]; then
UPDATE_BASE_DIR=$CURRENT_DIR
else
UPDATE_BASE_DIR=$1

if [[ ! -d $UPDATE_BASE_DIR ]]; then
echo -e "Passed directory \033[0;31m${UPDATE_BASE_DIR}\033[0m is not exists"
exit 1
fi

if [[ ! -w $UPDATE_BASE_DIR ]]; then
echo -e "Passed directory \033[0;31m${UPDATE_BASE_DIR}\033[0m is not writable"
exit 1
fi
fi

MESSAGES_DIR="${UPDATE_BASE_DIR}/messages"
DATABASES_DIR="${UPDATE_BASE_DIR}/databases"

echo -e "\033[0;32mMessages directory: \033[0m ${MESSAGES_DIR}"
echo -e "\033[0;32mDatabase directory: \033[0m ${DATABASES_DIR}"

# update pkg-isocodes source
echo -e "\033[0;32mUpdate pkg-isocodes repository\033[0m"

if [[ -d $PKG_ISOCODES_DIR ]]; then
cd $PKG_ISOCODES_DIR
git pull origin master
else
mkdir -p $PKG_ISOCODES_DIR
cd $PKG_ISOCODES_DIR
git clone $PKG_ISOCODES_REPO .
git clone $PKG_ISOCODES_REPO $PKG_ISOCODES_DIR/iso-codes
fi

cd $CURRENT_DIR

# clear previous database and locales files
rm -rf $MESSAGES_DIR
mkdir -p $MESSAGES_DIR
rm -rf $DATABASES_DIR
mkdir -p $DATABASES_DIR

# add copyright notice
echo -e "This files is part of iso-codes library.\nSee license agreement at ${PKG_ISOCODES_REPO}" > $DATABASES_DIR/LICENSE
echo -e "This files is part of iso-codes library.\nSee license agreement at ${PKG_ISOCODES_REPO}" > $MESSAGES_DIR/LICENSE

# move database files
echo -e "\033[0;32mCopy database files to target dir ${DATABASES_DIR}\033[0m"

cp $PKG_ISOCODES_DIR/data/iso_*.json $DATABASES_DIR

# move locale message files
echo -e "\033[0;32mCopy message files to target dir ${MESSAGES_DIR}\033[0m"

for database_file in `ls -1 $DATABASES_DIR`; do
database_name=`echo $database_file | sed "s/.json//g"`
gettext_domain=`echo $database_name | sed "s/iso_//g"`
source_locale_dir=$PKG_ISOCODES_DIR/$database_name

echo -e " * Copying ${source_locale_dir} ..."

for locale_file in `ls -1 $source_locale_dir | grep .po`; do
locale_name=`echo $locale_file | sed "s/.po//g"`
# copy locale file
Expand All @@ -46,16 +67,23 @@ for database_file in `ls -1 $DATABASES_DIR`; do
done;
done

# locate composer
# add copyright notice
echo -e "This files is part of iso-codes library.\nSee license agreement at ${PKG_ISOCODES_REPO}" > $DATABASES_DIR/LICENSE
echo -e "This files is part of iso-codes library.\nSee license agreement at ${PKG_ISOCODES_REPO}" > $MESSAGES_DIR/LICENSE

# test updated database and message files
echo -e "\033[0;32mTest updated database\033[0m"

cd ${CURRENT_DIR}
COMPOSER_PATH=`which composer`
if [[ $? -eq 1 ]]; then
COMPOSER_PATH=`which composer.phar`
if [[ $? -eq 1 ]]; then
echo -e "\033[0;31m\n\nCan not locale composer for testing build.\033[0m\n\n"
echo -e "\033[0;31m\n\nCan not locate composer for testing build.\033[0m\n\n"
exit 1
fi
fi

# start tests
$COMPOSER_PATH test

# message on success test
Expand Down

0 comments on commit 4ec31a6

Please sign in to comment.