Changes for live system
authorCameron Ball <c.ball1729@gmail.com>
Wed, 8 Jul 2015 00:20:50 +0000 (08:20 +0800)
committerCameron Ball <c.ball1729@gmail.com>
Wed, 8 Jul 2015 00:20:50 +0000 (08:20 +0800)
13 files changed:
.xinitrc [new file with mode: 0644]
TODO [new file with mode: 0644]
camflush-adapter.sh [new file with mode: 0755]
dialog
dialogrc
menu.json
menu.sh
rsync-adapter.sh
simlink-adapter.sh
steam.sh [new file with mode: 0755]
stream.sh [new file with mode: 0755]
stream_parameters.txt
test.sh [new file with mode: 0755]

diff --git a/.xinitrc b/.xinitrc
new file mode 100644 (file)
index 0000000..9c4893e
--- /dev/null
+++ b/.xinitrc
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+export DISPLAY=:0.0
+
+/usr/bin/urxvt -pixmap /itg/launchbg.jpg \
+              -foreground White \
+              -bl \
+              -borderColor Black \
+              -color4 RoyalBlue \
+              -color12 RoyalBlue \
+              +sb \
+              -geometry 102x34+0+0 \
+              -e /itg/PreCom/start.sh
+
+pid=$!
+
+wait $pid
diff --git a/TODO b/TODO
new file mode 100644 (file)
index 0000000..3f4cba5
--- /dev/null
+++ b/TODO
@@ -0,0 +1,5 @@
+Streaming to peekingboo etc is a TASK not a service,
+
+remove the psexec stuff from stream.sh to a new script that just calls psexec (might not even need a script, just do it as the task)
+
+Need some way of adding delays between commands for presets 
diff --git a/camflush-adapter.sh b/camflush-adapter.sh
new file mode 100755 (executable)
index 0000000..686b4b2
--- /dev/null
@@ -0,0 +1,14 @@
+#!/bin/bash
+#
+# widget:      msgbox
+# description: Flushed the camera then says cool.
+
+v4l2-ctl -d /dev/video0 -c focus_auto=0 -c focus_absolute=0 -c exposure_auto_priority=3 -c exposure_auto=3>/dev/null 2>&1 &
+
+sleep 6
+
+v4l2-ctl -d /dev/video0 -c exposure_auto=1 -c exposure_absolute=500>/dev/null 2>&1 &
+
+sleep 2
+
+echo "Camera flushed"
diff --git a/dialog b/dialog
index b67e260..0488fdf 100755 (executable)
Binary files a/dialog and b/dialog differ
index 2434190..3c0883a 100644 (file)
--- a/dialogrc
+++ b/dialogrc
@@ -1,4 +1,4 @@
 
-bindkey * \w ITEM_PREV
-bindkey * \e ITEM_NEXT
-bindkey * \r ENTER
+bindkey * \y ITEM_PREV
+bindkey * \u ITEM_NEXT
+bindkey * \d ENTER
index a2ce116..171b1ba 100644 (file)
--- a/menu.json
+++ b/menu.json
             "name": "ITG",
             "type": "service",
             "description": "Start/Stop the ITG service",
-            "command": "/home/cameron/Games/OpenITG/openitg-beta-2",
+            "command": "/itg/de-itg",
             "user": "itg"
         },
