Uploading music to Google Play Music from the command line using gmusicapi

I’ve always found uploading my music to Google Play Music a pain using their tools to be a pain. Luckily you can do it via your CLI!

Install gmusicapi-wrapper:
pip3 install docopt gmusicapi-wrapper

Download the gmusicapi script to upload our music (supports .mp3, .flac, .m4a, .ogg):
wget https://raw.githubusercontent.com/thebigmunch/gmusicapi-scripts/master/gmusicapi_scripts/gmupload.py

Run the gmupload script:
./gmupload.py songname.mp3

For even easier use (access the script from anywhere):
mv gmupload.py /usr/local/bin/gmupload

gmupload songname.mp3

Please note, on the first time running this you will need to follow the link provided by the script to insert your authentication key into terminal.

For specific usage of the script have a look at the documentation here

Using mkisofs to create an ISO from a folder on OSX

Quick tip, if you’re wanting to make a CD-style ISO file from a folder.

We can use mkisofs via the command line, to get it you need to install the cdrtools package.

On OSX:
brew install cdrtools

It should be available on other distributions under the same name.

To generate the ISO:
mkisofs -V CDNAME -J -r -o /path/to/output.iso /path/to/folder

Deleting old messages in iMessage/Messages application on OSX

If you’re trying to reclaim some disk space, years of old messages and associated attachments can easily consume several gigabytes. I recently tried to find out how to delete my old iMessages… unfortunately for some reason Apple makes this more difficult than it should be, without any obvious ways to do it.

The first thing to do is to close the Messages app. Then delete the contents of the Messages folder:

~/Library/Messages

I restarted my computer and all the old messages were now gone. However, a few weeks later while doing a spotlight search, I noticed that a few old conversations began to show up in these searches. Odd, I thought I had deleted everything. I later found out that older messages seem to be archived elsewhere. I also deleted the contents of the following folder, and the messages were now gone.

~/Library/Containers/com.apple.iChat/Data/Library/Messages/Archive

Compressing old logfiles into a single tar archive

This is something that has bothered me. Having tens of thousands of logfiles (especially with backup solutions that are sensitive of the number of files) has become a bit of a problem.

After a bit of googling, I came across this question on stackexchange – full credit to the users there for this tip.

From outside the directory that contains the logfiles:

find /home/user/logs/ -mtime +1 | xargs tar -czvPf /home/user/old_logs_$(date +%F).tar.gz

mtime +1 refers to a file having not been modified for one day. This can of course be changed as your use case requires.

Finally, to delete the files older than one day:

find /home/user/logs/ -mtime +1 -delete

Another useful tip I use to create tar .bz2 files for each year. The logfiles are in format YYYY-, hence the 2012* wildcard.

find * -name "2012*" | tar -cvjSf logs-2012.tar.bz2 -T -

find . -name "2012*" -delete

Enabling https SSL connection with The Lounge self-hosted IRC client

Please note: This is the same as https://nertant.com/2016/02/05/enabling-https-ssl-connection-with-the-shout-self-hosted-irc-client/ but updated for the more up-to-date fork called The Lounge.

The Lounge is a great self-hosted IRC client, similar to IRCCloud. Unfortunately it only supports http straight out of the box and enabling https is not documented. Here’s how to enable it.

First you should stop lounge.

Make a directory for our SSL certificate:

cd .lounge
mkdir ssl

Generate our SSL certificate:

openssl genrsa 1024 > key.pem
openssl req -x509 -new -key key.pem > key-cert.pem

Let’s edit our lounge config file to enable https and tell lounge where our SSL certificate is located.

nano .configjs

Find the section:

