Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Tags: Bash, Created At: 10/24/2016 8:26:36 PMViews:

HTML view:
Copy Source | Copy HTML
       1:  #!/bin/bash
       2:  function decodeUCS2 () # Ð´ÐµÐºÐ¾Ð´Ð¸Ñ€ÑƒÐµÑ‚ UCS
       3:  {
       4:  bytes=$(echo -n $1 | sed "s/\(.\{2\}\)/\\\x\1/g")
       5:  REPLY=$(printf $bytes | iconv -f UCS-2BE -t UTF-8)
       6:  }
       7:  function encodePDU () # ÐºÐ¾Ð´Ð¸Ñ€ÑƒÐµÑ‚ Ð² PDU
       8:  {
       9:  in=$1
      10:  let "in_len=${#in}-1"
      11:  for chr in $(seq 0 $in_len)
      12:  do
      13:  let "chr2=$chr+1"
      14:  let "t=$chr%8+1"
      15:  if [ "$t" -ne 8 ]; then
      16:  byte=$(printf "%d" "'${in:$chr:1}")
      17:  let "c=$byte>>($chr%8)"
      18:  let "c2=(1<<$t)-1"
      19:  byte2=$(printf "%d" "'${in:$chr2:1}")
      20:  let "b=$byte2 & $c2"
      21:  let "c=$b<<(8-$t) | $c"
      22:  REPLY=$REPLY$(echo "obase=16; $c" | bc | sed "s/^\(.\{,1\}\)$/0\1/")
      23:  fi
      24:  done
      25:  }
      26:  function USSD () # Ð²Ñ‹Ð¿Ð¾Ð»Ð½ÑÐµÑ‚ USSD Ð·Ð°Ð¿Ñ€Ð¾Ñ
      27:  {
      28:  $(printf "AT+CUSD=1,$1,15\r\n" > /dev/ttyUSB$ttyID)
      29:  REPLY=$(grep -m 1 "+CUSD" /dev/ttyUSB$ttyID | sed "s/.*\"\([A-F0-9]*\)\".*/\1/")
      30:  decodeUCS2 $REPLY
      31:  }
      32:  function data_traffic () # Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ñ‚ель Ð¸Ð½Ñ„Ñ‹ Ð°Ð²Ñ‚орепортов Ð¼Ð¾Ð´ÐµÐ¼Ð°
      33:  {
      34:  i=0
      35:  REPLY=$1
      36:  REPLY2=$1
      37:  data_text=( "байт" "Кбайт" "Мбайт" "Гбайт" "Тбайт" ) #ИМХО Ð±Ð¾Ð»ÑŒÑˆÐµ Ð½Ð¸ÐºÑ‚о Ð½Ðµ ÑÐºÐ°Ñ‡Ð°ÐµÑ‚
      38:  while [ $REPLY2 -gt 1024 ]
      39:  do
      40:  REPLY=$(echo "scale = 2 ; $REPLY/1024" | bc)
      41:  REPLY2=$(echo "$REPLY2/1024" | bc)
      42:  let "i=i+1"
      43:  done
      44:  REPLY="$REPLY ${data_text[$i]}"
      45:  }
      46:  if ls /dev/ttyUSB* > /dev/null; then
      47:  ttyID=$(ls /dev/ttyUSB* | xargs file -s | grep "ASCII text, with CRLF line terminators" | sed "s/.*ttyUSB\([0-9]\).*/\1/") # Ð¼Ð¾Ð´ÐµÐ¼
      48:  if [ -z "$*" ]; then
      49:  op=$(zenity --list --text="Выберите Ð¾Ð¿ÐµÑ€Ð°Ñ†Ð¸ÑŽ:" --column="" --column=""  --height="280" --width="280" --title="Билайн Ð˜Ð½Ñ‚ернет Ð”ома" --print-column=1 --hide-column=1 "balance" "Проверить Ð±Ð°Ð»Ð°Ð½Ñ" "start" "Активация ÑÑ‚артового Ð±Ð°Ð»Ð°Ð½ÑÐ°" "req" "Выполнить USSD Ð·Ð°Ð¿Ñ€Ð¾Ñ" "at" "Выполнить AT ÐºÐ¾Ð¼Ð¼Ð°Ð½Ð´Ñƒ" "info" "Информация Ð¾ ÑÐ¾ÐµÐ´Ð¸Ð½ÐµÐ½Ð¸Ð¸")
      50:  elif [ $# -gt 1 ]; then
      51:  op=$(echo -n $* |sed "s/\(.*\) .*/\1/")
      52:  op2=$(echo -n $* |sed "s/.* \(.*\)/\1/")
      53:  else
      54:  op=$*
      55:  fi
      56:  case $op in
      57:  balance)
      58:  USSD "AA184C3602"
      59:  MSG=$(echo -n $REPLY | sed "s/\.Дета.*//")
      60:  ;;
      61:  start)
      62:  USSD "AA182CA68AC562B111"
      63:  MSG=$REPLY
      64:  ;;
      65:  req)
      66:  if [ -z "$op2" ]; then
      67:  number=$(zenity --entry --text="Введите Ð½Ð¾Ð¼ÐµÑ€" --title="Билайн Ð˜Ð½Ñ‚ернет Ð”ома" --width=270)
      68:  else
      69:  number=$op2
      70:  fi
      71:  encodePDU $number
      72:  USSD $REPLY
      73:  MSG=$REPLY
      74:  ;;
      75:  at)
      76:  if [ -z "$op2" ]; then
      77:  cmd=$(zenity --entry --text="Введите AT ÐºÐ¾Ð¼Ð¼Ð°Ð½Ð´Ñƒ" --title="Билайн Ð˜Ð½Ñ‚ернет Ð”ома" --width=270)
      78:  else
      79:  cmd=$op2
      80:  fi
      81:  cmd=$(echo -n $cmd | tr a-z A-Z)
      82:  cmd2=$(echo -n $cmd | sed "s/^AT//; s/\(.[A-Za-z0-9]*\).*/\1/")
      83:  $(printf "$cmd\r\n" > /dev/ttyUSB$ttyID)
      84:  MSG=$(grep -m 1 "$cmd2" /dev/ttyUSB$ttyID)
      85:  ;;
      86:  info)
      87:  DSFLOWRPT=$(grep -m 1 "SFLOWRPT" /dev/ttyUSB$ttyID | sed "s/.*://g")
      88:  for i in `seq 1 5`
      89:  do
      90:  info_[$i]=$(echo -n "$DSFLOWRPT" | cut -f$i -d, | sed "s/./ibase=16; /" | bc)
      91:  done
      92:  let "time=${info_[1]}/60"
      93:  let "speed_trans=${info_[2]}/1024"
      94:  let "speed_rec=${info_[3]}/1024"
      95:  data_traffic "${info_[4]}" ; trans_data=$REPLY
      96:  data_traffic "${info_[5]}" ; rec_data=$REPLY
      97:  MSG="Время ÑÐ¾ÐµÐ´Ð¸Ð½ÐµÐ½Ð¸Ñ: $time Ð¼Ð¸Ð½.<br/>Передача Ð´Ð°Ð½Ð½Ñ‹Ñ…: $speed_trans ÐšÐ±Ð¸Ñ‚/c<br/>Получение Ð´Ð°Ð½Ð½Ñ‹Ñ…: $speed_rec ÐšÐ±Ð¸Ñ‚/с<br/>Передано Ð´Ð°Ð½Ð½Ñ‹Ñ…: $trans_data<br/>Получено Ð´Ð°Ð½Ð½Ñ‹Ñ…: $rec_data"
      98:  ;;
      99:  *)
     100:  MSG="Неверная Ð¾Ð¿ÐµÑ€Ð°Ñ†Ð¸Ñ"
     101:  esac
     102:  else
     103:  MSG="Модем Ð½Ðµ Ð¿Ð¾Ð´ÐºÐ»ÑŽÑ‡ÐµÐ½"
     104:  fi
     105:  if [ -n "$MSG" ]; then
     106:  $(notify-send "Билайн Ð˜Ð½Ñ‚ернет Ð”ома" "$MSG")
     107:  fi 

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2017