From 915faab9c074a0a30b8321c3836d0b35f475e94d Mon Sep 17 00:00:00 2001 From: Einhard Leichtfuß Date: Fri, 29 Apr 2022 14:58:55 +0200 Subject: Use proper .bash suffix --- README | 8 +- TODO | 2 +- basic.bash | 102 +++++++++++++++++++++++ basic.sh | 102 ----------------------- general-config.bash | 89 ++++++++++++++++++++ general-config.sh | 89 -------------------- make_install.bash | 77 +++++++++++++++++ make_install.sh | 77 ----------------- update.bash | 211 +++++++++++++++++++++++++++++++++++++++++++++++ update.sh | 211 ----------------------------------------------- user-config.default.bash | 9 ++ user-config.default.sh | 9 -- 12 files changed, 493 insertions(+), 493 deletions(-) create mode 100644 basic.bash delete mode 100644 basic.sh create mode 100644 general-config.bash delete mode 100644 general-config.sh create mode 100755 make_install.bash delete mode 100755 make_install.sh create mode 100755 update.bash delete mode 100755 update.sh create mode 100644 user-config.default.bash delete mode 100644 user-config.default.sh diff --git a/README b/README index 28f088a..1031184 100644 --- a/README +++ b/README @@ -6,17 +6,17 @@ Things are to be written here. Configuration: -------------- -Copy user-config.default.sh to user-config.sh and set any options to your +Copy user-config.default.bash to user-config.bash and set any options to your linking. Usage: ------ -Make sure user-config.sh exists and has the correct $maintainer variable set. +Make sure user-config.bash exists and has the correct $maintainer variable set. -Then, just call ./update.sh or ./make_install.sh. Usage information will be -displayed. +Then, just call ./update.bash or ./make_install.bash. Usage information will +be displayed. Dependencies: diff --git a/TODO b/TODO index 27c294e..1485fa7 100644 --- a/TODO +++ b/TODO @@ -16,6 +16,6 @@ TODO file for aur-fd-scripts * Set up directory structure if not existing. * [consider] Notify on checksum change (should not happen unless version numbers change). -* Add $basedir in user-config.default.sh +* Add $basedir in user-config.default.bash * check(): `make validation' - The .dtd and .rng files would need to be included in the tools package. diff --git a/basic.bash b/basic.bash new file mode 100644 index 0000000..643c39d --- /dev/null +++ b/basic.bash @@ -0,0 +1,102 @@ +#!/usr/bin/env bash +# +# Copyright 2018 Einhard Leichtfuß +# +# basic.bash - script containing the array of the to be generated dictionary's +# names and some common functionality, mostly wrapping sed. +# +# Copyright 2018,2022 Einhard Leichtfuß +# +# This file is part of aur-fd-scripts +# +# aur-fd-scripts is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# aur-fd-scripts is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with aur-fd-scripts. If not, see . +# + +# All methods operate on the file "$tmp". + + +script_path="$(realpath "$0")" +script_dir="${script_path%/*}" + +. "${script_dir}/general-config.bash" || exit 1 +. "${script_dir}/user-config.bash" || exit 1 + + +function init +{ + tmp_d="$(mktemp -d)" + tmp="$tmp_d/a" + 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" +} +trap cleanup EXIT + +# $1: string to replace: extended regular expression +# $2: string to replace with: sed replacement string +function replace +{ + sed -Ei "s/${1}/${2}/g" "$tmp" +} + +# Replace line by a string (possibly including newlines). +# $1 line to replace: extended regular expression +# $2 text to replace with: (newline terminated) sed replacement string +# $3 removal type: (rm-plus-one|normal) +# `- If $2 is empty, whether to remove only that line or also the one +# following. +function replace_line +{ + if test -n "$2" + then + printf '%s' "$2" > "$tmp_" + + sed -Ei " + /${1}/ { + r $tmp_ + d + } + " "$tmp" + else + if [[ "$3" == rm-plus-one ]] + then + sed -Ei "/${1}/,+1 d" "$tmp" + else + sed -Ei "/${1}/ d" "$tmp" + fi + fi +} + +# $1 line to delete: extended regular expression +function delete_line +{ + sed -Ei "/${1}/ d" "$tmp" +} diff --git a/basic.sh b/basic.sh deleted file mode 100644 index 5dc475f..0000000 --- a/basic.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright 2018 Einhard Leichtfuß -# -# basic.sh - script containing the array of the to be generated dictionary's -# names and some common functionality, mostly wrapping sed. -# -# Copyright 2018 Einhard Leichtfuß -# -# This file is part of aur-fd-scripts -# -# aur-fd-scripts is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# aur-fd-scripts is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with aur-fd-scripts. If not, see . -# - -# All methods operate on the file "$tmp". - - -script_path="$(realpath "$0")" -script_dir="${script_path%/*}" - -. "${script_dir}/general-config.sh" || exit 1 -. "${script_dir}/user-config.sh" || exit 1 - - -function init -{ - tmp_d="$(mktemp -d)" - tmp="$tmp_d/a" - 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" -} -trap cleanup EXIT - -# $1: string to replace: extended regular expression -# $2: string to replace with: sed replacement string -function replace -{ - sed -Ei "s/${1}/${2}/g" "$tmp" -} - -# Replace line by a string (possibly including newlines). -# $1 line to replace: extended regular expression -# $2 text to replace with: (newline terminated) sed replacement string -# $3 removal type: (rm-plus-one|normal) -# `- If $2 is empty, whether to remove only that line or also the one -# following. -function replace_line -{ - if test -n "$2" - then - printf '%s' "$2" > "$tmp_" - - sed -Ei " - /${1}/ { - r $tmp_ - d - } - " "$tmp" - else - if [[ "$3" == rm-plus-one ]] - then - sed -Ei "/${1}/,+1 d" "$tmp" - else - sed -Ei "/${1}/ d" "$tmp" - fi - fi -} - -# $1 line to delete: extended regular expression -function delete_line -{ - sed -Ei "/${1}/ d" "$tmp" -} diff --git a/general-config.bash b/general-config.bash new file mode 100644 index 0000000..d9f62d3 --- /dev/null +++ b/general-config.bash @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# +# Copyright 2018,2022 Einhard Leichtfuß +# +# general-config.bash - general configuration options +# +# This file is part of aur-fd-scripts +# +# aur-fd-scripts is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# aur-fd-scripts is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with aur-fd-scripts. If not, see . +# + + +# Dictionaries in the VCS tree, GPL2 assumed. +typeset -a vcs_langs +vcs_langs=( + deu-eng eng-deu + fra-eng eng-fra + spa-eng eng-spa + ) + +# Dictionaries imported from WikDict, hence Wiktionary. +# Dual licensed: CC-BY-SA, GNU FDL (1.1 or later). +typeset -a wikdict_langs +wikdict_langs=( + fra-deu deu-fra + ) + +typeset -a langs +langs=( "${vcs_langs[@]}" "${wikdict_langs[@]}" ) + + +# Long names table. +typeset -A long +long[fra]=French +long[deu]=German +long[eng]=English +long[spa]=Spanish + + +# Contributors for some specific PKGBUILDs (indexed by $lang$ext). +typeset -A contrs +contrs[deu-eng-bin]=\ +'# Contributor: akane '$'\n' +contrs[eng-deu-bin]=\ +'# Contributor: akane '$'\n' +contrs[fra-eng-bin]=\ +'# Contributor: Benjamin Vanderford '$'\n' +contrs[eng-fra-bin]=\ +'# Contributor: Benjamin Vanderford '$'\n' + +# Licenses (indexed by $lang) +typeset -A licenses +for lang in "${vcs_langs[@]}" +do + licenses["$lang"]="'GPL'" +done + +for lang in "${wikdict_langs[@]}" +do + licenses["$lang"]="'CCPL:by-sa' 'FDL'" +done + + +# prepare() functions (indexed by $lang$ext). +typeset -A prepare + +# Does not work for deu-fra-bin, since the index file must stay in sync. +prepare[deu-fra]=\ +'prepare() +{ + cd "$_lang" + sed -Ei \ + -e '"'"'s/(10)(10)(100\>)(\s+\(10)(Googol.*(1|Eins) mit einem Googol Nullen)/\1^(\2^\3)\4^\5/'"'"' \ + -e '"'"'s/(10)([1-9][0-9]*)(.*(1|Eins) mit \2 Nullen)/\1\^\2\3/'"'"' \ + -e '"'"'s/(die Zahl 10)(60)/\1^\2/'"'"' \ + "${_lang}.tei" +} +' diff --git a/general-config.sh b/general-config.sh deleted file mode 100644 index 040ec6a..0000000 --- a/general-config.sh +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env bash -# -# Copyright 2018,2022 Einhard Leichtfuß -# -# general-config.sh - general configuration options -# -# This file is part of aur-fd-scripts -# -# aur-fd-scripts is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# aur-fd-scripts is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with aur-fd-scripts. If not, see . -# - - -# Dictionaries in the VCS tree, GPL2 assumed. -typeset -a vcs_langs -vcs_langs=( - deu-eng eng-deu - fra-eng eng-fra - spa-eng eng-spa - ) - -# Dictionaries imported from WikDict, hence Wiktionary. -# Dual licensed: CC-BY-SA, GNU FDL (1.1 or later). -typeset -a wikdict_langs -wikdict_langs=( - fra-deu deu-fra - ) - -typeset -a langs -langs=( "${vcs_langs[@]}" "${wikdict_langs[@]}" ) - - -# Long names table. -typeset -A long -long[fra]=French -long[deu]=German -long[eng]=English -long[spa]=Spanish - - -# Contributors for some specific PKGBUILDs (indexed by $lang$ext). -typeset -A contrs -contrs[deu-eng-bin]=\ -'# Contributor: akane '$'\n' -contrs[eng-deu-bin]=\ -'# Contributor: akane '$'\n' -contrs[fra-eng-bin]=\ -'# Contributor: Benjamin Vanderford '$'\n' -contrs[eng-fra-bin]=\ -'# Contributor: Benjamin Vanderford '$'\n' - -# Licenses (indexed by $lang) -typeset -A licenses -for lang in "${vcs_langs[@]}" -do - licenses["$lang"]="'GPL'" -done - -for lang in "${wikdict_langs[@]}" -do - licenses["$lang"]="'CCPL:by-sa' 'FDL'" -done - - -# prepare() functions (indexed by $lang$ext). -typeset -A prepare - -# Does not work for deu-fra-bin, since the index file must stay in sync. -prepare[deu-fra]=\ -'prepare() -{ - cd "$_lang" - sed -Ei \ - -e '"'"'s/(10)(10)(100\>)(\s+\(10)(Googol.*(1|Eins) mit einem Googol Nullen)/\1^(\2^\3)\4^\5/'"'"' \ - -e '"'"'s/(10)([1-9][0-9]*)(.*(1|Eins) mit \2 Nullen)/\1\^\2\3/'"'"' \ - -e '"'"'s/(die Zahl 10)(60)/\1^\2/'"'"' \ - "${_lang}.tei" -} -' diff --git a/make_install.bash b/make_install.bash new file mode 100755 index 0000000..1df6acb --- /dev/null +++ b/make_install.bash @@ -0,0 +1,77 @@ +#!/usr/bin/env bash +# +# make_install.bash - script to create the .install files +# +# Copyright 2018,2022 Einhard Leichtfuß +# +# This file is part of aur-fd-scripts +# +# aur-fd-scripts is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# aur-fd-scripts is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with aur-fd-scripts. If not, see . +# + +script_path="$(realpath "$0")" +script_dir="${script_path%/*}" +. "${script_dir}/basic.bash" || exit 1 + + +function main +{ + if [ "$#" -lt 2 ] + then + echo "Usage: $0 (-|-a)" >&2 + exit 1 + elif [ "$#" -gt 2 ] + then + cd "${1}/${2}" || exit 1 + fi + + if [[ "$2" == src ]] + then + ext= + else + ext="-${2}" + fi + + init + + if [[ "$3" == "-a" ]] + then + for lang in ${langs[@]} + do + make_install + done + else + lang=$3 + make_install + fi +} + + +# Create the install file. +# +# requires: $lang, $ext to be set; +# $PWD == / +# +function make_install +{ + pkgname=dict-freedict-${lang}${ext} + + input "${script_dir}/sample.install" + replace "%LANG%" "$lang" + replace "%SUFFIX%" "$ext" + write "${lang}/${pkgname}.install" +} + + +main "$@" diff --git a/make_install.sh b/make_install.sh deleted file mode 100755 index 579586a..0000000 --- a/make_install.sh +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env bash -# -# make_install.sh - script to create the .install files -# -# Copyright 2018 Einhard Leichtfuß -# -# This file is part of aur-fd-scripts -# -# aur-fd-scripts is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# aur-fd-scripts is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with aur-fd-scripts. If not, see . -# - -script_path="$(realpath "$0")" -script_dir="${script_path%/*}" -. "${script_dir}/basic.sh" || exit 1 - - -function main -{ - if [ "$#" -lt 2 ] - then - echo "Usage: $0 (-|-a)" >&2 - exit 1 - elif [ "$#" -gt 2 ] - then - cd "${1}/${2}" || exit 1 - fi - - if [[ "$2" == src ]] - then - ext= - else - ext="-${2}" - fi - - init - - if [[ "$3" == "-a" ]] - then - for lang in ${langs[@]} - do - make_install - done - else - lang=$3 - make_install - fi -} - - -# Create the install file. -# -# requires: $lang, $ext to be set; -# $PWD == / -# -function make_install -{ - pkgname=dict-freedict-${lang}${ext} - - input "${script_dir}/sample.install" - replace "%LANG%" "$lang" - replace "%SUFFIX%" "$ext" - write "${lang}/${pkgname}.install" -} - - -main "$@" diff --git a/update.bash b/update.bash new file mode 100755 index 0000000..324dfa1 --- /dev/null +++ b/update.bash @@ -0,0 +1,211 @@ +#!/usr/bin/env bash +# +# update.bash - script to check for updates and perform them (on the PKGBUILDs) +# +# Copyright 2018,2022 Einhard Leichtfuß +# +# This file is part of aur-fd-scripts +# +# aur-fd-scripts is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# aur-fd-scripts is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with aur-fd-scripts. If not, see . +# + +# usage: $0 dir type [--nopull] [-u xyz-uvw|-ua|-uaf] +# $1 base directory: string +# $2 type: (src|bin|svn) +# $4 option: --nopull {can be omitted} +# ${4,5} update force mode: (-u lang1-lang2|-ua|-uaf) {can be omitted} +# -u x: Update x, even if it appears up to date. +# -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%/*}" + +. "${script_dir}/basic.bash" || exit 1 + + +function main +{ + if [ "$#" -lt 2 ] + then + echo "Usage: $0 [--nopull] [-u -|-ua|-uaf]" >&2 + exit 1 + else + cd "$1" || exit 1 + fi + + type="$2" + + if [ "$3" = "--nopull" ] + then + nopull=true + shift 3 + else + nopull=false + shift 2 + fi + + + init + if [[ "$type" == src ]] + then + handle_all src '' src "$@" + elif [[ "$type" == bin ]] + then + handle_all bin -bin dictd "$@" + elif [[ "$type" == svn ]] + then + handle_all_vcs svn -svn "$@" + else + echo "Type ${type} not supported." >&2 + exit 1 + fi +} + + +# Update PKGBUILD and .SRCINFO +# +# requires: $lang, $ext, $type, $ver, $convver to be set; +# $PWD == // +# +function update +{ + echo "Updating ${lang}${ext} (${pkgver} -> ${convver})..." + + lang_a="${long[${lang%-*}]}" + lang_b="${long[${lang#*-}]}" + + input "${script_dir}/${type}/sample.PKGBUILD" + + replace '%MAINTAINER%' "$maintainer" + replace '%LANG%' "$lang" + replace '%LANG_A%' "$lang_a" + replace '%LANG_B%' "$lang_b" + replace '%VER%' "$convver" + replace '%LICENSES%' "${licenses[$lang]}" + replace '%CHECKSUM%' "$checksum" + + replace_line '%CONTRS%' "${contrs[${lang}${ext}]}" normal + + if [[ "$ver" == "$convver" ]] + then + delete_line '^_pkgver=\$\{pkgver\/\/_\/-\}$' + replace '_pkgver' 'pkgver' + fi + + replace_line '%PREPARE%' "${prepare[${lang}${ext}]}" rm-plus-one + + write PKGBUILD + makepkg --printsrcinfo > .SRCINFO +} + + +# Check for updates for src / bin packages and optionally update them. +# +# $1 type: (src|bin) +# $2 suffix: (|-bin) +# $3 platform: (src|dictd) +# ${@:4} args: $@ +# +# requires: $PWD == +# +function handle_all +{ + type="$1" + ext="$2" + platform="$3" + shift 3 + + curl -sSO https://freedict.org/freedict-database.json || exit 1 + + cd "$type" || exit 1 + + for lang in ${langs[@]} + do + cd $lang || exit 1 + $nopull || git pull -q + 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")" + checksum="$(jq -r '.checksum' <<< "$data")" + convver="${ver//-/_}" + + if [[ "$pkgver" != "$convver" ]] + then + echo "${lang}${ext} requires update (${pkgver} -> ${convver})." + ureq=true + else + ureq=false + fi + + if [[ "$url" != "https://download.freedict.org/dictionaries/${lang}/${ver}/freedict-${lang}-${ver}.${platform}.tar.xz" ]] + then + echo "${lang}${ext} URL changed (${url})." + else + if [[ "$1" == "-u" && "$2" == "$lang" ]] \ + || ([[ "$1" == "-ua" ]] && $ureq) \ + || [[ "$1" == "-uaf" ]] + then + update + fi + fi + + cd .. + done + + cd .. +} + + +# Check for updates for VCS (svn) packages and optionally update them. +# +# $1 type: (svn) +# $2 suffix: (-svn) +# ${@:3} args: $@ +# +# requires: $PWD == +# +function handle_all_vcs +{ + type="$1" + ext="$2" + shift 2 + + cd "$type" || exit 1 + + for lang in "${vcs_langs[@]}" + do + cd $lang || exit 1 + $nopull || git pull -q + pkgver="$(sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p' .SRCINFO)" + makepkg --nobuild --nodeps > /dev/null 2>&1 + ver="$(makepkg --printsrcinfo \ + | sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p')" + convver="$ver" + + if [[ "$1" == "-u" && "$2" == "$lang" ]] || [[ "$1" == "-uaf" ]] + then + update + fi + + cd .. + done + + cd .. +} + + +main "$@" diff --git a/update.sh b/update.sh deleted file mode 100755 index f011164..0000000 --- a/update.sh +++ /dev/null @@ -1,211 +0,0 @@ -#!/usr/bin/env bash -# -# update.sh - script to check for updates and perform them (on the PKGBUILDs) -# -# Copyright 2018,2022 Einhard Leichtfuß -# -# This file is part of aur-fd-scripts -# -# aur-fd-scripts is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published -# by the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# aur-fd-scripts is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with aur-fd-scripts. If not, see . -# - -# usage: $0 dir type [--nopull] [-u xyz-uvw|-ua|-uaf] -# $1 base directory: string -# $2 type: (src|bin|svn) -# $4 option: --nopull {can be omitted} -# ${4,5} update force mode: (-u lang1-lang2|-ua|-uaf) {can be omitted} -# -u x: Update x, even if it appears up to date. -# -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%/*}" - -. "${script_dir}/basic.sh" || exit 1 - - -function main -{ - if [ "$#" -lt 2 ] - then - echo "Usage: $0 [--nopull] [-u -|-ua|-uaf]" >&2 - exit 1 - else - cd "$1" || exit 1 - fi - - type="$2" - - if [ "$3" = "--nopull" ] - then - nopull=true - shift 3 - else - nopull=false - shift 2 - fi - - - init - if [[ "$type" == src ]] - then - handle_all src '' src "$@" - elif [[ "$type" == bin ]] - then - handle_all bin -bin dictd "$@" - elif [[ "$type" == svn ]] - then - handle_all_vcs svn -svn "$@" - else - echo "Type ${type} not supported." >&2 - exit 1 - fi -} - - -# Update PKGBUILD and .SRCINFO -# -# requires: $lang, $ext, $type, $ver, $convver to be set; -# $PWD == // -# -function update -{ - echo "Updating ${lang}${ext} (${pkgver} -> ${convver})..." - - lang_a="${long[${lang%-*}]}" - lang_b="${long[${lang#*-}]}" - - input "${script_dir}/${type}/sample.PKGBUILD" - - replace '%MAINTAINER%' "$maintainer" - replace '%LANG%' "$lang" - replace '%LANG_A%' "$lang_a" - replace '%LANG_B%' "$lang_b" - replace '%VER%' "$convver" - replace '%LICENSES%' "${licenses[$lang]}" - replace '%CHECKSUM%' "$checksum" - - replace_line '%CONTRS%' "${contrs[${lang}${ext}]}" normal - - if [[ "$ver" == "$convver" ]] - then - delete_line '^_pkgver=\$\{pkgver\/\/_\/-\}$' - replace '_pkgver' 'pkgver' - fi - - replace_line '%PREPARE%' "${prepare[${lang}${ext}]}" rm-plus-one - - write PKGBUILD - makepkg --printsrcinfo > .SRCINFO -} - - -# Check for updates for src / bin packages and optionally update them. -# -# $1 type: (src|bin) -# $2 suffix: (|-bin) -# $3 platform: (src|dictd) -# ${@:4} args: $@ -# -# requires: $PWD == -# -function handle_all -{ - type="$1" - ext="$2" - platform="$3" - shift 3 - - curl -sSO https://freedict.org/freedict-database.json || exit 1 - - cd "$type" || exit 1 - - for lang in ${langs[@]} - do - cd $lang || exit 1 - $nopull || git pull -q - 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")" - checksum="$(jq -r '.checksum' <<< "$data")" - convver="${ver//-/_}" - - if [[ "$pkgver" != "$convver" ]] - then - echo "${lang}${ext} requires update (${pkgver} -> ${convver})." - ureq=true - else - ureq=false - fi - - if [[ "$url" != "https://download.freedict.org/dictionaries/${lang}/${ver}/freedict-${lang}-${ver}.${platform}.tar.xz" ]] - then - echo "${lang}${ext} URL changed (${url})." - else - if [[ "$1" == "-u" && "$2" == "$lang" ]] \ - || ([[ "$1" == "-ua" ]] && $ureq) \ - || [[ "$1" == "-uaf" ]] - then - update - fi - fi - - cd .. - done - - cd .. -} - - -# Check for updates for VCS (svn) packages and optionally update them. -# -# $1 type: (svn) -# $2 suffix: (-svn) -# ${@:3} args: $@ -# -# requires: $PWD == -# -function handle_all_vcs -{ - type="$1" - ext="$2" - shift 2 - - cd "$type" || exit 1 - - for lang in "${vcs_langs[@]}" - do - cd $lang || exit 1 - $nopull || git pull -q - pkgver="$(sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p' .SRCINFO)" - makepkg --nobuild --nodeps > /dev/null 2>&1 - ver="$(makepkg --printsrcinfo \ - | sed -En 's/\s*pkgver\s*=\s*(.+)\s*/\1/p')" - convver="$ver" - - if [[ "$1" == "-u" && "$2" == "$lang" ]] || [[ "$1" == "-uaf" ]] - then - update - fi - - cd .. - done - - cd .. -} - - -main "$@" diff --git a/user-config.default.bash b/user-config.default.bash new file mode 100644 index 0000000..a2e0eca --- /dev/null +++ b/user-config.default.bash @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# +# user-config.default.bash - user configuration options; +# copy this file to user-config.bash and modify to +# your liking. +# + +# The maintainer to be listed in the PKGBUILD. +maintainer="Your Name " diff --git a/user-config.default.sh b/user-config.default.sh deleted file mode 100644 index 4675afb..0000000 --- a/user-config.default.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash -# -# user-config.default.sh - user configuration options; -# copy this file to user-config.sh and modify to -# your liking. -# - -# The maintainer to be listed in the PKGBUILD. -maintainer="Your Name " -- cgit v1.2.3