diff options
author | Einhard Leichtfuß <alguien@respiranto.de> | 2018-12-23 07:06:00 +0100 |
---|---|---|
committer | Einhard Leichtfuß <alguien@respiranto.de> | 2018-12-23 07:06:00 +0100 |
commit | a22ff75e023034068d07adae2ebc427607b24b5d (patch) | |
tree | 146c797ae2cee3bbe302f3a74467e04014f8c9ae | |
parent | cbbef9daa26418fd13aaa23cbb97ec0e536ae4e1 (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-- | TODO | 1 | ||||
-rw-r--r-- | basic.sh | 14 | ||||
-rwxr-xr-x | make_install.sh | 11 | ||||
-rwxr-xr-x | update.sh | 28 |
4 files changed, 42 insertions, 12 deletions
@@ -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. @@ -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 "$@" @@ -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" ]] |