aboutsummaryrefslogtreecommitdiff
path: root/update.sh
diff options
context:
space:
mode:
authorEinhard Leichtfuß <alguien@respiranto.de>2018-12-23 07:06:00 +0100
committerEinhard Leichtfuß <alguien@respiranto.de>2018-12-23 07:06:00 +0100
commita22ff75e023034068d07adae2ebc427607b24b5d (patch)
tree146c797ae2cee3bbe302f3a74467e04014f8c9ae /update.sh
parentcbbef9daa26418fd13aaa23cbb97ec0e536ae4e1 (diff)
Simplify and abstract from "$tmp"
- Add input and write to basic.sh to no longer need to know "$tmp" in the calling scripts. Also, - make runnable from outside the directory containing the scripts, - simplify chained grep and sed commands.
Diffstat (limited to 'update.sh')
-rwxr-xr-xupdate.sh28
1 files changed, 19 insertions, 9 deletions
diff --git a/update.sh b/update.sh
index e15d41b..6e06e00 100755
--- a/update.sh
+++ b/update.sh
@@ -29,12 +29,18 @@
# -ua: Update all that are out of date.
# -uaf: Update all, even if they appear up to date.
+script_path="$(realpath "$0")"
+script_dir="${script_path%/*}"
+
+
+# Long names table.
typeset -A long
long[fra]=French
long[deu]=German
long[eng]=English
long[spa]=Spanish
+# Contributors for some specific PKGBUILDs.
typeset -A contrs
contrs[deu-eng-bin]=\
'# Contributor: akane <grangerspit@gmail.com> <xmpp:heiß@neko.im>'$'\n'
@@ -45,6 +51,7 @@ contrs[fra-eng-bin]=\
contrs[eng-fra-bin]=\
'# Contributor: Benjamin Vanderford <hazor_at_swrpg_dot_info>'$'\n'
+# prepare functions.
typeset -A prepare
prepare[deu-fra]=\
'prepare()
@@ -58,7 +65,8 @@ prepare[deu-fra]=\
}
'
-. basic.sh
+
+. "${script_dir}/basic.sh"
function main
{
@@ -82,7 +90,6 @@ function main
fi
-
init
if [[ "$type" == src ]]
then
@@ -99,6 +106,7 @@ function main
fi
}
+
# $1 source type: (normal|vcs)
# requires: $PWD == <base directory>/<type>
function update
@@ -110,7 +118,7 @@ function update
lang_a="${long[${lang%-*}]}"
lang_b="${long[${lang#*-}]}"
- cp ../sample.PKGBUILD "$tmp"
+ input ../sample.PKGBUILD
replace '%LANG%' "$lang"
replace '%LANG_A%' "$lang_a"
@@ -122,16 +130,17 @@ function update
if [[ "$ver" == "$convver" ]]
then
- delete_line '^_pkgver=\${pkgver\/\/_\/-}$'
+ delete_line '^_pkgver=\$\{pkgver\/\/_\/-\}$'
replace '_pkgver' 'pkgver'
fi
replace_line '%PREPARE%' "${prepare[${lang}${ext}]}" rm-plus-one
- mv "$tmp" PKGBUILD
+ write PKGBUILD
makepkg --printsrcinfo > .SRCINFO
}
+
# $1 type: (src|bin)
# $2 suffix: (|-bin)
# $3 platform: (src|dictd)
@@ -152,7 +161,7 @@ function handle_all
do
cd dict-freedict-${lang}${ext} || exit 1
$nopull || git pull -q
- pkgver="$(grep pkgver .SRCINFO | sed -E 's/\s*pkgver\s*=\s*(.+)\s*/\1/')"
+ pkgver="$(sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p' .SRCINFO)"
data="$(jq -r ".[] | select(.name == \"${lang}\") | .releases[] | select(.platform==\"$platform\")" ../../freedict-database.json)"
ver="$(jq -r '.version' <<< "$data")"
url="$(jq -r '.URL' <<< "$data")"
@@ -185,6 +194,7 @@ function handle_all
cd ..
}
+
# $1 type: (svn)
# $2 suffix: (-svn)
# ${@:3} args: $@
@@ -201,10 +211,10 @@ function handle_all_vcs
do
cd dict-freedict-${lang}${ext} || exit 1
$nopull || git pull -q
- pkgver="$(grep pkgver .SRCINFO | sed -E 's/\s*pkgver\s*=\s*(.+)\s*/\1/')"
+ pkgver="$(sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p' .SRCINFO)"
makepkg --nobuild --nodeps > /dev/null 2>&1
- ver="$(makepkg --printsrcinfo | grep pkgver \
- | sed -E 's/\s*pkgver\s*=\s*(.+)\s*/\1/')"
+ ver="$(makepkg --printsrcinfo \
+ | sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p')"
convver="$ver"
if [[ "$1" == "-u" && "$2" == "$lang" ]] || [[ "$1" == "-uaf" ]]