Huawei E3531s-2 on Ubuntu 14.04

The BroadBand modem Huawei E3531s-2 on Ubuntu 14.04 does not work out of the box.

Let’s make it work.

  • - Install supervisor:

sudo apt-get install supervisor -y

  • Add a supervisor configuration to a new program: A script we’ell shortly create, In /etc/supervisor/conf.d/broadband.conf

[program:broadband]
command=/usr/bin/broadband
autostart=true
autorestart=true
stderr_logfile=/var/log/broadband_err.log
stdout_logfile=/var/log/broadband_info.log

  • Write a script in /usr/bin/broadband and make it executable.

#!/bin/bash
# Script to enable Mobile Broadband
# Author: (hanynowsky@gmail.com)
WAIT=25
# Huawei E3531s-2
localcon="Meditel2"
connector(){
isBUP=$(nmcli con status | grep -i "${localcon}")
if [ -z "${isBUP}" ];then
echo "Broadband Connection Status is void: ${isBUP}"
nmcli nm wwan on;
sleep 1;
nmcli nm wwan off;
sleep 1;
if [ -n "${isBUP}" ];then
echo "Switching Off connection to ${localcon}"
nmcli con down id "${localcon}";
fi
sleep 1;
echo "Trying to Connect to $localcon"
nmcli con up id "${localcon}";
if [ "$?" -eq 0  ]; then
echo "Connection Established."
fi
sleep 1
fi
#exit 0;
}

while true; do
if [ -n "$(lsusb | grep '12d1:15ce')" ]; then
# This will switch to modem mode : 12d1:15b1
sudo usb_modeswitch -v 12d1 -p 15ce -M '55534243123456780000000000000011062000000100000000000000000000'
echo "Activating modem, please wait ${WAIT} seconds."
notify-send -u normal -a broadband "Connecting Broadband" "Modem $(lsusb | grep -i huawei). \nPlease wait 25 seconds"
sleep $WAIT
fi
isModem=$(lsusb | grep -iE '12d1:15b1|modem on')
if [ -n "${isModem}" ]; then
eval connector
fi
done

  • Change ‘localcon=”Meditel2″‘ to the name of your BroadBand Connection (You should have already configured it using Network Manager Applet)
  • Restart Supervisor.
sudo service supervisor restart

Now everytime, you plug the broadband device, it will get connected through the BroadBand connection configuration you already set up. In our case it’s called “Meditel2″.

Please note that once you plug the device, you have to wait 30 seconds before the connection is established.

Get External/Local Ip regardless to Network Device in Linux

#!/bin/bash
# Date:     January 2015
# Author:  Hanine HAMZIOUI
# Usage:    Get the Machine IP. Commands are fallbacks
#           Just do: $~ bash ip.sh or bash.sh local/private/host
 
COM1=$(dig +short myip.opendns.com @resolver1.opendns.com 2>/dev/null)
COM2=$(hostname -i 2>/dev/null)
COM3=$(ip route show 2>/dev/null | grep src | grep -vE 'eth1.*|lo' |  awk -Fsrc '{print $2}' | sed -e 's/ //g')
COM4=$(curl -s monip.org 2>/dev/null | grep -o -E '([0-9]+\.){3}[0-9]+')
COM5=$(host `hostname -f 2>/dev/null` | awk -F[aA]ddress '{print $2}' | sed 's/ //g')
COM6=$(for i in eth0 em1 bond0; do inf=`ip -4 addr show dev $i 2>/dev/null | grep inet -m1 | cut -d/ -f1 | awk '{ print $2}'`;if [[ "$inf" =~ [0-9][0-9]?* ]]; then echo "$inf";fi ;done)
if [[ "$1" =~ local ]] ;then
    COM1=$COM3
fi
if [[ "$1" =~ private ]] ;then
    COM1=$COM2
fi
if [[ "$1" =~ host ]] ;then
    COM1=$COM5
