Files
literate-dotfiles/binaries-private.org

14 KiB

My own specific binaries

phonebook ESRF phone-book

Old phonebook: The phone-list is taken from scp rnice@esrf.fr:/mnt/multipath-shares/sware/pub/phonelist/share/annuaire.txt /home/thomas/.local/data/annuaire.txt new phonebook: Use the etd script

cat ~/.local/data/annuaire.txt | fzf --header="NAME                         Surname               Phone    Office              Room        Email"
$TERMINAL --title esrf-phonebook -e phonebook
#!/bin/bash

ROOT_URL='https://phonedirectory.esrf.fr'
API_ENDPOINT="$ROOT_URL/api"
USAGE="
  ESRF Telephone Directory

  CLI to search $ROOT_URL

  Usage :
    # Search for <search term> in first name or last name
    $0 <search term>

"

function fail {
  echo "$1" >&2
  exit 1
}

function json_curl { curl --get --fail --silent --show-error -H "Content-Type:application/json" -H "Accept: application/json" "$@"; }

function lspersons {
    # List users and output result in csv
    json_curl --data-urlencode "search=$1" "$API_ENDPOINT/searchUsers" |\
      jq -r '. | (map(keys) | add | unique | sort) as $cols | map(. as $row | $cols | map($row[.])) as $rows | $rows[] | @csv' 2>/dev/null
}

if [ $# -eq 0 ]; then
  fail "$USAGE"
fi

# Print the list of persons as a table

lspersons $1 | awk 'BEGIN { FS=OFS="," }; {print $4,$3,$5,$1,$6,$2,$7}' | sed 's/"//g' | column -t -s "," | sort

exit $?

contacts Personnal phone-book

khard | fzf --header="Index    Name                      Phone                       E-Mail"
$TERMINAL --title esrf-phonebook -e contacts

remote-desktop - Remote Desktop Connect

computer=$(echo -e 'PCOPTRO\nPCMEL1\nRNICE\nPCDEHAEZE\nLAPMEL01\nZOTAC' | rofi -i -dmenu -p 'Computer:' -l 20);

if [[ -z "$computer" ]]; then
    exit 1
fi

dunstify --replace=99425 'Rdesktop' "Connection to ${computer}..."

proxy_arg=""
if [ "$computer" = "ZOTAC" ]; then
    # If connect to local PC
    ping -c 1 openwrt.lan &> /dev/null
    if [ $? -ne 0 ]; then
        # And outside of local network, use proxy
        proxy_arg="/proxy:socks5://localhost:8080"
    fi
else
    ping -c 1 proxy.esrf.fr &> /dev/null
    if [ $? -ne 0 ]; then
        # Outside the ESRF network
        proxy_arg="/proxy:socks5://localhost:8081"
    fi
fi

common_arg="/clipboard /bpp:32 /compression -themes -wallpaper /audio-mode:1 /dynamic-resolution /auto-reconnect /wm-class:RDP_$computer -grab-keyboard /cert:ignore /rfx /gfx:avc444"

case "$computer" in
    "RNICE" | "PCDEHAEZE")
        xfreerdp3 $proxy_arg $common_arg /d:ESRF /u:dehaeze /p:$(pass esrf.fr/dehaeze | sed -n 1p) /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;;

    "PCMEL1" | "PCOPTRO" | "LAPMEL01")
        xfreerdp3 $proxy_arg $common_arg /d:ESRF /u:OPPEL /p:$(pass esrf.fr/oppel | sed -n 1p) /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;;

    "ZOTAC")
        xfreerdp3 $proxy_arg $common_arg /u:thomas /p:$(pass windows/zotac | sed -n 1p) /v:192.168.5.75 > /tmp/freerdp_${computer}.log 2>&1 & ;;

    *)
        user=$(rofi -dmenu -p 'User:');
        password=$(rofi -dmenu -p 'Password:');
        xfreerdp3 $proxy_arg $common_arg /u:$user /p:$password /v:$computer.esrf.fr > /tmp/freerdp_${computer}.log 2>&1 & ;;

