From: Einar Jørgen Haraldseid Date: Tue, 7 Apr 2015 21:25:13 +0000 (+0200) Subject: Merge branch 'master' of ssh://git.slaskete.net/srv/git/einar-bin X-Git-Url: https://git.slaskete.net/einar-bin/commitdiff_plain/858e662f521c505898e437c54615c56faae32aee?hp=1facd0220e9c5fdc07e7dea2d8aa7707ce4b7887 Merge branch 'master' of ssh://git.slaskete.net/srv/git/einar-bin --- diff --git a/addpullprint.sh b/addpullprint.sh new file mode 100755 index 0000000..b1bd9cd --- /dev/null +++ b/addpullprint.sh @@ -0,0 +1,100 @@ +#!/bin/sh +# This script installs the SafeCom pullprint print queue +# for Høgskolen i Gjøvik on Linux and Mac systems. +# Written by einarh@hig.no +# I consider this script public domain + +# Test for system variant +OS=$(uname) +if [ "${OS}" != "Darwin" ] && [ "${OS}" != "Linux" ]; then + echo "I don't think I can run on "${OS}", but if you insist, please edit me and remove the test." 1>&2 + exit 1 +fi + +# Test for root +if [ $(id -u) -ne 0 ]; then + echo "This script must be run as root. Please use sudo or log in as root" 1>&2 + exit 1 +fi + +# Test for CUPS +command -v lpadmin >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "You must have CUPS installed to add printers. Please install CUPS." 1>&2 + exit 1 +fi + +# Test for smbclient if on Linux +if [ "${OS}" = "Linux" ]; then + command -v smbclient >/dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "You must have smbclient installed to add printers. Please install smbclient." 1>&2 + exit 1 + fi +fi + +echo "This script will add a new printer called Pullprint, connecting to +the print server safecom2.hig.no using your normal user name and +password from HiG. Do not use on multi user systems!" + +printf "User name: " +read USERNAME +printf "Password: " +SETTINGS=$(stty -g) +stty -echo +read PASSWORD +stty "${SETTINGS}" + +echo "" + +# Test for valid username and password if on Linux +if [ "${OS}" = "Linux" ]; then + smbclient -U HIG/${USERNAME}%${PASSWORD} -L //hig.no > /dev/null 2>&1 + if [ $? -ne 0 ]; then + echo "User name or password incorrect, or no contact with HiG servers." 1>&2 + exit 1 + fi +fi + +# Add the printer + +# The Linux way +if [ "${OS}" = "Linux" ]; then + lpadmin -p Pullprint \ + -D "SafeCom Pullprint ved HiG" \ + -v "smb://hig%5C${USERNAME}:${PASSWORD}@safecom2.hig.no/PullPrint" \ + -m "drv:///sample.drv/generic.ppd" \ + -u allow:all -E +fi + +# The OSX way +if [ "${OS}" = "Darwin" ]; then + lpadmin -p Pullprint \ + -D "SafeCom Pullprint ved HiG" \ + -v "smb://HIG;${USERNAME}:${PASSWORD}@safecom2.hig.no/PullPrint" \ + -m "drv:///sample.drv/generic.ppd" \ + -u allow:all -E +fi + +if [ $? -ne 0 ]; then + echo "Could not connect to printer share. See above error for details." 1>&2 + exit 1 +fi + +# Set correct paper size and enable the duplexer option +lpadmin -p Pullprint -o PageSize=A4 -o Option1=True + +if [ $? -ne 0 ]; then + echo "Could not set default options. See above error for details." 1>&2 + exit 1 +fi + +# Set as default +lpadmin -d Pullprint + +if [ $? -ne 0 ]; then + echo "Could not set Pullprint as default printer. See above error for details." 1>&2 + exit 1 +fi + +echo "Printer successfully installed." diff --git a/check_weechat b/check_weechat new file mode 100755 index 0000000..259d26b --- /dev/null +++ b/check_weechat @@ -0,0 +1,10 @@ +#!/bin/bash +# Short script to help keeping weechat alive +if test $(ps x | grep SCREEN | grep weechat-curses | grep -v grep | wc -l) -gt 0 +then + # screen process with ID weechat is running, exit silently + exit 0 +else + # No screen process with ID weechat is running, restart screen + screen -U -d -m -s /bin/bash -S weechat -T screen-256color weechat-curses +fi diff --git a/imgurgame-oneliner.bash b/imgurgame-oneliner.bash new file mode 100644 index 0000000..d1bacdf --- /dev/null +++ b/imgurgame-oneliner.bash @@ -0,0 +1 @@ +while true; do u=http://i.imgur.com/$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1).jpg;[ `curl -s -o /dev/null -I -w %{http_code} $u` == 200 ] && echo $u; done diff --git a/imgurgame.bash b/imgurgame.bash new file mode 100755 index 0000000..88af620 --- /dev/null +++ b/imgurgame.bash @@ -0,0 +1,39 @@ +#!/bin/bash +# Because why not? curl must be installed + +readonly BROWSER="google-chrome" + +# Create a random imgur url that may or may not be valid +imgururl() { + # 1/3 chance for length of 5, 6 or 7 length string + STRLN=$((5 + ${RANDOM} % 3)) + local ID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${STRLN} | head -n 1) + echo "http://i.imgur.com/${ID}.jpg" +} + +# Test if we found a valid URL +testimgur() { + local URL=${1} + local RESULT=$(curl -s -o /dev/null -I -w "%{http_code}" ${URL}) + if [[ ${RESULT} == "200" ]]; then + echo true + else + echo false + fi +} + +main() { + local FAIL=0 + while true; do + local URL=$(imgururl) + if [[ $(testimgur ${URL}) == "true" ]]; then + echo "Found ${URL} after ${FAIL} failed tries" + ${BROWSER} ${URL} > /dev/null 2>&1 + local FAIL=0 + else + ((FAIL++)) + fi + done +} + +main diff --git a/screencast-ts.sh b/screencast-ts.sh new file mode 100755 index 0000000..93ffa86 --- /dev/null +++ b/screencast-ts.sh @@ -0,0 +1,93 @@ +#!/bin/bash +# WARNING: This is a terribly dirty and messy shellscript, written over a couple of late nights. +# There was alcohol … +# You probably need to install all the gstreamer-plugins (at least -ugly and -ffmpeg) to get this +# to work. This version encodes h264 video and aac sound(s) to an MPEG4 Transport Stream file. +# +# So this script allows you to create screencasts on Linux, with optional sound inputs (both Mic +# and system sounds). It stores system sounds and mic in separate audio streams. +# You also get to choose to record from the whole screen or just a specified window. It has only +# been tested on Fedora 18. +# +# It dumps the recording in your $HOME directory with filename screencast-YYYY-MM-DD-HH-MM-SS.ts +# +# Written by Einar Jørgen Haraldseid (http://einar.slaskete.net) +# License: http://sam.zoy.org/wtfpl/COPYING + +# Get device names and pretty names for playback sinks: +PLAYSINKLIST=$(pacmd list-sinks | grep -e "name: " -e "device.description = " | cut -d " " -f "2-" | sed -e "s/name: \|= //g" -e "s/<\|>\|\x22//g") + +# Display playback monitor chooser +PLAYMON=$(echo "${PLAYSINKLIST} +none +Don't capture system sounds" | zenity --list --title "Choose Output Device" --text "Choose a sound device to capture system sound from:" --column "device" --column "Name" --print-column=1 --hide-column=1 2>/dev/null) + +if [ -z ${PLAYMON} ]; then + echo "No choice made on output device, assuming cancel." + exit 1 +fi + +if [ ${PLAYMON} != "none" ]; then + # Unmute monitor of the playback sink (if set): + PLAYMON="${PLAYMON}.monitor" + + pacmd set-source-mute ${PLAYMON} false >/dev/null +fi + +# Get device names and pretty names for microphones: +MICLIST=$(pacmd list-sources | grep -e "name: " -e "device.description = " | grep -v -i "monitor" | cut -d " " -f "2-" | sed -e "s/name: \|= //g" -e "s/<\|>\|\x22//g") + +# Display device chooser +MIC=$(echo "${MICLIST} +none +Don't use a microphone" | zenity --list --title "Choose Microphone" --text "Choose a microphone to capture voice from:" --column "device" --column "Name" --print-column=1 --hide-column=1 2>/dev/null) + +if [ -z ${MIC} ]; then + echo "No choice made on microphone, assuming cancel." + exit 1 +fi + +# Get target window for recording: +TARGET=$(echo "root +Whole screen +window +Specific window" | zenity --list --title "Choose recording mode" --text "Do you want to record the whole screen, or record a specific window?" --column "target" --column "Mode" --print-column=1 --hide-column=1 2>/dev/null) + +if [ -z ${TARGET} ]; then + echo "No choice for recording target, assuming cancel." + exit 1 +fi + +if [ ${TARGET} = "root" ]; then + echo "Root chosen" + XWININFO=$(xwininfo -root) +else + echo "custom chosen" + XWININFO=$(xwininfo) +fi + +# Get Window ID and dimensions, make sure dimensions are divisible by two, or else the encoder will fail +WID=$(echo "${XWININFO}" | grep "Window id:" | awk '{print $4}') +WIDTH=$(echo "${XWININFO}" | grep "Width: " | cut -d ":" -f 2 | awk '{print $1+$1%2}') +HEIGHT=$(echo "${XWININFO}" | grep "Height: " | cut -d ":" -f 2 | awk '{print $1+$1%2}') + +# Calculate a suitable bitrate based on window dimensions +BITRATE=$(echo "${WIDTH} * ${HEIGHT} * 0.006" | bc | cut -d "." -f 1 ) + +# Set file name. +FILENAME="screencast-$(date +%F-%H-%M-%S).ts" + +# Enable inputs as suitable +if [ ${PLAYMON} != "none" ]; then + MONITORARG="pulsesrc device=${PLAYMON} slave-method=0 provide-clock=false ! audiorate ! audioconvert ! ffenc_aac bitrate=256000 ! queue2 ! mux." +fi +if [ ${MIC} != "none" ]; then + MICARG="pulsesrc device=${MIC} slave-method=0 provide-clock=false ! audiorate ! audioconvert ! ffenc_aac bitrate=256000 ! queue2 ! mux." +fi + +# Launch gstreamer +gst-launch -e ximagesrc xid="${WID}" do-timestamp=1 use-damage=0 ! video/x-raw-rgb,framerate=30/1 \ + ! ffmpegcolorspace ! videoscale method=0 ! video/x-raw-yuv,width=${WIDTH},height=${HEIGHT} \ + ! x264enc speed-preset=ultrafast bitrate=${BITRATE} ! queue2 \ + ! h264parse ! mpegtsmux name="mux" ! filesink location="${HOME}/${FILENAME}" $MONITORARG $MICARG + diff --git a/x240-clickpad.sh b/x240-clickpad.sh new file mode 100755 index 0000000..1cde0b7 --- /dev/null +++ b/x240-clickpad.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +# Configure the X240 ClickPad + +# 1 finger = left click, 2 finger = right click, 3 finger = middle click +synclient TapButton2=3 +synclient TapButton3=2 +synclient ClickFinger2=3 +synclient ClickFinger3=2 + +# enable horizontal two-finger scrolling (vertical is enabled by default) +synclient HorizTwoFingerScroll=1 +synclient VertTwoFingerScroll=1 + +# Where does the touch pad end to leave the remainder as real buttons +synclient AreaTopEdge=2000 + +# Areas must not overlap or it throws BadValue errors +synclient MiddleButtonAreaLeft=3000 +synclient MiddleButtonAreaRight=4049 +synclient MiddleButtonAreaTop=0 +synclient MiddleButtonAreaBottom=2000 + +synclient RightButtonAreaLeft=4050 +synclient RightButtonAreaRight=0 +synclient RightButtonAreaTop=0 +synclient RightButtonAreaBottom=2000 diff --git a/x240-swapkeys.sh b/x240-swapkeys.sh new file mode 100755 index 0000000..4bb9ba3 --- /dev/null +++ b/x240-swapkeys.sh @@ -0,0 +1,3 @@ +#!/bin/sh +xmodmap -e "keycode 118 = End" +xmodmap -e "keycode 115 = Insert"