16.2.14

Linux special case listing options, tricks

To list only files beginning with the specified character:

mike@jarvis:/media/sdb1/jpg$ ls -1 [A]*.jpg
A-AM11-GGD_icon01_s_1.jpg
A-AM11-GGD_icon01_s.jpg
A-AM13-GGD_icon02_s_1.jpg
A-AM13-GGD_icon02_s.jpg

mike@jarvis:/media/sdb1/jpg$ ls -1 [a]*.jpg
a001_1.jpg
a001.jpg
a002_1.jpg
a002.jpg
a003_1.jpg
a003.jpg
a004_1.jpg
a004.jpg
a005_1.jpg
a005.jpg
Finding PNG images greater than 800 pixels:
for f in *.png;do if [ `file $f | cut -f5 -d\ ` -gt 800 ] ; then echo $f;fi;done
Finding JPG images greater than 800 pixels (requires installed imagemagick, to have identify command):
for f in *.jpg;do if [ `identify "$f" | cut -f3 -d ' ' | cut -f1 -d x` -gt 800 ] ; then echo "$f";fi;done

Resources that can also help:
http://www.codecoffee.com/tipsforlinux/articles/26-1.html http://www.thegeekstuff.com/2009/07/linux-ls-command-examples/ http://www.cyberciti.biz/faq/linux-list-just-directories-or-directory-names/

13.2.14

Trying WD SmartWare for My Passport USB HDD

During my data restoration struggles I tried Western Digitals SmartWare from http://support.wdc.com/product/download.asp?groupid=208
After attaching to my Mac the following log entries appear:
2/13/14 5:41:43.000 PM kernel[0]: USBMSC Identifier (non-unique): 57584A314143303737343937 0x1058 0x730 0x1012, 2
2/13/14 5:41:51.000 PM kernel[0]: NTFS driver 3.10 [Flags: R/W].
2/13/14 5:41:51.000 PM kernel[0]: NTFS volume name data1, version 3.1.
I'm using OSX 10.8.5 (Mountain Lion) and it's kernel supports NTFS, good to know.
After downloading SmartWare and launching the following entries appear in the Console.app
2/13/14 5:44:20.676 PM WD SmartWare Installer[69704]: Install Point: installSmartWareByFramework
2/13/14 5:44:20.677 PM WD SmartWare Installer[69704]: Install Point: uninstallSmartWareAndDriveManagerByFramework
2/13/14 5:44:23.038 PM coreservicesd[41]: Application App:'WD SmartWare Installer' [ 0x0/0x45c45c]  @ 0x0x7ffe39c56be0 tried to be brought forward, but isn't in fPermittedFrontASNs ( ( ASN:0x0-0x45d45d:) ), so denying.
2/13/14 5:44:23.038 PM WindowServer[182]: [cps/setfront] Failed setting the front application to WD SmartWare Installer, psn 0x0-0x45c45c, securitySessionID=0x186a5, err=-13066
2/13/14 5:44:23.049 PM authexec[69725]: executing /Volumes/data/Downloads/WD SmartWare Installer.app/Contents/MacOS/installerTool
2/13/14 5:44:25.750 PM SmartwareDriveService[69753]: SmartwareDriveService version V1.1.2.1 starting...
2/13/14 5:44:25.751 PM SmartwareDriveService[69753]: WDDevSvcServer::StartServer
2/13/14 5:44:25.751 PM SmartwareDriveService[69753]: Error while trying to delete /var/tmp/com.WD.SmartwareDriveService/Socket error = No such file or directory.
2/13/14 5:44:25.751 PM SmartwareDriveService[69753]: WDDeviceManager::DeletStatusMenuFile
2/13/14 5:44:25.754 PM SmartwareDriveService[69753]: WDDeviceManager::AddDevice
2/13/14 5:44:25.862 PM Dock[680]: no information back from LS about running process
2/13/14 5:44:26.095 PM WD SmartWare[69757]: I'm going to FrontParlor
2/13/14 5:44:26.000 PM kernel[0]: fsevents: watcher SmartwareService (pid: 69755) - Using /dev/fsevents directly is unsupported.  Migrate to FSEventsFramework
2/13/14 5:44:26.758 PM SmartwareDriveService[69753]: 00306d70: 1a 08 21 00 10 00                               ................
2/13/14 5:44:26.759 PM SmartwareDriveService[69753]: SCSI Command Status = 0 SCSI Status = 0 SCSI Sense Key = 0 ASC = 0 ASCQ = 0
2/13/14 5:44:26.759 PM SmartwareDriveService[69753]: 00306d70: 15 11 00 00 10 00                               ................
2/13/14 5:44:27.419 PM SmartwareDriveService[69753]: SCSI Command Status = 0 SCSI Status = 0 SCSI Sense Key = 0 ASC = 0 ASCQ = 0
2/13/14 5:44:27.421 PM SmartwareDriveService[69753]: WDDeviceManager::RebuildStatusMenuFile
2/13/14 5:44:27.421 PM SmartwareDriveService[69753]: 00306ef0: c0 45 00 00 00 00 00 00 20 00                   .E..............
2/13/14 5:44:27.422 PM SmartwareDriveService[69753]: SCSI Command Status = 0 SCSI Status = 0 SCSI Sense Key = 0 ASC = 0 ASCQ = 0
2/13/14 5:44:27.433 PM SmartwareDriveService[69753]: WDDevSvcServer::GetData



