Skip to content

Commit

Permalink
monocleaner-download quiet mode
Browse files Browse the repository at this point in the history
Closes #3
  • Loading branch information
ZJaume committed Jul 14, 2023
1 parent e2dd73d commit 7c0e6a0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## v1.4.1
### Added
- `monocleaner-download` quiet mode.

### Changed
- Precompile punctuation normalization regular expressions for better speed.

Expand Down
49 changes: 31 additions & 18 deletions scripts/monocleaner-download
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,54 @@
usage() {
echo "Script to download Bicleaner language packs."
echo
echo "Usage: `basename $0` <lang> <download_path>"
echo " <lang> Language code."
echo " <download_path> Path where downloaded language pack should be placed."
echo "Usage: `basename $0` <lang> [download_path]"
echo " -q Quiet mode."
echo " -h Show this help message."
echo " <lang> Language code."
echo " [download_path] Path where downloaded language pack should be placed."
echo " Default: current path."
}

invalid_url(){
wget -S --spider -o - $1 | grep -q '404 Not Found'
}

if [[ $1 == "-h" ]] || [[ $1 == "--help" ]];
then
usage 2>&1
exit 0
elif [[ $# -lt 2 ]];
WGETQUIET=""
TAROPS="xvf"
while getopts "qh" options
do
case "${options}" in
q) WGETQUIET="-q"
TAROPS="xf";;
h) usage
exit 0;;
\?) usage 1>&2
exit 1;;
esac
done

URL="https://github.com/bitextor/monocleaner-data/releases/latest/download"
L1=${@:$OPTIND:1}
DOWNLOAD_PATH=${@:$OPTIND+1:1}
if [ -z $L1 ];
then
echo "Wrong number of arguments: $@" 2>&1
echo "Error language is mandatory: $@" 2>&1
usage 2>&1
exit 1
fi

URL="https://github.com/bitextor/monocleaner-data/releases/latest/download"
L1=$1
if [ "$2" != "" ]; then
DOWNLOAD_PATH=$2
else
if [ "$DOWNLOAD_PATH" == "" ]; then
DOWNLOAD_PATH="."
fi

if invalid_url $URL/$L1.tgz
then
>&2 echo $L1 language pack does not exist
else
wget -P $DOWNLOAD_PATH $URL/$L1.tgz
tar xvf $DOWNLOAD_PATH/$L1.tgz -C $DOWNLOAD_PATH
wget $WGETQUIET -P $DOWNLOAD_PATH $URL/$L1.tgz
tar $TAROPS $DOWNLOAD_PATH/$L1.tgz -C $DOWNLOAD_PATH
rm $DOWNLOAD_PATH/$L1.tgz
fi

echo Finished >&2
if [ -z $WGETQUIET ]; then
echo Finished >&2
fi

0 comments on commit 7c0e6a0

Please sign in to comment.