Browse Source

Reorganised bash script

Brendan Abolivier 8 years ago
parent
commit
a3e6daa325
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
1 changed files with 15 additions and 17 deletions
  1. 15
    17
      welcomehome

+ 15
- 17
welcomehome View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
-
4
 ##### FUNCTIONS #####
3
 ##### FUNCTIONS #####
5
 
4
 
6
 log() {
5
 log() {
9
     echo "[$date]" $1
8
     echo "[$date]" $1
10
 }
9
 }
11
 
10
 
11
+parse_arg() {
12
+    # Echoes the value of a given parameter in a given configuration file
13
+    value=$(cat $1 | grep -E "^$2" | cut -d"=" -f2)
14
+    value=$(echo $value | sed "s,^\s+,,")
15
+    echo $value
16
+}
17
+
18
+check_url() {
19
+    # Check if URL is starting with "http(s)://"
20
+    # Returns the same code as grep, which is 1 if incorrect,
21
+    # 0 if correct
22
+    echo $1 | grep -E "https?\://"
23
+    return $?
24
+}
25
+
12
 play_stream() {
26
 play_stream() {
13
     # Reset playback state
27
     # Reset playback state
14
     curl -s -d '{"jsonrpc": "2.0", "id": 1, "method": "core.playback.stop"}' http://localhost:6680/mopidy/rpc > /dev/null
28
     curl -s -d '{"jsonrpc": "2.0", "id": 1, "method": "core.playback.stop"}' http://localhost:6680/mopidy/rpc > /dev/null
33
     log "Stream stopped"
47
     log "Stream stopped"
34
 }
48
 }
35
 
49
 
36
-parse_arg() {
37
-    # Echoes the value of a given parameter in a given configuration file
38
-    value=$(cat $1 | grep -E "^$2" | cut -d"=" -f2)
39
-    value=$(echo $value | sed "s,^\s+,,")
40
-    echo $value
41
-}
42
-
43
-check_url() {
44
-    # Check if URL is starting with "http(s)://"
45
-    # Returns the same code as grep, which is 1 if incorrect,
46
-    # 0 if correct
47
-    echo $1 | grep -E "https?\://"
48
-    return $?
49
-}
50
-
51
-
52
 ##### PROGRAM #####
50
 ##### PROGRAM #####
53
 
51
 
54
 if [[ $# -eq 0 || ! -f $1 ]]; then
52
 if [[ $# -eq 0 || ! -f $1 ]]; then