12.2.14

SSHFS mounting without password with SSH keys

First we need to generate public and private keys on our host.
When prompted for passphrase just hit enter to go without it

nevillegroup@shell:~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/nevillegroup/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/nevillegroup/.ssh/id_rsa.
Your public key has been saved in /home/nevillegroup/.ssh/id_rsa.pub.

We need to add our public key into authorized_keys file and upload it to the remote host into the .ssh directory.
nevillegroup@shell:~$ cat .ssh/id_rsa.pub > authorized_keys

Now we can create a bash script for mounting the remote directory
!/bin/bash

USERID="YOUR_UID"
USER="example"
HOST="example.com"
MOUNT_DIR="/home/example/examplecom_sshfs"

# create dir if it doesn't exists
if [ ! -d "$MOUNT_DIR" ]; then
    umount $MOUNT_DIR &> /dev/null
    mkdir $MOUNT_DIR
fi

# to check your uid use command `id`
sshfs -C -o uid=$USERID,ssh_command='ssh -i ~/.ssh/id_rsa',workaround=rename $USER@$HOST:. $MOUNT_DIR

Add executable flag to the file and you ready to mount with the script
nevillegroup@shell:~$ chmod +x bin/sshfs_examplecom
nevillegroup@shell:~$ ./bin/sshfs_examplecom
nevillegroup@shell:~$ ls /home/example/examplecom_sshfs
dev/  git/  logs/  sub/  web/


Backup with RSYNC and SSH authorized key

Finally I wrote my rsync backup script v. 0.1
https://raw.github.com/mikaelz/bin/master/backup.sh
#!/bin/sh

# ~/bin/backup.sh
# 
# Some help from
# http://www.sakana.fr/blog/2008/05/07/securing-automated-rsync-over-ssh/
# https://wiki.archlinux.org/index.php/Rsync#Automated_backup_with_SSH
# https://wiki.archlinux.org/index.php/Full_System_Backup_with_rsync
# https://www.linux.com/news/enterprise/storage/8200-back-up-like-an-expert-with-rsync
# Thanks

# man rsync
# -v be verbose
# -h human readable bytes
# -a, --archive archive mode; same as -rlptgoD (no -H) -H hard-links
# -z compress data during transfer
# --progress show file transfer progress
# -e remote shell to use