fi
IP=''
validip()
{
    local  ip=$1
    local  stat=1
 
    if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
        OIFS=$IFS
        IFS='.'
        ip=($ip)
        IFS=$OIFS
        [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]]
        stat=$?
    fi  
    if [ "$stat" -eq 0 ]; then
        echo $IP
    else
        echo $stat
    fi  
    return $stat
}
if [ -n "${COM1}" ];then
    IP=${COM1}
    eval validip $IP
    exit
fi
 
if [ -n "${COM2}" ];then
    IP=${COM2}
    eval validip $IP
    exit
fi
if [ -n "${COM3}" ];then
    IP=${COM3}
    eval validip $IP
    exit
fi
if [ -n "${COM4}" ];then
    IP=${COM4}
    eval validip $IP
    exit
fi
 
if [ -n "${COM5}" ];then
    IP=${COM5}
    eval validip $IP
    exit
fi
if [ -n "${COM6}" ];then
    IP=${COM6}
    eval validip $IP
    exit
fi
exit

Persist your screen brightness settings in Linux

If you like me have a machine running Linux OS and want to be able to persist your screen’s brightness setting, here is a small script that does the trick. (I don’t know if that feature lacks only in Ubuntu running in a Dell XPS 15 l502x or common to all Linux laptops)

Initially the problem is that once you reboot the machine, you lose the brightness setting and you have to manually adjust again. Annoying!

With the following instructions, you’ll be able to fix that. Tested in Ubuntu 13.10.

Copy these following three scripts in your Desktop folder (Or in the same folder) and give them execution permission:

RESET script (brightness-reset.sh):

#!/bin/bash
# Author: Hanine HAMZIOUI ALMADANY <hanynowsky@gmail.com>
# This script sets the brightness in Ubuntu as it is not persistent upon reboot

# In order to manually execute these commands below, the user must be root

# Brightness values are integers that range from 0 to 15
DEFAULT_BRIGHTNESS=7
CUSTOMBRIGHTNESS="$HOME/brightness/last_brightness"

if [ -f $CUSTOMBRIGHTNESS ];then echo $(cat $CUSTOMBRIGHTNESS) > /sys/class/backlight/acpi_video0/brightness
else echo $DEFAULT_BRIGHTNESS > /sys/class/backlight/acpi_video0/brightness
fi
exit 0

Brightness RUN (brightness-run.sh)

#!/bin/bash

# Persist Brightness value in Ubuntu 13.10
# Author Hanine HAMZIOUI ALMADANY <hanynowsky@gmail.com>

if [ -f "brightness-reset.sh" ]; then
sudo cp -v brightness-reset.sh /etc/init.d/ && sudo chmod +x /etc/init.d/brightness-reset.sh
else echo "brightness-reset file does not exist, it must be in the same folder. Terminating..."; exit 0;
fi

if [ -f "brightness-save.sh" ]; then
sudo cp -v brightness-save.sh /etc/init.d/ && sudo chmod +x /etc/init.d/brightness-save.sh
else echo "brightness-save file does not exist, it must be in the same folder. Terminating..."; exit 0;
fi

sudo ln -s /etc/init.d/brightness-save.sh /etc/rc0.d/K10brightness-save # Brightness SAVE Symbolic link to RC 0
sudo ln -s /etc/init.d/brightness-save.sh /etc/rc6.d/K10brightness-save # Brightness SAVE Symbolic link to RC 6

rawfile=`cat /etc/rc.local | grep "/etc/init.d/brightness-reset.sh"`
if [ -z "$rawfile" ]; then
sudo sed -e 's/exit 0//g' -i /etc/rc.local
sudo echo "#Reset screeen brightness" >> /etc/rc.local
sudo echo "/etc/init.d/reset-brightness.sh" >> /etc/rc.local
sudo echo "exit 0" >> /etc/rc.local
else echo "RC.LOCAL file is already customized to reset brightness at startup...If you think otherwise, do it manually again!"
fi

exit 0;

BRIGHTNESS Save (brightness-save.sh)

