summaryrefslogtreecommitdiffstats
path: root/god/licht
blob: 12e4555fd4b0d0d514677fedcfdd746d31585702 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
#
#SYNOPSIS
#   //god/licht [options] [0/1]
#OPTIONS
#   all         -    toggles all lights
#   links       -    toggles all lights on the left hand side while looking towards the Auditorium
#   rechts      -    toggles all lights on the right hand side while looking towards the Auditorium
#   kuschel     -    toggles the lights in the pwnie corner
#   software    -    toggles the software corner
#   tische      -    toggles the lights on the window side of the long table
#   porsche     -    toggles the lights on the window side where the porsche cockpit is
#   ghetto      -    toggles the lights in the hallway
#   0-7         -    toggles individual lights

TOGGLE=`echo "$2" | sed -n '/^[0-1]/p'` 
shorthelp() {
      echo  "Usage: $0 [OPTIONS] [0|1]"
      echo  "Toggle the lights in the shack."

}
longhelp(){
  shorthelp

cat <<EOF

OPTIONS
   all         -    toggles all lights
   links       -    toggles all lights on the left hand side while looking towards the Auditorium
   rechts      -    toggles all lights on the right hand side while looking towards the Auditorium
   kuschel     -    toggles the lights in the pwnie corner
   software    -    toggles the software corner
   tische      -    toggles the lights on the window side of the long table
   porsche     -    toggles the lights on the window side where the porsche cockpit is
   ghetto      -    toggles the lights in the hallway
   0-7         -    toggles individual lights
EOF
}
toggle() {
  LAMPE=`echo "$1" | sed -n '/^[1-2]*[0-9]*[0-9]$/p' | xargs echo "obase=16;" | bc` 
  if ! [ "$LAMPE" -a "$TOGGLE" ];then
    longhelp
    exit 1
  fi
  STRING="\\xA5\\x5A\\x$LAMPE\\x$TOGGLE"
  if [ $# != 2 ]
  then
    longhelp
    exit 1
  else
    echo "Toggle light $LAMPE ($TOGGLE)" 
     printf "$STRING" | nc -u -w1 licht.shack 1337
  fi
}

toggle_all() {
    for i in `seq 0 7`
    do
        toggle $i $TOGGLE
    done
    wait
}

kuschel(){
    for i in 0 2
    do
        toggle $i $TOGGLE
    done
    wait
}

software(){
    for i in 1 3
    do
        toggle $i $TOGGLE
    done
    wait
}

tische(){
    for i in 4 6 
    do
        toggle $i $TOGGLE
    done
    wait
}

ghetto(){
    i=7
    toggle $i $TOGGLE
}

porsche(){
    i=5
    toggle $i $TOGGLE
}

case "$1" in
  (--help) 
    if [ "$2" == "--verbose" ]
    then longhelp
    else shorthelp
    fi
      ;;
  all) 
      toggle_all
      ;;
  kuschel)
      kuschel
      ;;
  software)
      software
      ;;
  links)
      kuschel
      software
      ;;
  rechts)
      tische
      porsche
      ghetto
      ;;
  tische)
      tische
      ;;
  porsche)
      porsche
      ;;
  ghetto)
      ghetto
      ;;
  *)
      toggle "$@"
      ;;
esac