time rsync -vhaz --progress -e "ssh -i .ssh/id_rsa" \
    --exclude ".DS_Store" \
    --exclude "._.DS_Store" \
    --exclude "Thumbs.db" \
    --exclude "thumbs.db" \
    --exclude "desktop.ini" \
    --exclude ".svn" \
    --exclude ".git" \
    /Volumes/data/Dropbox/ \
    nevillegroup@shell.websupport.sk:/home/nevillegroup/optimalizaciaseosk/backup/Dropbox/
    # >> backup.log # log output
    # &> /dev/null


# needs FTP password
# time rsync -vhaz --progress -e ssh \
#     --exclude ".DS_Store" \
#     --exclude "._.DS_Store" \
#     --exclude "Thumbs.db" \
#     --exclude "thumbs.db" \
#     --exclude "desktop.ini" \
#     --exclude ".svn" \
#     --exclude ".git" \
#     /Volumes/data/Dropbox/ \
#     optimalizaciaseo.sk@optimalizaciaseo.sk:/backup/Dropbox/
#     # >> backup.log # log output
#     # &> /dev/null

Testing adblockedge (ABE)

"Adblock Edge is a fork of the Adblock Plus(R) version 2.1.2 extension for blocking advertisements on the web." - from https://bitbucket.org/adstomper/adblockedge/overview

I downloaded it from the Downloads section

Checked the SHA256 hash of the .xpi
mike@mikembp:~/Downloads$ shasum -a 256 adblockedge-2.0.9.xpi ; cat adblockedge-2.0.9.xpi.sha256 5b5b90306cbe675456323fb75d97ac3474315525999e7f7594ce18a7c4a72cd2 adblockedge-2.0.9.xpi 5b5b90306cbe675456323fb75d97ac3474315525999e7f7594ce18a7c4a72cd2 *adblockedge-2.0.9.xpi
Finally opening and installing in Firefox.
Install Firefox adblock edge

9.2.14

Android full backup with adb

To download Anroid SDK go to https://developer.android.com/sdk/index.html

The backup command
mike@mikembp:~/Downloads/android/sdk/platform-tools$ ./adb backup -all
Now unlock your device and confirm the backup operation.


Default backup file name is backup.ab
mike@mikembp:~/Downloads/android/sdk/platform-tools$ ls -la backup.ab
-rw-r-----  1 mike  wheel    60M Feb  9 07:39 backup.ab

Get some log stuff to examine phone stat data
mike@mikembp:~/Downloads/android/sdk/platform-tools$ ./adb logcat -b radio -d > radio.logcat
mike@mikembp:~/Downloads/android/sdk/platform-tools$ ./adb logcat -d > adb.logcat

Rooting an Android Samsung Galaxy Advance S GT-I9070

Today I googled my Androids firmware build code I9070XXLQG and read http://www.ibtimes.co.uk/galaxy-s-advance-root-i9070xxlqg-android412-jellybean-485079.

I have Android 4.1.2 Jelly Bean official update on my smartphone, which I updated with Samsung's Kies over USB cable.



From curiosity I downloaded the rooting package http://d-h.st/ook and looked at root/META-INF/com/google/android/updater-script
In a nutshell, rooting is adding su (SuperUser) binary into /system/bin.

ui_print("***************************");
ui_print("Rooting with SuperSU 0.95 & Busybox 1.20.2");
ui_print("***************************");
show_progress(1.000000, 0);

ui_print("Installing temporary busybox");
package_extract_file("system/xbin/busybox", "/tmp/busybox");
set_perm(0, 0, 0777, "/tmp/busybox");
set_progress(0.200000);

ui_print("Mounting system...");
run_program("/tmp/busybox", "mount", "/system");
set_progress(0.300000);

ui_print("Removing old superuser");
delete("/system/bin/su");
delete("/system/xbin/su");
delete("/system/app/superuser.apk");
delete("/system/app/superUser.apk");
delete("/system/app/Superuser.apk");
delete("/system/app/SuperUser.apk");
set_progress(0.400000);

