Installing Sailfish OS on Motorola Moto G 2013 (falcon)

These are the instructions are for the Motorola Moto G 2013. It has one of the most complete community ports of Sailfish and virtually all of the hardware is usable. The phone can be bought for around C$100 and is powerful enough to run the OS. As this is a community port, it does not have some of the proprietary bits bits that can be found on official Sailfish phones such as the Jolla phones. The most obvious of which is the Android run-time. So you will not be able to run Android apps after installing the Sailfish OS.
Keep in mind that this process will delete all data on your phone as well as void warranty!

Obtaining the files

To install Sailfish you need the following files:

Testing connection

You should be able to see your device now by typing:
adb devices

Unlocking the bootloader

The bootloader needs to be unlocked so that alternative OSes can be installed. This unlocking is what voids your warranty. It cannot be undone.
You will need a Motorola account for this to register your phone and obtain the unlocking code. Go to Motorola Support now to get your unlock code. You will also get the instructions there to unlock the bootloader, but in brief, the steps are: get the unlock key from your phone, paste that code in Motorola's form, agree to the licence and voiding of warranty, retrieve the unlock code by e-mail, and unlock the phone bootloader.

Installing TWRP

Now that your phone is free, you can install TWRP which is required to install both CyanogenMod and Sailfish OS. First get your phone in fastboot mode by typing
adb reboot bootloader
Then install the img file you just downloaded using fastboot by typing:
fastboot flash recovery twrp-3.1.0-0-falcon.img
Version shouldn't really matter, just use what you downloaded. After flashing has completed, reboot by typing
fastboot reboot
The phone should now boot into TWRP. Alternatively, you can power down the phone and next hold the power button and volume down button for 2 to 3 seconds and let go.

Installing CyanogenMod

To install CyanogenMod 12.1, you may need to upgrade your bootloader as 12.1 requires are least version 41.18. You should be good if you upgraded the stock Android on your phone before you unlocked it. Otherwise, you can manually upgrade the bootloader. You can flash it by typing
fastboot flash boot motoboot_411A_xt1032.img
Afterwards, reboot your phone again by typing
fastboot reboot
Then copy CyanogenMod over by copying the zip file over to your phone by typing
adb push cm-12.1-20160418-UNOFFICIAL-falcon.zip /sdcard
Then in TWRP on your phone, first wipe everything by tapping "Wipe" and then swipe to wipe. After that, click on "Install" and select the file "cm-12.1-20160418-UNOFFICIAL-falcon.zip" you just copied over.

Installing Sailfish OS

The procedure is the same as for CyanogenMod. So copy over the Sailfish OS file by typing
adb push sailfishos-falcon-release-2.0.2.51-pgz21.zip /sdcard
Then in TWRP, tap "Install" select "sailfishos-falcon-release-2.0.2.51-pgz21.zip". You can now reboot the phone and it should boot into Sailfish OS.

Fixing some stuff

GPS

GPS may not work if you have never used GPS before installing Sailfish. This seems to be due to CyanogenMod somehow. The solution seems to be to use the GPS in the original firmware of the Moto G 2013 to get a satellite lock. Once you have a lock, install CyanogenMod and then Sailfish.

Camera

The camera app is a bit wonky. To get it working, start the app and wait until you get the not-responding message. Close the app and start it again. The camera should just work now. You will need to do this after every reboot of the phone.

Fix repositories

To get pkcon to work, you need to disable the adaption0 repository. To do so, open the Terminal app and type
ssu dr adaptation0
pkcon refresh
And now for zypper:
devel-su zypper mr -d adaptation0
devel-su zypper ref -f
The devel-su is needed because zypper requires root access. The password can be found and set under Settings -> Developer Mode.

Browser crashes when playing video

You need to install a missing library. To fix this, go to Settings, Untrusted software, and enable the checkbox for "Allow Untrusted software". Then download the missing library here. You can install it simply by opening the file. You can disable the check box for untrusted software now. After restarting your browser, you should be able to play videos.

Volume control

When playing videos in the browser, the volume button does not change the volume for the browser, but rather changes the ring tone volume. You can change the volume buttons to always refer to media and not ring tone by opening the Terminal app and typing
dconf write /jolla/sound/force_mediavolume true
Now the volume buttons will always change the media volume. Use the ambiances to control ring tone volume instead.

CA certificates

If you have any CA certificates you like to install, then become root and copy them to "/etc/pki/ca-trust/source/anchors/". Then run the following command:
update-ca-trust
You will need to reboot afterwards.

CalDAV and CardDAV with ownCloud

To get calendar sharing to work with ownCloud, go to Setting, Accounts, Add account. Then choose "CalDAV and CardDAV". Fill in your username, password. As the server address, put in the full ownCloud calendar URL, the is: "https://example.com/owncloud/remote.php/caldav" or wherever you installed owncloud on your server. Then untick the CardDAV check box.
To get also get contacts sharing to work, make a new account. The URL is now "https://example.com/owncloud/remote.php/carddav" and you need to uncheck the box for CalDAV.

Eduroam

To get Eduroam to work with PEAP-MSCHAPv2, you need to save the following in "/var/lib/connman/wifi_eduroam.config":
[service_eduroam]
Type=wifi
Name=eduroam
EAP=peap
CACertFile=/etc/ssl/certs/organisation_root_certificate.cer
Phase1=0
Phase2=MSCHAPV2
Identity=your university e-mail here
Passphrase=your password here