esac

wake-on-lan - Wake on LAN

computer=$(echo -e 'ZOTAC' | rofi -i -dmenu -p 'Computer:' -l 20);

if [[ -z "$computer" ]]; then
    exit 1
fi

dunstify --replace=99425 'Wake On Lan' "${computer}..."

case "$computer" in
    "ZOTAC")
        ssh homelab 'wakeonlan 00:01:2E:A2:42:9C' ;;

esac

mount-dir - Mount/Unmout directories

# <file system>                <mount point>          <type>     <options>                                 <dump>  <pass>
homelab:/srv/storage/          /home/thomas/mnt/homelab   fuse.sshfs noauto,allow_other,user,default_permissions    0       0
# <file system>                <mount point>          <type>     <options>                                 <dump>  <pass>
dehaeze@rnice:/tmp_14_days/    /home/thomas/mnt/tmp_14_days  fuse.sshfs noauto,allow_other,user,default_permissions    0       0
# <file system>                        <mount point>          <type>     <options>                                 <dump>  <pass>
dehaeze@rnice:/home/esrf/dehaeze/      /home/thomas/mnt/unix_home  fuse.sshfs noauto,allow_other,user,default_permissions    0       0
# <file system>                        <mount point>          <type>     <options>                                 <dump>  <pass>
//wfiles/groupshare             /home/thomas/mnt/groupshare   vsifs      noauto,user,credentials=/home/thomas/.smbcredentials,uid=1001,gid=1001,forceuid,forcegid    0       0
//wfiles/groupshare                          /home/thomas/mnt/groupshare     cifs       noauto,user,uid=1000,gid=1000,credentials=/home/thomas/.smbcredentials 0       0
homelab:/srv/storage/                        /home/thomas/mnt/homelab        fuse.sshfs noauto,allow_other,user,uid=1000,gid=1000,default_permissions          0       0
dehaeze@rnice:/tmp_14_days/                  /home/thomas/mnt/tmp_14_days    fuse.sshfs noauto,allow_other,user,uid=1000,gid=1000,default_permissions          0       0
dehaeze@rnice:/home/esrf/dehaeze/            /home/thomas/mnt/unix_home      fuse.sshfs noauto,allow_other,user,uid=1000,gid=1000,default_permissions          0       0
dehaeze@rnice:/data/monochromators/          /home/thomas/mnt/monochromators fuse.sshfs noauto,allow_other,user,uid=1000,gid=1000,default_permissions          0       0
dehaeze@rnice:/gpfs/jazzy/data/id21/inhouse  /home/thomas/mnt/data_id21      fuse.sshfs noauto,allow_other,user,uid=1000,gid=1000,default_permissions          0       0
blissadm@lmellab:/data/id00/inhouse/DCM      /home/thomas/mnt/data_id24      fuse.sshfs noauto,allow_other,user,uid=1000,gid=1000,default_permissions          0       0
blissadm@lmellab:/data/id00/inhouse/MEL      /home/thomas/mnt/data_mel       fuse.sshfs noauto,allow_other,user,uid=1000,gid=1000,default_permissions          0       0
blissadm@lmellab:/users/blissadm/local       /home/thomas/mnt/bliss          fuse.sshfs noauto,allow_other,user,uid=1000,gid=1000,default_permissions          0       0
blissadm@lmellab:/data/visitor               /home/thomas/mnt/data_bl        fuse.sshfs noauto,allow_other,user,uid=1000,gid=1000,default_permissions          0       0
if [ $# -eq 0 ]; then
    drive=$(echo -e 'bliss_mel\nbliss_id21\ndata_bl\ndata_id21\ndata_id24\ndata_mel\ndata_visitor\ndrive\nhomelab\nmonochromators\ntmp_14_days\nunix_home' | rofi -dmenu -no-custom -p 'Drive:' -l 20);
    if [[ -z "$drive" ]]; then
        exit 1
    fi
else
    drive=$1
fi


if grep -qs "/home/thomas/mnt/$drive" /proc/mounts; then
    umount "/home/thomas/mnt/$drive" && \
        dunstify --replace=58249 "$drive " 'Successfully unmounted' || \
        dunstify --replace=58249 --urgency=critical "$drive " 'Error while unmounted'
else
    echo "It's not mounted."
    mount "/home/thomas/mnt/$drive" && \
        dunstify --replace=58249 "$drive " 'Successfully mounted' || \
        dunstify --replace=58249 --urgency=critical "$drive " 'Error while mounted'
fi
if [ $# -eq 0 ]; then
    # Takes a lot of time with "tmp_14_days" is mounted
    # drive=$(find ~/mnt/* -maxdepth 0 -type d -empty -printf '%f\n' | rofi -i -dmenu -no-custom -p 'Drive:' -l 20);
    drive=$(ls ~/mnt | rofi -i -dmenu -no-custom -p 'Drive:' -l 20);
    if [[ -z "$drive" ]]; then
        exit 1
    fi
else
    exit 1
fi

proxy_arg=""
ping -c 1 proxy.esrf.fr &> /dev/null
if [ $? -ne 0 ]; then
    # Outside the ESRF network
    proxy_arg=".esrf.fr"
fi

remote_loc=""
case "$drive" in
    "homelab")
        remote_loc="thomas@homelab:/srv/storage/" ;;
    "tmp_14_days")
        remote_loc="dehaeze@rnice$proxy_arg:/tmp_14_days/" ;;
    "unix_home")
        remote_loc="dehaeze@rnice$proxy_arg:/home/esrf/dehaeze/" ;;
    "monochromators")
        remote_loc="dehaeze@rnice$proxy_arg:/data/monochromators/" ;;
    "data_mel")
        remote_loc="opid00@lmelcontrol$proxy_arg:/data/id00/inhouse/" ;;
    "data_jazzy")
        remote_loc="dehaeze@rnice$proxy_arg:/gpfs/jazzy/data/" ;;
    "data_easy")
        remote_loc="dehaeze@rnice$proxy_arg:/gpfs/easy/data/" ;;
    "data_id16a")
        remote_loc="blissadm@pico3$proxy_arg:/data/id16a/inhouse1/commissioning/ni_endstation/Speedgoat/" ;;
    "data_id31")
        remote_loc="opid31@id31$proxy_arg:/data/id31/inhouse/" ;;
    "data_id24")
        remote_loc="dehaeze@rnice$proxy_arg:/gpfs/gb/data/id24-dcm/inhouse" ;;
    "bliss_mel")
        remote_loc="blissadm@lmelcontrol$proxy_arg:/users/blissadm/local/" ;;
    "bliss_id16a")
        remote_loc="blissadm@id16a$proxy_arg:/users/blissadm/local/" ;;
    "bliss_id21")
        remote_loc="blissadm@id21$proxy_arg:/users/blissadm/local/" ;;
    "bliss_bm23")
        remote_loc="blissadm@bm23$proxy_arg:/users/blissadm/local/" ;;
    "bliss_id24")
        remote_loc="blissadm@foucault$proxy_arg:/users/blissadm/local/" ;;
    "groupshare")
        mount ~/mnt/groupshare && \
            exit ;;
