Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | daniel-mar | 1 | #!/bin/bash |
2 | |||
3 | # Get the directory of this script (also works with symlinks) |
||
4 | # http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in |
||
5 | SOURCE="${BASH_SOURCE[0]}" |
||
6 | while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink |
||
7 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
||
8 | SOURCE="$(readlink "$SOURCE")" |
||
9 | [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located |
||
10 | done |
||
11 | DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" |
||
12 | |||
13 | # Check MySQL config |
||
14 | "$DIR"/check_db_conn -q |
||
15 | if [ $? -ne 0 ]; then |
||
16 | # TODO: fragen ob man write_stam_config aufrufen möchte |
||
17 | exit 1 |
||
18 | fi |
||
19 | |||
20 | echo_yellow() { |
||
21 | echo -ne "\033[1;33;40m" |
||
22 | echo "$*" |
||
23 | echo -ne "\033[0m" |
||
24 | } |
||
25 | |||
26 | echo_red() { |
||
27 | echo -ne "\033[1;31;40m" |
||
28 | echo "$*" |
||
29 | echo -ne "\033[0m" |
||
30 | } |
||
31 | |||
32 | #categ="$1" |
||
33 | categ=$( echo $@ ) |
||
34 | if [[ "$categ" == "" ]]; then |
||
35 | echo "Syntax: $0 <entry>" 1>&2 |
||
36 | exit 2 |
||
37 | fi |
||
38 | |||
39 | # Do not allow empty category (reserved for '*') |
||
40 | if [[ "$categ" == "" ]]; then |
||
41 | echo_red "[!] FATAL ERROR: Category cannot be empty!" |
||
42 | exit 1 |
||
43 | fi |
||
44 | |||
45 | # Warning if it does not exist yet. |
||
46 | "$DIR"/exists1 "$categ" |
||
47 | if [ $? -eq 1 ]; then |
||
48 | echo_yellow "(i) Note: The category does not exist and will be created if you continue:" |
||
49 | echo_yellow " $categ" |
||
50 | SIGN="*" |
||
51 | else |
||
52 | SIGN="+" |
||
53 | fi |
||
54 | |||
55 | while (( 1 )); do |
||
56 | # "-r" übernimmt alle "\". gut für z.B. "\\netbios\", schlecht für "\" am zeilenende, um weiterzuschreiben |
||
57 | read -erp "<$categ> $SIGN " entry |
||
58 | if [[ $? -gt 0 ]]; then |
||
59 | # For example end of stream -- exit |
||
60 | break |
||
61 | fi |
||
62 | |||
63 | # Keine leeren Zeilen (ist das OK?) |
||
64 | if [[ "$entry" == "" ]]; then |
||
65 | continue |
||
66 | fi |
||
67 | |||
68 | # Eintrag hinzufügen |
||
69 | "$DIR"/aps "$categ" "$entry" |
||
70 | if [ $? -ne 0 ]; then |
||
71 | echo_red "[!] FATAL ERROR: Could not append the entry!" 1>&2 |
||
72 | else |
||
73 | SIGN="+" |
||
74 | fi |
||
75 | done |