-        {
-          "name":"gEdit",
-            "type": "service",
-            "description": "Start/Stop the gEdit service",
-            "command": "/usr/bin/gedit",
-            "user": "itg"
-        },
-        {
-          "name":"xterm",
-            "type": "service",
-            "description": "Start/Stop the xterm service",
-            "command": "/usr/bin/xterm",
-            "user": "itg"
-        }]
+       {
+           "name": "Steam",
+           "type": "service",
+           "description": "Start/Stop the Steam service",
+           "command": "/itg/PreCom/steam.sh",
+           "user": "steam"
+       },
+       {
+           "name": "Steam TenFoot",
+           "type": "service",
+           "description": "Start/Stop the Steam service in tenfoot mode",
+           "command": "/itg/PreCom/steam.sh",
+           "args": "-t",
+           "user": "steam"
+       },
+       {
+           "name": "Stream",
+           "type": "service",
+           "description": "Start/Stop the stream service",
+           "command": "/itg/PreCom/stream.sh",
+           "user": "itg"
+       }]
     },
     { 
         "name": "Tasks",
             "description": "Update the ITG song list",
             "commands": [
             {
-                "command": "./rsync-adapter.sh -ia --delete --exclude 'A is for Cool Shit' /home/cameron/PreComTestRepo/Songs /home/cameron/Games/OpenITG",
+                "command": "./rsync-adapter.sh -ia --delete --exclude 'A is for Cool Shit' --exclude 'Footspeed' --exclude 'Stamina' /mnt/shares/itg-repo/Songs /itg",
                 "title": "Syncing songs..."
             },
            {
-               "command": "./simlink-adapter.sh -d /home/cameron/Games/OpenITG/Songs/ -f 240 -s 5 -r 13",
+               "command": "./simlink-adapter.sh -d /itg/Songs/ -f 240 -s 5 -r 13",
                "title": "Sorting songs..."
            },
             {
                 "title": "Songs updated"
             }],
             "user": "itg"
-        }]
+        },
+       {
+           "name": "DivinElegy Twitch",
+           "type": "task",
+           "description": "Sets up the camera and launches OBS",
+           "commands": [
+           {
+               "command": "./camflush-adapter.sh",
+               "title": "Flush camera"
+           },
+           {
+               "command": "ssh peekingboo@...",
+               "title": "Starting obs"
+           }],
+           "user": "itg"
+       }]
     },
     {
         "name": "Presets",
             "description": "Sync songs and launch ITG",
             "itemsToRun": [
               "MainMenu.Tasks.Update songs",
-              "MainMenu.Services.xterm"
+              "MainMenu.Services.ITG"
             ]
-        }]
+        },
+       {
+           "name": "GameStomp",
+           "type": "preset",
+           "description": "Do shit for GameStomp",
+           "itemsToRun": [
+             "MainMenu.Services.Steam",
+             "MainMenu.tasks.Divinelegy Twitch"
+           ]
+       }]
     }]
   }
 }
diff --git a/menu.sh b/menu.sh
index 172ff1c..6337df3 100755 (executable)
--- a/menu.sh
+++ b/menu.sh
@@ -3,21 +3,22 @@
 #TODO: There are probably instances where I should be quoting variables but am not.
 #Basically, if there is any chance that an argument will have a space in it, it should
 #be quoted when used.
-
+export DIALOGRC=/itg/PreCom/dialogrc
+export DISPLAY=:0.0
 INPUT=/tmp/menu.sh.$$
 OUTPUT=/tmp/output.sh.$$
 
 touch $INPUT
 touch $OUTPUT
 
-trap "rm $OUTPUT; rm $INPUT; rm /run/precom-*; exit" SIGHUP SIGINT SIGTERM
+trap "rm $OUTPUT; rm $INPUT; rm /run/precom-*; service xorg stop; exit" SIGHUP SIGINT SIGTERM
 
 menu_json="$(./JSON.sh -l < menu.json)"
 current_item="MainMenu"
 backtitle="DivinElegy PreCom"
 box_width=70
 box_height=30
-dialog_bin="/usr/bin/dialog"
+dialog_bin="/itg/PreCom/dialog"
 
 while getopts ":d:" opt; do
   case $opt in
