Thursday 29 November 2018

How to install busybox onto an Android emulator in order to access more linux commands

I have created the following script which can install busybox silently and headlessly via command line. It works on both 32-bit and 64-bit Android emulators.

Firstly, you should download busybox binary executable from https://busybox.net/downloads/binaries/ and copy it into your $HOME/bin folder.

Next, make a script called install-busybox.sh in $HOME/bin with the following content:

if [ $# == 0 ]; then
    devs="`adb devices | awk '{if(NF>0)print $0}' | sed -n '2,$p'`"
    N=`echo $devs | wc -l`
    if [ $N -gt 1 ]; then
        echo "Usage: $0 device-serial" >&2
        adb devices
        exit 1
    fi
    set -- `echo "$devs" | awk '{print $1}'`
fi

set -x

adb -s $1 root
adb -s $1 shell setenforce 0
adb -s $1 shell mount -o remount,rw /
adb -s $1 push $HOME/bin/busybox /sbin

# on 64-bit system, it fails
if [ $? != 0 ]; then
    adb -s $1 shell mount -o rw,exec,remount /mnt
    adb -s $1 shell cp -rfp '/sbin' /mnt/
    adb -s $1 shell mount /mnt/sbin /sbin
    adb -s $1 push $HOME/bin/busybox /sbin
fi

adb -s $1 shell /sbin/busybox --install -s /sbin
res=$?

set +x
if [ $res == 0 ]; then
    echo Successful
else
    echo Failed
fi


So far, I have tested it on API 26-28, but it might not work on all Android images.

Tuesday 8 May 2018

Ubuntu HDMI extended monitor low resolution solved

It seems that recent versions of Ubuntu (16.04) has a bug in handling extended HDMI monitors. The HDMI monitor has up to 1980x1080 resolution, my laptop has up to 1366x768 resolution. Both screens have native 16:9 ratio.
However, in "mirrored display" mode, I can only select 1024x768 and 800x600 resolution as shown in the image below:


In such mode, my laptop screen has two blank strip on the left and right side. On the HDMI monitor, it shows a squashed screen (1024x768 resolution stretched to 16:9 full screen).

The solution is to use xrandr to list all display modes and add each mode into every monitor, the shell script is as follows:
displays=(`xrandr | grep '^[^ ]' | awk '{print $1}'`)

xrandr | grep "^ " | awk '{print $1}' | grep [0-9]x[0-9] | sort | uniq \
        | while read mode; do
        echo "Adding $mode ..."
        for display in ${displays[*]}; do
                xrandr --addmode $display $mode
        done
done
You just need to run this script before plugging in the HDMI cable.

Thursday 22 February 2018

X11 tunnelling with audio

By default, X11 tunneling only support video but not audio. However, if both the server and the client is running Linux/Ubuntu, there is a way to do so. Hereby, I define 'server' as the machine running the actual program, 'client' as the machine which displays in front of the user.

The procedures are as follows:

1. Install and run paprefs, goto "Network server", check "Enable network access to local sound devices" and "Allow other machines on LAN to discover local sound devices"

2. on the client, run "start-pulseaudio-x11"

3. on the client, ssh to server with reverse SSH, "ssh -X -R 9998:localhost:4713 username@server"

4. in SSH, run the program on server, "PULSE_SERVER=localhost:9998 rhythmbox"

Monday 5 February 2018

Installing Office2010 using PlayOnLinux on Ubuntu 16.04 with Chinese input method

  A few years ago, I posted a quite troublesome method of installing Office2010 using Wine. Some issues are neglected. Nowadays, Ubuntu has evolved to have PlayOnLinux to get you through all those troubles.

All you need to do is the following:

0. Install winbind and samba using apt-get (if not installed)

1. Install PlayOnLinux, using the following command: 

    apt install playonlinux

2. Install Office2010 using PlayOnLinux and your MS-Office install CD

3. change configuration to support Chinese (or whatever non-latin language) input by editing those .desktop files, append "env XMODIFIERS='@im=fcitx' LC_ALL=zh_CN.UTF-8" at the beginning of the Exec command:

The original command line should look like following:
Exec=/usr/share/playonlinux/playonlinux --run "Microsoft Excel 2010" %F

You need to change it into the following:
Exec=env XMODIFIERS='@im=fcitx' LC_ALL=zh_CN.UTF-8 /usr/share/playonlinux/playonlinux --run "Microsoft Excel 2010" %F

Notes:
- if you are using some other using input method system (not fcitx), change the field '@im=fcitx' accordingly
- if you are using other non-latin languages (not Chinese), change the field LC_ALL=zh_CN.UTF-8 accordingly (see language code list at https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes)
- by default, PlayOnLinux will install those .desktop files to your desktop folder (at $HOME/Desktop) and your local shared application folder (at $HOME/.local/share/applications/playonlinux*.desktop). You can drag these icons onto your Unity launcher bar for convenient launching.

4. copy the 32-bit version of t2embed.dll and fontsub.dll (in C:\windows\system32 for 32-bit Windows, in C:\windows\SysWOW64\ for 64-bit Windows) from Windows into $WINE_PREFIX/drive_c/windows/system32 so that you can save Office document into PDF with embedded fonts. Otherwise, the resultant PDF file is very big due to bitmap fonts.

5. copy all fonts files from \Windows\Fonts into $WINE_PREFIX/drive_c/windows/Fonts so that you can now use all fonts that are available in Windows.

After doing all these steps, the resulting copy of MS-Office installation should support most of the functionalities, including non-English character display and input method, all Windows and Linux fonts, space efficient save-as-PDF, and can be launched via X11 tunneling (i.e., the PlayOnLinux MS-Office is installed on the server, run on server, but the GUI is displayed at the client).