ui_print("Installing Superuser & Busybox...");
package_extract_dir("system", "/system");
set_progress(0.600000);

ui_print("Setting Permission...");
set_perm(0, 0, 06755, "/system/xbin/su");
set_perm(0, 0, 0644, "/system/app/superuser.apk");
set_perm(0, 0, 04755, "/system/xbin/busybox");
set_progress(0.700000);

ui_print("Installing Busybox...");
run_program("/system/xbin/busybox", "--install", "-s", "/system/xbin");
set_progress(0.900000);

ui_print("Symlinking...");
symlink("/system/xbin/su", "/system/bin/su");

ui_print("Unmounting system...");
run_program("/tmp/busybox", "umount", "/system");

ui_print("Deleting temporary busybox");
delete("/tmp/busybox");
set_progress(1.000000);
show_progress(1.000000, 0);

ui_print("Root complete!");
ui_print("SuperSU 0.95 & Busybox 1.20.2");

After reading and playing around with adb I decided that I go for it
For strengthening my decision a checked if the MD5 matches and it matched
mike@mikembp:~/Downloads/android$ md5 root.zip
MD5 (root.zip) = 3d5cc207f625a032e7ff4fe92e3e6efa



Trying su after restart
shell@android:/ $ ll data/
opendir failed, Permission denied
1|shell@android:/ $ su
shell@android:/ # ll data/
-rw------- system   system       4096 2014-02-09 09:45 NVM0
-rw------- system   system      16384 2014-02-08 23:08 NVM1
-rw------- system   system       2832 2014-02-09 09:45 NVM13
-rw------- system   system          0 2013-11-14 06:33 NVM2
-rw------- system   system      83724 2014-02-08 22:46 NVM3
-rw------- system   system        112 2014-02-08 23:10 NVM5
-rw------- system   system          0 2013-11-14 06:33 NVM6
-rw-rw-rw- root     system   15032320 2014-02-08 20:35 adm.sqlite
-rw-rw-rw- root     system          0 2013-11-14 06:31 adm.sqlite-copy-datestamp-JB
drwxrwxr-x system   system            2014-02-03 13:53 anr
drwxrwx--x system   system            2014-02-09 07:43 app
drwx------ root     root              2014-02-07 12:27 app-asec
drwxrwx--x system   system            2014-02-07 12:26 app-private
drwx------ system   system            2014-02-09 09:45 backup
-rw------- system   system       2777 2014-02-09 09:55 cal.bin
drwxrwxr-x system   system            2014-02-09 07:37 clipboard
-rw-rw-rw- nobody   nobody      95613 2014-02-09 09:45 cops.log
drwxrwx--x system   system            2014-02-09 09:45 dalvik-cache
drwxrwx--x system   system            2014-02-09 09:44 data
drwxr-x--- root     log               2013-11-14 06:31 dontpanic
drwxrwx--- drm      drm               2013-11-14 06:31 drm
-rwxr--r-- system   system          8 2014-02-09 09:55 hidden_volume.txt
drwxr-x--x root     root              2013-11-14 06:31 local
drwxrwxr-x system   log               2014-02-09 09:55 log
drwxrwx--- root     root              1970-01-01 01:00 lost+found
drwxrwxr-x media_rw media_rw          2013-11-14 06:31 media
drwxrwx--t system   misc              2013-12-27 09:46 misc
drwxrwxrwx media    system            2013-11-20 14:27 mmdsp-SIA_2013-11-20_14-27-31_1384954051
drwx------ root     root              2014-02-09 09:45 property
drwxrwx--x system   system            2013-11-14 06:31 resource-cache
drwxr-x--- root     shell             2013-11-14 06:31 ssh
drwxrwxr-x system   system            2014-01-30 19:31 ste-debug
drwxrwxr-x system   system            2014-02-09 09:55 system
drwxr-xr-x system   system            2013-12-24 16:12 tombstones
drwx--x--x system   system            2013-11-14 06:31 user