https: {

Change:

enable: false, to enable: true and populate the key and certificate fields:

key: "/home/nertant/.lounge/ssl/key.pem",

certificate: "/home/nertant/.lounge/ssl/key-cert.pem"

My config file looks like:

https: {
//
// Enable HTTPS support.
//
enable: true,
key: "/home/nertant/.lounge/ssl/key.pem",
certificate: "/home/nertant/.lounge/ssl/key-cert.pem"

Start lounge.

lounge start

lounge is now accessible from https. Since the SSL certificate is self-signed, your browser will likely present a warning when trying to access lounge. This can be disregarded for most personal uses. If your lounge instance is accessible by many people, it’s probably a good idea to use a paid SSL certificate to prevent seeing the warning message in the browser.

Setting up unattended upgrades for security on Debian

With the recent spate of vulnerabilities in popular Linux packages, I figured it was time to enable automatic updating of packages to ensure my servers are secure, even when I’m not there to manually update them. On Debian, setting up unattended upgrades is trivial.

The following commands need to be run with escalated privileges: sudo or root.

apt-get install unattended-upgrades
dpkg-reconfigure unattended-upgrades

Select yes after the last command and your system should now automatically upgrade to the latest packages (and hopefully be a bit more secure).

There are more advanced configurations and options to exclude certain packages from automatically updating. I recommend looking here and here if that suits your use case.

Enabling https SSL connection with the shout self-hosted IRC client

Shout is a great self-hosted IRC client, similar to IRCCloud. Unfortunately it only supports http straight out of the box and enabling https is not documented. Here’s how to enable it.

First you should stop shout.

Make a directory for our SSL certificate:

cd .shout
mkdir ssl

Generate our SSL certificate:

openssl genrsa 1024 > key.pem
openssl req -x509 -new -key key.pem > key-cert.pem

Let’s edit our shout config file to enable https and tell shout where our SSL certificate is located.

nano .configjs

Find the section:

https: {

Change:

enable: false, to enable: true and populate the key and certificate fields:

key: "/home/nertant/.shout/ssl/key.pem",

certificate: "/home/nertant/.shout/ssl/key-cert.pem"

My config file looks like:

https: {
//
// Enable HTTPS support.
//
enable: true,
key: "/home/nertant/.shout/ssl/key.pem",
certificate: "/home/nertant/.shout/ssl/key-cert.pem"

Start shout.

shout start

Shout is now accessible from https. Since the SSL certificate is self-signed, your browser will likely present a warning when trying to access shout. This can be disregarded for most personal uses. If your shout instance is accessible by many people, it’s probably a good idea to use a paid SSL certificate to prevent seeing the warning message in the browser.

Upgrading rsync 2.6.9 on Mac OSX to a modern version

Unfortunately due to Apple not liking the GPL 3 license, many of the popular command line tools on OSX are now years out of date, and even broken in the case of certain uses of rsync. If rsync is a tool you use regularly then I definitely recommend upgrading it using the following steps.

First we get the source, the patches for OSX and expand everything to the same directory.

cd ~/Downloads
wget http://rsync.samba.org/ftp/rsync/rsync-3.1.0.tar.gz
tar -xzvf rsync-3.1.0.tar.gz
cd rsync-3.1.0
wget http://rsync.samba.org/ftp/rsync/rsync-patches-3.1.0.tar.gz
tar -xzvf rsync-patches-3.1.0.tar.gz

Apply the various patches.

patch -p1 <patches/fileflags.diff
patch -p1 <patches/crtimes.diff
patch -p1 <patches/hfs-compression.diff

Configure, make and install
./prepare-source
./configure
make
sudo make install

The last step is to update the path so that when you issue ‘rsync’ it uses the new version we just installed. Using your favourite editor, edit /private/etc/paths to make sure that /usr/local/bin is ahead of /usr/bin on the descending list of paths.

That’s it. Run rsync –version to make sure it worked.

Using Icecast2 and IceGenerator to create MP3 radio stream on Debian 6 & 7

This is a quick and easy way to create your own internet radio stream. By using two bits of lightweight software and MP3 files on your server, you will be able to create a stream that can be accessed from anywhere in the world. We will be using Icecast2 and IceGenerator to feed a playlist of MP3s to Icecast.

First install icecast2.

apt-get update
apt-get install icecast2

Icecast should now display a warning that you must edit a file before it will start working. We can fix this up after we have set the passwords for icecast

sudo nano /etc/icecast2/icecast.xml

You can go through and edit this as you wish. There are two main areas that are essential, though most can be left alone.

  • Change all the passwords under <authentication> – source, relay and admin.
  • You then need to change the mountpoint under <shoutcast-mount> to your personal preference.<shoutcast-mount>/radiostream.mp3</shoutcast-mount> for instance would allow you to access your radio stream from your URL:8000/radiostream.mp3. Note the.mp3 extension for mount points is not required. You can also change the default port from 8000 if you wish to do so.

Now that we have changed the passwords and Icecast is secure, let’s fix that warning message we received when installing it.

sudo nano /etc/default/icecast2

Go right down to the bottom and replace ENABLE=false with ENABLE=true

Now we can start Icecast

sudo /etc/init.d/icecast2 start

Now go to your URL:8000 or IP:8000 in a web browser to ensure that the Icecast web interface is working.

Now we install IceGenerator to feed Icecast the MP3 file playlist.

wget http://www.becrux.com/pages/projects/icegenerator/icegenerator-0.5.5-pre2.tar.gz
tar -xzvf icegenerator*
cd icegenerator*
sudo ./configure
sudo make
sudo make install

A configuration file needs to be created. Use nano to create config.txt in your home folder/icegenerator directory and paste in the following config file example.

cd $home
mkdir icegenerator
cd icegenerator
nano config.txt

NAME=Name of Streaming Server

IP=127.0.0.1
PORT=8000
# 2 – Icecast 2.0 (HTTP protocol compatible)
SERVER=2
SOURCE=source
PASSWORD=passwordofsource
FORMAT=1
RECURSIVE=1
DUMPFILE=
LOOP=1
SHUFFLE=1
BITRATE=48000
PUBLIC=0
METAUPDATE=5
MDFPATH=/myhomefolder/icecast/global.mdf
LOG=2
LOGPATH=/myhomefolder/icecast/icegenerator.log
DATAPORT=8796

#######################################################

MOUNT=/radiostream

MP3PATH=m3u:/myhomefolder/icecast/music.m3u

GENRE=Type of Music

DESCRIPTION=Radio Description

URL=http://MyURL:8000/radiostream

Now enter the following command

find /path/to/mp3s/ | grep .mp3 > music.m3u

OR alternatively in the above configuration file set

MP3PATH=pth://path/to/mp3s

That’s it!

Run the following (note you may need to use sudo)

icegenerator -f /pathtohomefolder/icegenerator/config.txt

You should now be able to use your web browser/media device/software such as VLC to access your stream at http://yourURL:8000/radiostream

Common problems (if things don’t work)

  • Check all your paths in the IceGenerator config.txt to see that the files they are referencing are in the right place
  • Ensure the ‘source’ password in the IceGenerator config.txt match the one that was set in the Icecast configuration file
  • Check the logfile for IceGenerator (location set in IceGenerator config.txt)

The following tutorials/information provided inspiration and example configuration files and can be used for further reference