Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

February 7, 2015

Installing PHP Composer globally on Mac & Linux

Composer is a dependency manager for PHP. PEAR used to be the go-to tool for managing PHP dependencies quite some time ago, but it was always cumbersome, and not much fun to use. Composer makes it very easy!

Installing Composer is easy on Mac or Linux:
curl -sS https://getcomposer.org/installer | php

If you want to run it globally, simply move and rename the downloaded .phar file:
mv composer.phar /usr/local/bin/composer

It might even be possible to set it all up in a single command, though I cannot test it right now:
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

You can now run the composer command from anywhere in your shell.

composer
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 1.0-dev

September 4, 2014

How to set up a private Git server on a Raspberry Pi (or any Linux-based OS, really)

Paying for private Git space sucks. And sometimes some code is really not worth putting out onto the greater web, or really doesn't need to be up there. The solution is to privately host your repository!

A Raspberry Pi is a super cheap, small, power-effective computer, excellently re purposed as a Git server. Start by installing some dependencies - chances are, if you're running Raspbian, you may already have these.
sudo apt-get install wget git-core

It is good practice to set up a dedicated system user, in this case we are calling the user git with a home folder location at /home/git
sudo adduser --system --shell /bin/bash -gecos 'Raspberry Pi Git user' --group --home /home/git git

Enter the user's home folder, and initialize a new bare git repository:
su git
cd /home/git
mkdir newrepo.git
cd newrepo.git
git --bare init

And your Pi is now set up with a shiny new repository, ready to accept some files!

Return to your host machine, and go to the root of the new project that is about to get pushed to the new repository. At this point, it is a good idea to check your .gitignore file to make sure you aren't about to push stuff that shouldn't be version-controlled. Replace the IP address below as needed; or better yet, hostname if that is set up (mine is just running on my local network). We will now tell our host machine where to push to, then will commit the project, and actually push it:
git init
git remote add origin git@192.168.0.xx:/home/git/newrepo.git
git add .
git commit -m "First commit"
git push origin master

If, like me, you already had a git work tree set up, but the old repository is now defunct, you can instead just change the repo location like this:
git remote set-url origin git@192.168.0.xx:/home/git/newrepo.git
git push origin master

This will retain your entire git history, even though you may previously have been pushing to a different repository. If you had the entire history checked out locally before your switchover, that history will be uploaded to the new location as well.

Finally, as a last quality-of-life tweak, upload your public SSH key to your remote user's ~/.ssh/authorized_keys file. This stops the annoying password prompts during every push, but is just as secure.

Lastly, back on the host machine, it might be worth setting Git's case-sensitivity off via git config core.ignorecase false.

April 28, 2014

Bash shell: Incremental history searching

From using Git, Linux/Ubuntu apt-repositories, or general Bash folder navigation, you may have noticed that pushing the tab button halfway through typing an item/folder name will autocomplete it if it exists. Similarly, we can build an autocomplete feature for user commands that have been entered in the past! They are obviously stored in history somewhere, because you can already chronologically "scroll" through every single command you've issued, or just see it all by entering history. It would be nice to have a quick way to access something specific, complex or lengthy, especially if you already know how it starts.

All you need to do to find a previous command, is to start entering the first few letters of it, then you can navigate all commands you previously issued that started with your entered phrase, by using the up/down arrows! Here's how you set it up:

In terminal, open or create:
gedit  ~/.inputrc

Copy/paste the following there, and save (you may also have to close and reopen a terminal, or reload this way):
"\e[A": history-search-backward
"\e[B": history-search-forward
"\e[C": forward-char
"\e[D": backward-char

And done! Now, for example, if I am now looking for the command...
sudo apt-get update

...all I need to do is enter the first few letters, something like...
sud

...and scrolling up/down through my now-selective bash history will allow me to easily locate the command in its entirety for use again!

Adapted from: Ubuntu User Community

April 1, 2014

Windows/Mac/Linux filesharing from Synology NAS accounts

This is really simple to do, but ties in with setting up proper user accounts and permissions. Remember setting up user accounts and permissions? On the final application page, check what is necessary. I have a need for all these services on this particular user account:


Now we need to actually enable file sharing with our operating system. In most cases this should already be filled in, but if it is not, take a look at Control Panel -> File Services:


Since I'm using Windows, I don't presently have a need for Mac File Service, so let's disable that for now.

You should now be able to access your NAS from Windows' Network, and should see it listed as a "computer" along with all the other devices on the network.