Skip to content

Commit 2a2e7e5

Browse files
committed
Shellcheck
1 parent ad03309 commit 2a2e7e5

13 files changed

+79
-55
lines changed

src/lifecap

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
HELP="Usage: lifecap [command]
44
55
lifecap captures a stream of events about your life, to feed into summarization
66
and aggregation systems. The idea is that we use collectors to gather data,
77
which publish events to topics that other collectors might be interested in.
88
"
9-
. $(dirname $0)/lifecap_lib.sh
9+
. "$(dirname "$0")"/lifecap_lib.sh
1010

11+
echo "$HELP"
1112

src/lifecap-collector

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
HELP="Lifecap collectors
44
@@ -8,5 +8,7 @@ below by adding programs with lifecap-collector-name* to your path.
88
See --help on the collectors themselves for configuration and use.
99
"
1010

11-
. $(dirname $0)/lifecap_lib.sh
11+
. "$(dirname "$0")"/lifecap_lib.sh
12+
13+
echo "$HELP"
1214

src/lifecap-config

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
HELP="Usage: lifecap config [command]
44
55
Lists the config"
66

7-
. $(dirname $0)/lifecap_lib.sh
7+
. "$(dirname "$0")"/lifecap_lib.sh
88

9-
echo config_dir: $config_dir
10-
echo cache_dir: $cache_dir
11-
echo data_dir: $data_dir
9+
echo config_dir: "$config_dir"
10+
echo cache_dir: "$cache_dir"
11+
echo data_dir: "$data_dir"
1212

src/lifecap-job

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
HELP="Usage: lifecap job [command]
44
55
Commands to do with data collection jobs."
66

7-
. $(dirname $0)/lifecap_lib.sh
7+
. "$(dirname "$0")"/lifecap_lib.sh
88

99
echo "$HELP"
1010

src/lifecap-job-add

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,28 @@ HELP="Usage: lifecap job add <name> <collector_name> [collector options]
55
Adds a data collection job.
66
"
77

8-
. $(dirname $0)/lifecap_lib.sh
8+
. "$(dirname "$0")"/lifecap_lib.sh
99

1010
name="$1"
1111
collector="$2"
12-
shift 2
1312

1413
if [ -z "$name" ] || [ -z "$collector" ]; then
1514
echo "$HELP" >&2
1615
exit 1
1716
fi
1817

19-
job_dir="$data_dir/jobs/$name"
18+
shift 2
19+
20+
job_dir="$config_dir/jobs/$name"
2021

21-
safe_path "$data_dir/jobs" "$name"
22+
safe_path "$job_dir"
2223

2324
if [ -e "$job_dir" ]; then
2425
echo "Job '$name' already exists" >&2
2526
exit 1
2627
fi
2728

28-
if [ -z "$(lifecap collector options | grep "$collector")" ]; then
29+
if ! "$(lifecap collector options | grep -q "$collector")"; then
2930
echo "Collector '$collector' doesn't exist" >&2
3031
echo "Options: $(lifecap collector options)" >&2
3132
exit 1
@@ -37,6 +38,7 @@ mkdir -p "$job_dir"
3738
# Configure the collector
3839
if ! lifecap collector "$collector" setup "$job_dir" "$@"; then
3940
echo "Job creation failed." >&2
40-
rm -r $job_dir
41+
rm -r "$job_dir"
42+
exit 1
4143
fi
4244

src/lifecap-job-ls

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
HELP="Usage: lifecap collector ls
44
55
Lists currently installed collectors"
66

7-
. $(dirname $0)/lifecap_lib.sh
7+
. "$(dirname "$0")"/lifecap_lib.sh
88

9-
ls -1 $config_dir/collectors
9+
ls -1 "$config_dir/collectors"

src/lifecap-job-rm

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

3-
HELP="Usage: lifecap collector ls
3+
HELP="Usage: lifecap job rm <name>
44
55
Lists currently installed collectors"
66

7-
. $(dirname $0)/lifecap_lib.sh
7+
. "$(dirname "$0")"/lifecap_lib.sh
88

9-
set -e
9+
if [ -z "$1" ]; then
10+
echo "No such job"
11+
echo "Jobs: $(ls "$config_dir"/collectors)"
12+
fi
13+
14+
path="$config_dir/collectors/$1"
15+
16+
path_exists "$path"
17+
18+
rm "$path"
1019

11-
rm "$config_dir/collectors/$1"

src/lifecap-topic

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ HELP="Usage: lifecap topic [command]
44
55
Topics are channels where data flows."
66

7-
. $(dirname $0)/lifecap_lib.sh
7+
. "$(dirname "$0")"/lifecap_lib.sh
88

9-
echo $HELP >&2
9+
echo "$HELP" >&2
1010
exit 1

src/lifecap-topic-ls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
HELP="Usage: lifecap topic ls [pattern]
44
55
List existing topics"
66

7-
. $(dirname $0)/lifecap_lib.sh
7+
. "$(dirname "$0")"/lifecap_lib.sh
88

99
ls -1 "$data_dir/topics/$1"
1010

src/lifecap-topic-rm

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,10 @@ HELP="Usage: lifecap topic rm <name>
44
55
Remove a topic by name"
66

7-
. $(dirname $0)/lifecap_lib.sh
7+
. "$(dirname "$0")"/lifecap_lib.sh
88

9-
# Reject wildcards/globs
10-
case "$1" in
11-
*[\*\?]* )
12-
echo "Wildcards not allowed!"
13-
exit 1
14-
;;
15-
*\.\.* )
16-
echo "No traversal, thanks."
17-
exit 1
18-
;;
19-
esac
9+
path="$data_dir/topics/$1"
10+
path_exists "$path"
2011

21-
# Resolve full path and ensure it’s under
22-
path=$data_dir/topics/$1
23-
real_path=$(cd "$(dirname "$path")" && pwd -P)/$(basename "$path")
24-
[ ! "$real_path" = "$path" ] && echo "Invalid path!" && exit 1
25-
26-
rm -r $path
12+
rm -r "$path"
2713

0 commit comments

Comments
 (0)