aboutsummaryrefslogtreecommitdiff
path: root/basic.sh
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 /basic.sh
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.
Diffstat (limited to 'basic.sh')
-rw-r--r--basic.sh49
1 files changed, 49 insertions, 0 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"
+}