esac

if [ -z $remote_loc ]; then
    exit
else
    sshfs -o allow_other,user,uid=1000,gid=1000,default_permissions,IdentityFile=/home/thomas/.ssh/id_ed25519 $remote_loc /home/thomas/mnt/$drive
fi

# sshfs -o allow_other,user,uid=1000,gid=1000,default_permissions $remote_loc /home/thomas/mnt/$drive
if [ $# -eq 0 ]; then
    # Takes a lot of time with tmp_14_days is mounted...
    # drive=$(ls ~/mnt/ | rofi -dmenu -no-custom -p 'Drive:' -l 20);
    drive=$(find ~/mnt/* -maxdepth 0 -type d -not -empty -printf '%f\n' | rofi -dmenu -no-custom -p 'Drive:' -l 20);
    if [[ -z "$drive" ]]; then
        exit 1
    fi
else
    exit 1
fi

umount /home/thomas/mnt/$drive

screen-select - Xrandr pre-defined scripts

option=$(echo -e "Work\nLaptop\nHome\nAouste" | rofi -i -dmenu -no-custom -p 'Screen:' -l 20)

if [[ -z "$option" ]]; then
    exit 1
fi

after_screen_change () {
    # Fix background if screen size/arangement has changed.
    setbg

    # Kill polybar
    killall -q polybar

    # Wait until the processes have been shut down
    while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done

    # Launch bars
    polybar top &
}

case "$option" in
    "Work")
        xrandr --output eDP-1 --off \
               --output DP-3-2 --primary --mode 2560x1440 --pos 0x0    --rotate normal \
               --output DP-3-1 --primary --mode 2560x1440 --pos 2560x0 --rotate normal && \
               after_screen_change
        ;;
    "Laptop")
        xrandr --output DP-1-1 --off \
               --output DP-1-2 --off \
               --output DP-3-1 --off \
               --output DP-3-2 --off \
               --output HDMI-1 --off \
               --output eDP-1 --primary --mode 1920x1200 --pos 0x0 --rotate normal && \
               after_screen_change
        ;;
    "Home")
        xrandr --output eDP-1  --off \
               --output DP-3-1 --off \
               --output DP-3-2 --off \
               --output HDMI-1 --off \
               --output DP-1-2 --primary --mode 2560x1440 --pos 0x0 --rotate normal && \
               after_screen_change
        ;;
    "Aouste")
        xrandr --output eDP-1 --off \
               --output HDMI-1 --primary --mode 2560x1440 --pos 0x0 --rotate normal && \
               after_screen_change
        ;;
    ,*)
        echo "== ! missing or invalid argument ! =="
        exit 2
esac

exit 0

print-esrf - Print on Rnice

  • To list printers lpstat -p -d
nbpage=$(echo -e '1\n2\n4' | rofi -dmenu -no-custom -p 'Number of pages per sheet' -l 20);
sides=$(echo -e 'one-sided\ntwo-sided-long-edge\ntwo-sided-short-edge' | rofi -dmenu -no-custom -p 'Two Sided:' -l 20);
media=$(echo -e 'A4\nA3' | rofi -dmenu -no-custom -p 'Size:' -l 20);
printer=$(echo -e 'ctb127c1u\nctb110c1u' | rofi -dmenu -no-custom -p 'Size:' -l 20);

if [[ -z "$nbpage" || -z "$sides" || -z "$media" || -z "$printer" ]]; then
    exit 1
fi

rsync -zaP "$1" dehaeze@rnice:/home/esrf/dehaeze/Downloads/to-be-printed.pdf && \
    ssh rnice "lpr -o media=$media -o sides=$sides -o number-up=$nbpage -P $printer /home/esrf/dehaeze/Downloads/to-be-printed.pdf";

readbib - Open Bibliography File

List all pdf files and open selected one with zathura.

cd ~/Cloud/pdfs/ && ls | rofi -dmenu -lines 20 | xargs -I {} zathura {}

readnotes - Open Note

List all pdf files and open selected one with zathura.

cd ~/Cloud/brain/pdfs/ && ls *.pdf | rofi -dmenu -lines 20 | xargs -I {} zathura {}

torrent-add - Add Torrent using stig

Used to add notification when a torrent is added.

stig add $@ && \
    dunstify --replace=22221 "Stif" 'Torrent Added' || \
    dunstify --replace=22221 --urgency=critical "Stif" 'Failed'