aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEinhard Leichtfuß <alguien@respiranto.de>2018-03-30 22:08:42 +0200
committerEinhard Leichtfuß <alguien@respiranto.de>2018-03-30 22:08:42 +0200
commit2a7eb7221b85af3f2c5141c3918ff1959566f55a (patch)
treefd6725c155ab0e8ef8e6ef7383d1ab2d66ca359c
parent9d45fe6b329cbae295ed83d90dd20c5fc3e70717 (diff)
Split some functionality off update.sh
Such that it may be used by the to be bettered make_install.sh. In particular, the latter is supposed to work for both non-vcs source and binary packages. Also add a main() method to update.sh.
-rw-r--r--basic.sh49
-rwxr-xr-xmake_install.sh (renamed from src/make_install.sh)0
-rw-r--r--sample.install (renamed from src/sample.install)2
-rwxr-xr-xupdate.sh48
4 files changed, 58 insertions, 41 deletions
diff --git a/basic.sh b/basic.sh
new file mode 100644
index 0000000..65b44e5
--- /dev/null
+++ b/basic.sh
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+function init
+{
+ tmp_d="$(mktemp -d)"
+ tmp="$tmp_d/a"
+ tmp_="$tmp_d/b"
+}
+
+function cleanup
+{
+ rm -r "$tmp_d"
+}
+trap cleanup EXIT
+
+# $1: string to replace: regular expression
+# $2: string to replace with: sed replacement string
+function replace
+{
+ sed -i "s/${1}/${2}/g" "$tmp"
+}
+
+# $1 line to replace: regular expression
+# $2 text to replace with: (newline terminated) sed replacement string
+# $3 removal type: (rm-plus-one|normal)
+function replace_line
+{
+ if test -n "$2"
+ then
+ cat <(sed "/${1}/,\$ d" < "$tmp") \
+ <(echo -n "$2") \
+ <(sed "0,/${1}/ d" < "$tmp") \
+ > "$tmp_"
+ mv "$tmp_" "$tmp"
+ else
+ if [[ "$3" == rm-plus-one ]]
+ then
+ sed -i "/${1}/,+1 d" "$tmp"
+ else
+ sed -i "/${1}/ d" "$tmp"
+ fi
+ fi
+}
+
+# $1 line to delete: regular expression
+function delete_line
+{
+ sed -i "/${1}/ d" "$tmp"
+}
diff --git a/src/make_install.sh b/make_install.sh
index a24837f..a24837f 100755
--- a/src/make_install.sh
+++ b/make_install.sh
diff --git a/src/sample.install b/sample.install
index 882fbf5..7ce3ba2 100644
--- a/src/sample.install
+++ b/sample.install
@@ -1,5 +1,5 @@
basename=%LANG%
-pkgname=dict-freedict-$basename
+pkgname=dict-freedict-$basename%SUFFIX%
dictd_conf=/etc/dict/dictd.conf
datadir=/usr/share/dictd
conf="database $basename {
diff --git a/update.sh b/update.sh
index a3d3863..c36b556 100755
--- a/update.sh
+++ b/update.sh
@@ -46,39 +46,16 @@ prepare[deu-fra-bin]=\
}
'
-# $1: string to replace: regular expression
-# $2: string to replace with: sed replacement string
-function replace
-{
- sed -i "s/${1}/${2}/g" "$tmp"
-}
+. basic.sh
-# $1 line to replace: regular expression
-# $2 text to replace with: (newline terminated) sed replacement string
-# $3 removal type: (rm-plus-one|normal)
-function replace_line
+function main
{
- if test -n "$2"
- then
- cat <(sed "/${1}/,\$ d" < "$tmp") \
- <(echo -n "$2") \
- <(sed "0,/${1}/ d" < "$tmp") \
- > "$tmp_"
- mv "$tmp_" "$tmp"
- else
- if [[ "$3" == rm-plus-one ]]
- then
- sed -i "/${1}/,+1 d" "$tmp"
- else
- sed -i "/${1}/ d" "$tmp"
- fi
- fi
-}
+ curl -sO http://freedict.org/freedict-database.json
-# $1 line to delete: regular expression
-function delete_line
-{
- sed -i "/${1}/ d" "$tmp"
+ init
+ handle_all src '' src "$@"
+ handle_all bin -bin dictd "$@"
+ cleanup
}
function update
@@ -90,10 +67,6 @@ function update
checksum="$(wget -qO - "$url" | sha512sum | sed -E 's/\s*-$//')"
- tmp_d="$(mktemp -d)"
- tmp="$tmp_d/a"
- tmp_="$tmp_d/b"
-
cp ../sample.PKGBUILD "$tmp"
replace '%LANG%' "$lang"
@@ -114,8 +87,6 @@ function update
mv "$tmp" PKGBUILD
makepkg --printsrcinfo > .SRCINFO
-
- rm -r "$tmp_d"
}
# $1 type: (src|bin)
@@ -168,7 +139,4 @@ function handle_all
}
-curl -sO http://freedict.org/freedict-database.json
-
-handle_all src '' src "$@"
-handle_all bin -bin dictd "$@"
+main "$@"