@@ -216,12 +217,13 @@ function render_menu()
 
 function toggle_service()
 {
-       service_command=$(get_item_key $1 command)
-       service_name=$(basename $service_command)
+       service_command=$(get_item_key "$1" command)
+       service_command_array=($service_command)
+       service_name=$(basename ${service_command_array[0]})
+       service_args=$(get_item_key "$1" args)
        nice_service_name=$(echo $service_name | tr '[:upper:]' '[:lower:]')
-       local user=$(get_item_key $1 user)
+       local user=$(get_item_key "$1" user)
        confirm=0
-
        #If the quotes aren't here then the application launches
        #Not sure why
        pid="$(pgrep $service_name)"
@@ -235,8 +237,18 @@ function toggle_service()
        fi
 
        if [[ $confirm == 0 ]]; then
-               start-stop-daemon --start --user "$user" --name "$nice_service_name" --chuid "$user" --background --pidfile "/var/run/precom-${nice_service_name}.pid" --make-pidfile --startas $service_command > /dev/null
-               [[ $? == 1 ]] && start-stop-daemon --stop --user "$user" --name "$nice_service_name" --pidfile "/var/run/precom-${nice_service_name}.pid"
+#        debug "start-stop-daemon --start --user \"$user\" --name \"$nice_service_name\" --chuid \"$user\" --background --pidfile \"/var/run/precom-${nice_service_name}.pid\" --make-pidfile --startas \"$service_command\" -- \"$service_args\""  #> /dev/null
+               start-stop-daemon --start --user "$user" --name "$nice_service_name" --chuid "$user" --background --pidfile "/var/run/precom-${nice_service_name}.pid" --make-pidfile --startas "$service_command" -- $service_args #> /dev/null
+               if [[ $? == 1 ]]; then
+                       #XXX: If we start a script with start-stop-daemon and it spawns child processes, start-stop-daemon doesn't kill them
+                       #pkill kills the child processes and then start-stop-daemon stops the daemon
+                       #probably bash scripts should kill their own children when they receive the kill signal but I can't work out how
+                       #to do that.
+                       pid=$(cat /var/run/precom-${nice_service_name}.pid)
+                       pkill -TERM -P "$pid"
+                       start-stop-daemon --stop --user "$user" --name "$nice_service_name" --pidfile "/var/run/precom-${nice_service_name}.pid"
+                       rm "/var/run/precom-${nice_service_name}.pid"
+               fi
        fi
 
        #Kind of a hack? When we get here current_item will be:
@@ -321,3 +333,5 @@ clear
 
 [[ -f $OUTPUT ]] && rm $OUTPUT
 [[ -f $INPUT ]] && rm $INPUT
+
+service xorg stop
index c4d2d59..ce93747 100755 (executable)
@@ -5,5 +5,5 @@
 #              with dialog's --progress option
 
 #XXX: Some versions of rsync say to-chk instead of to-check, be careful
-rsync --progress "$@" | tee >(grep -v "*deleting" | grep -i ".sm" > /tmp/newsongs.txt) | mawk -Winteractive '{ if (index($0, "to-chk=") > 0) { split($0, pieces, "to-chk="); split(pieces[2], term, ")"); split(term[1], division, "/"); print (1-(division[1]/division[2]))*100 } }' \
-                     | sed --unbuffered 's/\([0-9]*\).*/\1/'
+rsync --progress "$@" #| tee >(grep -v "*deleting" | grep -i ".sm" > /tmp/newsongs.txt) | mawk -Winteractive '{ if (index($0, "to-check=") > 0) { split($0, pieces, "to-check="); split(pieces[2], term, ")"); split(term[1], division, "/"); print (1-(division[1]/division[2]))*100 } }' \
+                     #| sed --unbuffered 's/\([0-9]*\).*/\1/'
index 4322cfe..1afd791 100755 (executable)
@@ -117,6 +117,9 @@ function difficulty()
        echo "$max300"
 }
 
+rm -rf "${songs_dir}/Footspeed"
+rm -rf "${songs_dir}/Stamina"
+
 mkdir -p "${songs_dir}/Footspeed"
 mkdir -p "${songs_dir}/Stamina"
 
@@ -137,6 +140,5 @@ do
        fi
 
         ((num_processed++))
-
         printf '%i %i' $num_processed $total_charts | mawk -Winteractive '{ pc=100*$1/$2; i=int(pc); print (pc-i<0.5)?i:i+1 }'
 done
