aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--TODO1
-rw-r--r--basic.sh14
-rwxr-xr-xmake_install.sh11
-rwxr-xr-xupdate.sh28
4 files changed, 42 insertions, 12 deletions
diff --git a/TODO b/TODO
index 1d246f1..9a8a3a8 100644
--- a/TODO
+++ b/TODO
@@ -6,6 +6,7 @@ TODO file for aur-fd-scripts
* Use the provided sample.* instead of relying them to be in the destination
directories.
* [consider] Unify the different sample.PKGBUILDs.
+* Split off a (bash) configuration file.
[FEATURES]
* Notify on checksum change.
diff --git a/basic.sh b/basic.sh
index 77d893b..891d9c5 100644
--- a/basic.sh
+++ b/basic.sh
@@ -47,6 +47,20 @@ function init
tmp_="$tmp_d/b"
}
+# $1: file to treat as input: filename
+# requires: init to be run
+function input
+{
+ cp "$1" "$tmp"
+}
+
+# $1: file to write to: filename
+# requires: init and input to be run
+function write
+{
+ cp "$tmp" "$1"
+}
+
function cleanup
{
rm -rf "$tmp_d"
diff --git a/make_install.sh b/make_install.sh
index 0a3098c..6a3468d 100755
--- a/make_install.sh
+++ b/make_install.sh
@@ -20,7 +20,10 @@
# along with aur-fd-scripts. If not, see <https://www.gnu.org/licenses/>.
#
-. basic.sh
+script_path="$(realpath "$0")"
+script_dir="${script_path%/*}"
+. "${script_dir}/basic.sh"
+
function main
{
@@ -54,14 +57,16 @@ function main
fi
}
+
function make_install
{
pkgname=dict-freedict-${lang}${ext}
- cp ../sample.install "$tmp"
+ input ../sample.install
replace "%LANG%" "$lang"
replace "%SUFFIX%" "$ext"
- mv "$tmp" ${pkgname}/${pkgname}.install
+ write ${pkgname}/${pkgname}.install
}
+
main "$@"
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" ]]