pinephone-scripts

Scripts and small applications for the PinePhone
git clone https://src.jayvii.de/pub/pinephone-scripts.git
Log | Files | Refs | README | LICENSE

mconnect-yad.sh (1497B)


      1 #!/usr/bin/env bash
      2 
      3 if [[ -d `whereis mconnectctl | awk '{ print $2 }'` ]]; then
      4     echo "[FAIL] mconnect and mconnectctl need to be installed."
      5     exit 1;
      6 fi
      7 
      8 if [[ -d `pidof mconnect` ]]; then
      9     echo "[FAIL] mconnect needs to be running: \"mconnect -d\"."
     10     exit 2;
     11 fi
     12 
     13 DEVICES=`mconnectctl list-devices | \
     14                      grep "/org/mconnect/device/" | \
     15                      sed -e 's/^.*\/org\/mconnect\/device\///g' | \
     16                      tr '\n' ';'`
     17 
     18 CHOICE=`yad --title="MConnect" \
     19             --form \
     20             --item-separator=";" \
     21             --field="Device:CBE" "${DEVICES}" \
     22             --field="Text:TEXT" \
     23             --field="File:FL" \
     24             --field="Allow Device:CHK"`
     25 
     26 CH_DEV=`echo $CHOICE | cut -d "|" -f1 | awk '{ print $1 }'`
     27 CH_TXT=`echo $CHOICE | cut -d "|" -f2`
     28 CH_DAT=`echo $CHOICE | cut -d "|" -f3`
     29 CH_ALW=`echo $CHOICE | cut -d "|" -f4`
     30 
     31 if [[ "$CH_ALW" == "TRUE" ]]; then
     32     mconnectctl allow-device /org/mconnect/device/${CH_DEV}
     33 fi
     34 
     35 IS_URL=FALSE
     36 if [[ -d "$CH_TXT" ]]; then
     37     if [[ ! -d `echo "$CH_TXT" | grep "^(http|mailto:)"` ]]; then
     38         IS_URL=TRUE
     39     fi
     40 fi
     41 
     42 if [[ $IS_URL == TRUE ]]; then
     43     mconnectctl share-url /org/mconnect/device/${CH_DEV} "$CH_TXT"
     44 elif [[ "$CH_TXT" != "" ]]; then
     45     mconnectctl share-text /org/mconnect/device/${CH_DEV} "$CH_TXT"
     46 elif [[ "$CH_DAT" != "" ]]; then
     47     mconnectctl share-file /org/mconnect/device/${CH_DEV} "$CH_DAT"
     48 else
     49     echo "[FAIL] Nothing to be shared..."
     50 fi
     51 
     52 exit 0;
     53