diff --git a/steam.sh b/steam.sh
new file mode 100755 (executable)
index 0000000..bc95535
--- /dev/null
+++ b/steam.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+export DISPLAY=:0.0
+
+tenfoot=false
+
+while getopts "t" opt; do
+  case $opt in
+    t)
+      tenfoot=true
+      ;;
+    \?)
+      echo "Invalid option: -$OPTARG" >&2
+      exit 1
+      ;;
+  esac
+done
+
+
+if [ $tenfoot = true ] ; then
+    steam-debian -480p -tenfoot > /dev/null 2>&1
+else
+    steam-debian > /dev/null 2>&1
+fi
diff --git a/stream.sh b/stream.sh
new file mode 100755 (executable)
index 0000000..a5e2ba5
--- /dev/null
+++ b/stream.sh
@@ -0,0 +1,74 @@
+#!/bin/bash
+
+while getopts "p:s:" opt; do
+echo "$opt" >> /tmp/someopts
+echo "$OPTARG" >> /tmp/someopts
+  case $opt in
+    p)
+      obs_profile="$OPTARG"
+      ;;
+    s)
+      obs_scene="$OPTARG"
+      ;;
+    \?)
+      echo "Invalid option: -$OPTARG" >&2
+      exit 1
+      ;;
+    :)
+      echo "Option -$OPTARG requires an argument." >&2
+      exit 1
+      ;;
+  esac
+done
+key_re="([a-zA-Z0-9_]+?)[[:space:]]*="
+value_re="=[[:space:]]*(.+?)"
+
+while IFS='' read -r line || [[ -n $line ]]; do
+       [[ "$line" =~ $key_re ]] && key=${BASH_REMATCH[1]}
+       [[ "$line" =~ $value_re ]] && value=${BASH_REMATCH[1]}
+
+       if [[ ! -z "$key" ]] && [[ ! "${key}xxx" = "xxx" ]] && [[ ! -z "$value"  ]] && [[ ! "${value}xxx" = "xxx" ]]; then
+               eval $key=$value
+       fi
+done < "/itg/PreCom/stream_parameters.txt"
+
+dos2unix /mnt/shares/itg-repo/CaptureInfo.txt > /dev/null 2>&1
+
+line1=$(sed -n "1p" "/mnt/shares/itg-repo/CaptureInfo.txt")
+line2=$(sed -n "2p" "/mnt/shares/itg-repo/CaptureInfo.txt")
+
+OLDIFS=$IFS
+IFS=', ' read -a v1coords <<< "$line1"
+IFS=', ' read -a v2coords <<< "$line2"
+IFS=$OLDIFS
+
+/usr/local/bin/ffmpeg -y -f x11grab -r "$framerate" -i 0:0 -f video4linux2 -i /dev/video0 -itsoffset 0.1 -f alsa -i "plughw:CARD=${device},DEV=0" -filter_complex \
+"[0:v]setpts=PTS-STARTPTS+${video_offset}/TB,scale=$((v1coords[2])):$((v1coords[3])),pad=1280:720:$((v1coords[0])):$((v1coords[1])):black[v1];[1:v]setpts=PTS-STARTPTS,scale=$((v2coords[2])):$((v2coords[3]))[v2]; [v1][v2]overlay=$((v2coords[0])):$((v2coords[1]))" \
+-f flv  -vcodec libx264 -g "$framerate" -keyint_min "$framerate" -b "$video_bitrate" -minrate "$video_bitrate" -maxrate "$video_bitrate" -pix_fmt yuv420p -preset ultrafast -tune film -threads 2 -s 1280:720 \
+-strict experimental -bufsize "$video_bitrate" -ar "$audio_bitrate" /itg/stream.mp4 > /dev/null 2>&1 &
+
+#if [[ -z "$stream" ]]; then
+#      case $stream in
+#        peekingboo)
+#              obs_profile="PeekingBoo-ITG"
+#              obs_scene="PeekingBoo"
+#              ;;
+#         birdymint)
+#              obs_profile="BirdyMint-ITG"
+#              obs_scene="PeekingBoo"
+#              ;;
+#        divinelegy)
+#              obs_profile="DivinElegy-ITG"
+#              obs_scene="PeekingBoo"
+#              ;;
+
+if [[ -n "$obs_profile" ]] && [[ -n "$obs_scene" ]]; then
+       ssh PeekingBoo@192.168.0.6 'C:\Program Files\PsExec.exe -i -s "C:\Program Files (x86)\OBS\OBS.exe"' -profile "$obs_profile" \
+       -scenecollection "$obs_scene" -start > /dev/null 2>&1 &
+fi
+
+#XXX: Loop forever so start-stop-daemon can kill us
+while :
+do
+       sleep 1
+done
index c0f1cd3..a9a99fd 100644 (file)
@@ -1,2 +1,5 @@
-bitrate=dank
-swage=memes
+framerate=60
+device=C615
+video_offset=0.5
+video_bitrate=5000k
+audio_bitrate=44100
diff --git a/test.sh b/test.sh
new file mode 100755 (executable)
index 0000000..9bd27d8
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+touch /var/log/testfffggg