Hacking Ubuntu Community Flavors on Nexus 7

With the recent launch of the testing images of Ubuntu on Nexus 7 there has been lots of interest and people have asked why Xubuntu, Lubuntu, Kubuntu etc were not selected simply put those are community flavors and this is a Canonical initiative so its really up to the Community to bring those flavors to the Nexus 7 if they so choose.

For those interested in testing other flavors on the Nexus 7 the first place to start might be to look at the script that is behind the Ubuntu One-Click Installer for Nexus 7 (below) and then go from their making your own image also this site has the .img files which the script currently uses.

#
# Chris Van Hoof <redacted@redacted.com>
#
# Desktop installer for the Galaxy Nexus 7
#
NOTICE_ACCEPTED=”$HOME/.${0##*/}.notice-accepted”
IMAGES=(boot.img rootfs.img)
CHECKSUM=”ubuntu-nexus7-sha256sum.txt”
SERVER=”http://hwe.ubuntu.com”
SERVER_PATH=”uds-r/nexus7″
XDG_DIRS=”$HOME/.config/user-dirs.dirs”
XDG_DOWNLOAD_DIR=”$HOME/Downloads”
if [ -f "$XDG_DIRS" ]; then
source $XDG_DIRS
fi
WORKDIR=”$XDG_DOWNLOAD_DIR/UbuntuNexus7″
usage_notice () {
if [ ! -e $NOTICE_ACCEPTED ];
then
zenity –ok-label=Agree –title “Ubuntu Nexus7 Usage Notice” \
–height 550 –width=515 \
–text-info \
–filename=/usr/share/doc/ubuntu-nexus7-installer/ubuntu-nexus7-USAGE-NOTICE-en.txt
RESPONSE=$?
if [ $RESPONSE -eq 0 ];
then
touch $NOTICE_ACCEPTED
return 0
else
return 1
fi
fi
}
checksum_images () {
sha256sum –check $WORKDIR/$CHECKSUM
if [ $? -eq 0 ];
then
return 0
else
zenity –error –title=”Ubuntu Nexus7 Installer” –text=”Downloaded images failed checksum validation”
return 1
fi
}
download_images () {
wget –progress=bar:force $SERVER/$SERVER_PATH/$VARIANT/$CHECKSUM -O $WORKDIR/$CHECKSUM 2&gt;&amp;1 |
zenity –title=”Ubuntu Nexus7 Installer” –text=”Downloading Ubuntu Nexus7 Checksum: $CHECKSUM” \
–progress –auto-close –auto-kill
wget –progress=bar:force $SERVER/$SERVER_PATH/$VARIANT/”${IMAGES[0]}” -O $WORKDIR/”${IMAGES[0]}” 2&gt;&amp;1 |
zenity –title=”Ubuntu Nexus7 Installer” –text=”Downloading Ubuntu Nexus7 Boot Image: ${IMAGES[0]}” \
–progress –auto-close –auto-kill
wget –progress=bar:force $SERVER/$SERVER_PATH/$VARIANT/”${IMAGES[1]}” -O $WORKDIR/”${IMAGES[1]}” 2&gt;&amp;1 |
zenity –title=”Ubuntu Nexus7 Installer” –text=”Downloading Ubuntu Nexus7 Root Filesystem Image: ${IMAGES[1]}” \
–progress –auto-close –auto-kill –percentage=5
}
mk_workdir () {
if [ ! -d $WORKDIR ];
then
mkdir -p $WORKDIR
return 0
fi
}
check_prior_download () {
if [ -f $WORKDIR/"${IMAGES[0]}” -a -f $WORKDIR/”${IMAGES[1]}” ];
then
return 1
else
return 0
fi
}
check_network () {
if [ ! -z "${SERVER}" ];
then
ping -c 1 “${SERVER##*/}”
if [ $? -eq 0 ];
then
return 0
else
zenity –warning –title=”Ubuntu Nexus7 Installer” –text=”Network connection not detected or ${SERVER##*/} is unreachable”
return 1
fi
fi
}
is_fastboot_installed () {
fb_installed=`which fastboot || true`
if [[ -z $fb_installed ]];
then
zenity –warning –title=”Ubuntu Nexus7 Installer” –text=”Fastboot not found:\n\nPlease ensure fastboot is in your PATH or the\nandroid-tools-fastboot package is installed”
return 1
else
return 0
fi
}
fastboot_device_found () {
fb=`sudo -Sp ” — fastboot devices &lt;&lt;&lt;”${SPW}”`
if [[ -z $fb ]];
then
zenity –warning –title=”Ubuntu Nexus7 Installer” –text=”Your tablet was not detected by fastboot:\n\nPlease ensure your tablet is connected via USB\nand boot into fastboot mode by holding down the\npower and volume down buttons”
return 1
else
return 0
fi
}
close_installer () {
zenity –warning –title=”Ubuntu Nexus7 Installer” –text=”Closing Ubuntu Nexus7 Installer”
}
# display usage notice
usage_notice
if [ $? -ne 0 ];
then
close_installer
exit 1
fi
# main
CHOICE=$(zenity –list \
–title=”Ubuntu Nexus7 Installer” \
–text=”Select your action” \
–width=300 \
–height=170 \
–radiolist \
–column=”" –column=”Option” \
FALSE “Install Ubuntu for Nexus7″ \
TRUE “Exit”)
case $CHOICE in
“Install Ubuntu for Nexus7″)
VARIANT=$(zenity –list \
–title=”Ubuntu Nexus7 Installer” \
–text=”Select the storage capacity of your Nexus7″ \
–width=300 \
–height=170 \
–radiolist \
–column=”" –column=”Storage Capacity” \
FALSE “16GB” \
TRUE “8GB”)
RESPONSE=$?
if [ "${RESPONSE}" == "1" ];
then
close_installer
exit 1
fi
zenity –title=”Ubuntu Nexus7 Installer” –question –text=”Welcome to the Ubuntu Nexus7 Installer\n\nThe installer will:\n * Download images suitable for running Ubuntu on the Galaxy Nexus7\n * Install the images on the device\n\n The download and flashing process will take a few minutes to complete.\n\nPlease connect your device in fastboot mode.\n\nReady to begin the installation?”
RESPONSE=$?
if [ "${RESPONSE}" == "1" ];
then
close_installer
exit 1
fi
# check for fastboot
is_fastboot_installed
if [ $? -ne 0 ];
then
close_installer
exit 1
fi
# create WORKDIR for download
mk_workdir
if [ $? -ne 0 ];
then
close_installer
exit 1
fi
# check for prior download
check_prior_download
if [ $? -eq 1 ];
then
zenity –title=”Ubuntu Nexus7 Installer” –question –text=”Previously downloaded images found\n\nWould you like to re-flash using these images?”
RESPONSE=$?
if [ "${RESPONSE}" == "0" ];
then
USE_EXISTING=”true”
else
USE_EXISTING=”false”
fi
else
USE_EXISTING=”false”
fi
# move over to WORKDIR for download
pushd $WORKDIR
if [ "${USE_EXISTING}" == "false" ];
then
# ensure network is up and begin download
check_network &amp;&amp; download_images
if [ $? -ne 0 ];
then
close_installer
exit 1
fi
fi
# checksum downloaded images
checksum_images
if [ $? -ne 0 ];
then
close_installer
exit 1
fi
# obtain sudo privs for fastboot
SPW=”$(gksudo –print-pass –message “Provide permission to execute: ${0##*/}” — : 2&gt;/dev/null)”
# check for null entry or cancel request
if [[ ${?} != 0 || -z ${SPW} ]]; then
zenity –error –title=”Ubuntu Nexus7 Installer” –text=”Password not specified”
close_installer
exit 1
fi
# check password validity
if ! sudo -kSp ” [ 1 ] &lt;&lt;&lt;”${SPW}” 2&gt;/dev/null; then
zenity –error –title=”Ubuntu Nexus7 Installer” –text=”Invalid password specified”
close_installer
exit 1
fi
# check for device
fastboot_device_found
if [ $? -ne 0 ];
then
close_installer
exit 1
fi
# begin flashing process
(
set -e
echo “0″; sleep 2
echo “# Begining Ubuntu Nexus7 installation”
echo “20″
echo “# Erasing boot partition”
sudo -Sp ” — fastboot erase boot &lt;&lt;&lt;”${SPW}”
echo “40″
echo “# Flashing boot partition”
sudo -Sp ” — fastboot flash boot ./boot.img &lt;&lt;&lt;”${SPW}”
echo “60″
echo “# Erasing userdata partition”
sudo -Sp ” — fastboot erase userdata &lt;&lt;&lt;”${SPW}”
echo “80″
echo “# Flashing Ubuntu root file system”
sudo -Sp ” — fastboot flash userdata ./rootfs.img &lt;&lt;&lt;”${SPW}”
echo “100″
echo “# Rebooting device”
sudo -Sp ” — fastboot reboot &lt;&lt;&lt;”${SPW}”
) |
zenity –auto-close –progress \
–title=”Ubuntu Nexus7 Installer” \
–text=”Flashing Ubuntu on the Nexus7″ \
–percentage=0
if [ ${PIPESTATUS[0]} -ne 0 ];
then
zenity –error –title=”Ubuntu Nexus7 Installer” –text=”Installation failed”
close_installer
exit 1
fi
zenity –info –title=”Ubuntu Nexus7 Installer” –text=”Nexus7 flashed with Ubuntu successfully\n\nIt will take several minutes for the root filesystem\nto be unpacked and installed after reboot”
# pop out of WORKDIR
popd
# invalidate sudo credentials
sudo -K
;;
“Exit”)
exit 0
;;
esac

 

Will you be attempting to hack a community flavor on your Nexus 7? What are your initial thoughts on Ubuntu on Nexus 7?

Comments

  1. gilir says

    I may be blind, but one piece is missing : the script which create the .img from a seed or a list of packages, or an ISO or anything. It sounds easy to customize the installer script to point to another flavor, but you need an .img of a flavor for this. Any documentation / link is welcome, as I’m very interested to generate a Lubuntu version for Nexus 7 :-)