#!/bin/bash

# Author: Hanine HAMZIOUI ALMADANY <hanynowsky@gmail.com>
# Target: Ubuntu 13.10 and below
# Script that saves the last brightness value used

CUSTOMBRIGHTNESS="$HOME/brightness/last_brightness"
mkdir -p $(dirname $CUSTOMBRIGHTNESS)
cat /sys/class/backlight/acpi_video0/brightness > $CUSTOMBRIGHTNESS
exit 0;

then

chmod +x ~/Desktop/brightness-*

And finally; from your terminal again:

bash ~/Desktop/brightness-run.sh

You will be prompted for your user password.

Now adjust brightness ti a certain value and reboot. ;)

Beautify LibreOffice with a new set of Chrome Icons

The era of very ugly LibreOffice icons is over. A new set of beautiful and homogeneous icons is being prepared for the next versions of LibreOffice.

libreoffice_icons

libreoffice_Icons

You can use the Beta version if you’re impatient like me. This is how:

Copy/Paste the content of this script below in a text file in your Desktop folder (name it for example: icoffice.sh, and give it execution permissions:

#!/bin/bash
# Script that downloads Libreoffice new gnome icons
# Author: hanynowsky 2013
# After executing this script: From the LibreOffice menu select Tools > Options,
# then under LibreOffice > View > Icon size and style, set the icon theme to "Crystal"
sudo apt-get install libreoffice-style-crystal
cd /tmp && wget https://github.com/hotice/myfiles/raw/master/images_flat.zip

if [ -d "/usr/share/libreoffice/share/config/" ]; then
sudo cp images_flat.zip /usr/share/libreoffice/share/config/images_crystal.zip
else echo "No official LibreoFfice?"
fi

if [ -d "/opt/libreoffice4.0/share/config/" ]; then
sudo cp images_flat.zip /opt/libreoffice4.0/share/config/images_crystal.zip
else echo "No custom Libreoffice - it is okay!"
fi
exit 0

and then

chmod +x ~/Desktop/icoffice.sh

And finally:

bash ~/Desktop/icoffice.sh

You’ll be prompted to type your password in order to achieve installation of the new icon set.
Once finished, after executing this script: From the LibreOffice menu select Tools -> Options. Then under LibreOffice -> View -> Icon size and style, set the icon theme to “Crystal

Integration of Java Swing Applications with Unity Global Menu in Ubuntu 13.10

Due to recent changes and updates in Ubuntu 13.10, Version 1.x of Jayatana no longer works.

A new version (2.0) of Java Ayatana is being tested to support java Application menu integration with UBuntu 13.10. Watch this post. Un update should land soon.

————————————————————————————————————

Hopefully, the new version 2.0 is released and you can get it right away for Ubuntu 13.10:

sudo add-apt-repository ppa:danjaredg/jayatana
sudo apt-get update
sudo apt-get install jayatana

Ubuntu 13.10 Saucy on Dell XPS L502X

This post mentions some issues and fixes after upgrading to Ubuntu 13.10.

For Ubuntu 13.04 and previous versions, please refer to the corresponding post.

Nvidia Optimus:

– First of all, once the upgrade has completed, the user should workaround bumblebee to make it work:

When you run optirun command, you get an error message like this:

error while loading shared libraries: libturbojpeg.so: cannot open shared object file: No such file or directory

Open a Terminal and type:

sudo ln -s /usr/lib/x86_64-linux-gnu/libturbojpeg.so.0 /usr/lib/x86_64-linux-gnu/libturbojpeg.so

and

sudo ln -s /usr/lib/i386-linux-gnu/libturbojpeg.so.0 /usr/lib/i386-linux-gnu/libturbojpeg.so

—————————————————-

SD Card Reader:

Up to 13.04, the SD card reader was not really functional, unless you boot up with the card inserted. This bug has been fixed in Kernel 3.12 and should be backported soon to 13.10. Patience.

We’d be updating this post by this week-end, with useful information.