Thursday, October 30, 2014

Assigning to a variable from a pipe in Z Shell

Unfortunately or sadly, this could not be done by me for my use case in Bash. I'm looking for a good solution in Bash too. Just to note here. To read from the pipe you just have to use the Read command. It only works this way in Zsh so far.
blkid $dev | sed -n 's/.*UUID=\"\([^\"]*\)\".*/\1/p' | read var;
Now you can easily use that $var in that scope like
echo $var

Z Shell, the fancy in Linux terminal

Z Shell is probably now the best known Shell option for Unix users all over the globe. That too contributed by the fact that most people take the Terminal they get as full and final and never give a second thought about it's improvement. But geeks can't resist exploring and the first option they get astounds them because Z Shell, if compared to Bash, is simple a super set of it's functionality. It gives us a great Terminal which is intelligent and customizable to the point where people might ask you "Which terminal is this?".

Installation: This is fairly simple. Just a quick apt-get
sudo apt-get install zsh
Configuration: After you have installed Z Shell, the very first thing you have to do launch is type in your terminal
zsh
The first you do this, you will get some configuration manual that is navigated using numbers. The procedures are very self explanatory. It helps you configure various Options such as
  • How far back in time do you want to remember commands
  • If you want the shell to search history using partially entered commands (It's neat and powerful)
  • Should all of your terminals be in sync while running
The whole configuration is saved into the file at '/home//.zshrc'.
After you have configured the shell, you can make it your default shell using the command
chsh  -s /bin/zsh

Configuration repositories: Some great configurations for Zsh have come up with full modular support and themes that will make your experience with Z a breeze. These are the most popular to repositories. There are some others that maintain Z shell configurations around the net.
Using these pre-built configurations is very easy. Such as, configuring with Prezto. You need to type in the following after launching Z Shell. The commands will create Z Shell configurations in your home directory.
git clone --recursive https://github.com/sorin-ionescu/prezto.git "${ZDOTDIR:-$HOME}/.zprezto"
setopt EXTENDED_GLOB
for rcfile in "${ZDOTDIR:-$HOME}"/.zprezto/runcoms/^README.md(.N); do
  ln -s "$rcfile" "${ZDOTDIR:-$HOME}/.${rcfile:t}"
done
This will simple clone the repository into your home folder and then, link the configurations in place of your current configurations.


Sunday, October 26, 2014

NodeJS permission issues troubleshooting path

It was such a terrifying experience to have node and especially yeoman not work because of weird permission issues. I fixed the issues finally and kind of think there's pattern to it. This is not a full and final cookbook type of thingy but you might wanna check this method out in case you are stuck with the same issues. First of all
1. If the problem is not in your project directory then it must me in your ~/.config and ~/.npm directories. As you may have seen many newbies of node opt to the sudo method of installing things. But this causes problem regarding permission when yeoman comes in as some of the commands need access to areas where root is not permitted and if you do not use sudo before yo, you get errors about some of the errors where you need root. This mess up is simply caused by sometimes using sudo and sometimes not. Which you have to do because you do not own the ~/.npm directory. Just own it using
sudo chown -R `whoami` ~/.npm
2. If the problem still persists, check your project directories node_modules directory if it has any subdirectory or file deep inside where access is needed it has root privileges required. So you can use the same owning method there too
sudo chown -R `whoami` ~/.npm
3. Always try to install non globally. This will save you a lot of trouble.

Credits: Stackoverflow [ http://stackoverflow.com/questions/16151018/npm-throws-error-without-sudo ]

Saturday, October 25, 2014

When 'chsh' simple does not work

I got into this problem lately in a Live environment of the new Ubuntu MATE release where no matter how many times I change the password using 'sudo passwd' it simply does not effect 'chsh'. So, when I type in
chsh -s /usr/bin/zsh
It asks for the password. And when I type the password in, it does not work. It simply says "PAM: Authentication Failure". Ok, so go for Googling. Later, I found out that all user 'home' and 'shell' infos are stored in a file located by '/etc/passwd'. Now you need root to do this. So how do you get root? For a Live system, that's simple. just type in
sudo -i
It should give you the '#' prompt so you're root now. Now just open the file using your favorite editor like
nano /etc/passwd
Then find your user name and change the string right after the last ':' on that line. Done. Reboot and go. For now, I seriously don't know why 'chsh' didn't work. :( anybody have any clues?

Sunday, August 31, 2014

Change FAT / NTFS file attributes from Linux

The original use case was born for me when one of my friends gave me a memory card that was infected by the 'hidden file' virus (he calls it so). All of the files were applied the +S +H +R attributes which made the file System file, Hidden and Read only respectively. For this reason he could not see them in his cell phone which depended on this attributes (Nokia Symbian OS).
I personally don't like to work with Microsoft born tools, so instead of booting into my Windows 7 installation (I usually never do that), I wanted to find a way that allowed me to change these attributes right from my Linux installation. There it came, the awesome 'mtools' toolset.

To change the file attributes, you first need to switch into that directory (which points to the card). But the mtools have a catch. They do not let you work with them, unless you ignore some errors. And to instruct it to do so, you have to make an RC file that will do just that right before one of tools takes any actions. The location of the RC file will be
~/.mtoolsrc
or
/home/<user>/.mtoolsrc
The contents have to be
drive s: file="/dev/<your-usb-drive>"
mtools_skip_check=1
The significance of the first line is, it assigns the directory into drive S. it could be anything else, like C, D, E etc. The second line tells mtools to check for some errors, it has to be set to not check because otherwise it refuses to operate on the drive (please don't look at me, I just copied it from somewhere)
Then change into your drive
$ mattrib -/ s:
And change the attributes (actually unset them) for all the files
$ mattrib -/ -h -s -r s:
That's it :)

Credits due:
http://blogs.gnome.org/diegoe/2012/04/21/removing-the-hiddensystem-bit-of-vfatfat32-files-on-gnulinux/

Tuesday, August 12, 2014

Running Counter Strike Source on Linux (native version)

CAUTION: Try this only if you face any problem running the game(s).
Well, it's great news that companies are now releasing Linux version of many games including Valve. They've already made Portal, Half Life and Counter Strike: Source available on Linux. But running them is sometimes a bit tricky mainly when CPU architectures mismatch. I have a 64bit setup while the copy I was trying to run was 32 bit so some libraries were reported to be missing when what it actually meant was, the 32 bit versions were missing. A little bit of research goes a long way.
1. First execute this command in you Counter Strike: Source installation directory (cd into it)
LD_LIBRARY_PATH=bin ldd bin/vguimatsurface.so | grep found
This should tell you exactly which libraries are missing
2. To give you an idea about exactly what is going to happen with the next command, these are the libraries that are need to be installed
lib32-fontconfig lib32-gtk2 lib32-libxi lib32-nss lib32-libpng12 lib32-alsa-lib lib32-pango lib32-cairo lib32-sdl2
So, to install them, type these in your terminal
libfontconfig1:i386
libgtk2.0-0:i386
libnss3:i386   
References:
1. https://bbs.archlinux.org/viewtopic.php?id=169422
2. Torrent page on The Pirate Bay

Monday, July 21, 2014

Some useful Apache web server commands

These are mostly for reference, to find the ones I use the most
Enable module: a2enmod vhost_alias
Enable site: a2ensite vhosts_alias
List enabled modules: apache2ctl -M

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...