<commit_before>#!/bin/sh -e
export LC_ALL=C

chromium_release="chromium-32.0.1700.76"

#chroot_cloud9_git_tag="v2.0.93"
node_prefix="/usr"
#node_release="0.8.26"
#node_build_options="--without-snapshot --shared-openssl --shared-zlib --prefix=${node_prefix}"
node_release="0.10.24"
node_build_options="--without-snapshot --shared-cares --shared-openssl --shared-zlib --prefix=${node_prefix}"

user_name="debian"

. /.project

is_this_qemu () {
	unset warn_qemu_will_fail
	if [ -f /usr/bin/qemu-arm-static ] ; then
		warn_qemu_will_fail=1
	fi
}

qemu_warning () {
	if [ "${warn_qemu_will_fail}" ] ; then
		echo "Log: (chroot) Warning, qemu can fail here... (run on real armv7l hardware for production images)"
		echo "Log: (chroot): [${qemu_command}]"
	fi
}

git_clone () {
	mkdir -p ${git_target_dir} || true
	qemu_command="git clone ${git_repo} ${git_target_dir} --depth 1 || true"
	qemu_warning
	git clone ${git_repo} ${git_target_dir} --depth 1 || true
	sync
	echo "${git_target_dir} : ${git_repo}" >> /opt/source/list.txt
}

system_patches () {
	#For when sed/grep/etc just gets way to complex...
	cd /
	if [ -f /opt/scripts/mods/debian-add-sbin-usr-sbin-to-default-path.diff ] ; then
		patch -p1 < /opt/scripts/mods/debian-add-sbin-usr-sbin-to-default-path.diff
	fi
}

setup_xorg () {
	if [ -d /etc/X11/ ] ; then
		echo "Section \"Monitor\"" > /etc/X11/xorg.conf
		echo "        Identifier      \"Builtin Default Monitor\"" >> /etc/X11/xorg.conf
		echo "EndSection" >> /etc/X11/xorg.conf
		echo "" >> /etc/X11/xorg.conf
		echo "Section \"Device\"" >> /etc/X11/xorg.conf
		echo "        Identifier      \"Builtin Default fbdev Device 0\"" >> /etc/X11/xorg.conf
		echo "        Driver          \"modesetting\"" >> /etc/X11/xorg.conf
		echo "        Option          \"SWCursor\"      \"true\"" >> /etc/X11/xorg.conf
		echo "EndSection" >> /etc/X11/xorg.conf
		echo "" >> /etc/X11/xorg.conf
		echo "Section \"Screen\"" >> /etc/X11/xorg.conf
		echo "        Identifier      \"Builtin Default fbdev Screen 0\"" >> /etc/X11/xorg.conf
		echo "        Device          \"Builtin Default fbdev Device 0\"" >> /etc/X11/xorg.conf
		echo "        Monitor         \"Builtin Default Monitor\"" >> /etc/X11/xorg.conf
		echo "        DefaultDepth    16" >> /etc/X11/xorg.conf
		echo "EndSection" >> /etc/X11/xorg.conf
		echo "" >> /etc/X11/xorg.conf
		echo "Section \"ServerLayout\"" >> /etc/X11/xorg.conf
		echo "        Identifier      \"Builtin Default Layout\"" >> /etc/X11/xorg.conf
		echo "        Screen          \"Builtin Default fbdev Screen 0\"" >> /etc/X11/xorg.conf
		echo "EndSection" >> /etc/X11/xorg.conf
	fi
}

setup_autologin () {
	if [ -f /etc/lightdm/lightdm.conf ] ; then
		sed -i -e 's:#autologin-user=:autologin-user='$user_name':g' /etc/lightdm/lightdm.conf
		sed -i -e 's:#autologin-session=UNIMPLEMENTED:autologin-session=LXDE:g' /etc/lightdm/lightdm.conf
	fi

	if [ -f /etc/slim.conf ] ; then
		echo "#!/bin/sh" > /home/${user_name}/.xinitrc
		echo "" >> /home/${user_name}/.xinitrc
		echo "exec startlxde" >> /home/${user_name}/.xinitrc
		chmod +x /home/${user_name}/.xinitrc

		#/etc/slim.conf modfications:
		sed -i -e 's:default,start:startlxde,default,start:g' /etc/slim.conf
		echo "default_user        ${user_name}" >> /etc/slim.conf
		echo "auto_login        yes" >> /etc/slim.conf
	fi
}

install_desktop_branding () {
	#FixMe: move to github beagleboard repo...
	wget --no-verbose --directory-prefix=/opt/ http://rcn-ee.net/deb/testing/beaglebg.jpg
	chown -R ${user_name}:${user_name} /opt/beaglebg.jpg

	mkdir -p /home/${user_name}/.config/pcmanfm/LXDE/ || true
	echo "[desktop]" > /home/${user_name}/.config/pcmanfm/LXDE/pcmanfm.conf
	echo "wallpaper_mode=1" >> /home/${user_name}/.config/pcmanfm/LXDE/pcmanfm.conf
	echo "wallpaper=/opt/beaglebg.jpg" >> /home/${user_name}/.config/pcmanfm/LXDE/pcmanfm.conf
	chown -R ${user_name}:${user_name} /home/${user_name}/.config/

	#Disable LXDE's screensaver on autostart
	if [ -f /etc/xdg/lxsession/LXDE/autostart ] ; then
		cat /etc/xdg/lxsession/LXDE/autostart | grep -v xscreensaver > /tmp/autostart
		mv /tmp/autostart /etc/xdg/lxsession/LXDE/autostart
		rm -rf /tmp/autostart || true
	fi
}

dogtag () {
	echo "BeagleBoard.org BeagleBone Debian Image ${time}" > /etc/dogtag
}

build_node () {
	mount -t tmpfs shmfs -o size=256M /dev/shm
	#df -Th

	cd /opt/source
	wget http://nodejs.org/dist/v${node_release}/node-v${node_release}.tar.gz
	tar xf node-v${node_release}.tar.gz
	cd node-v${node_release}
	./configure ${node_build_options} && make -j5 && make install
	cd /
	rm -rf /opt/source/node-v${node_release}/ || true
	rm -rf /opt/source/node-v${node_release}.tar.gz || true
	echo "node-v${node_release} : http://rcn-ee.net/pkgs/nodejs/node-v${node_release}.tar.gz" >> /opt/source/list.txt

	echo "debug: node: [`node --version`]"
	echo "debug: npm: [`npm --version`]"

	echo "debug: npm config ls -l"
	npm config ls -l

	#echo "Installing bonescript"
	#NODE_PATH=${node_prefix}/lib/node_modules/ npm install -g bonescript --arch=armhf

	sync
	umount -l /dev/shm || true
}

install_builds () {
	cd /opt/
	wget http://rcn-ee.net/pkgs/chromium/${chromium_release}-armhf.tar.xz
	tar xf ${chromium_release}-armhf.tar.xz -C /
	rm -rf ${chromium_release}-armhf.tar.xz || true
	echo "${chromium_release} : http://rcn-ee.net/pkgs/chromium/${chromium_release}.tar.xz" >> /opt/source/list.txt

	#link Chromium to /usr/bin/x-www-browser
	update-alternatives --install /usr/bin/x-www-browser x-www-browser /usr/bin/chromium 200
}

install_repos () {
	git_repo="git://github.com/ajaxorg/cloud9.git"
	git_target_dir="/opt/cloud9"
	if [ "x${chroot_cloud9_git_tag}" = "x" ] ; then
		git_clone
	else
		mkdir -p /opt/cloud9/ || true
		qemu_command="git clone --depth 1 -b ${chroot_cloud9_git_tag} ${git_repo} ${git_target_dir} || true"
		qemu_warning<commit_msg>bb.org: fix? npm<commit_after>#!/bin/sh -e
export LC_ALL=C

chromium_release="chromium-32.0.1700.76"

#chroot_cloud9_git_tag="v2.0.93"
node_prefix="/usr"
#node_release="0.8.26"
#node_build_options="--without-snapshot --shared-openssl --shared-zlib --prefix=${node_prefix}"
node_release="0.10.24"
node_build_options="--without-snapshot --shared-cares --shared-openssl --shared-zlib --prefix=${node_prefix}"

user_name="debian"

. /.project

is_this_qemu () {
	unset warn_qemu_will_fail
	if [ -f /usr/bin/qemu-arm-static ] ; then
		warn_qemu_will_fail=1
	fi
}

qemu_warning () {
	if [ "${warn_qemu_will_fail}" ] ; then
		echo "Log: (chroot) Warning, qemu can fail here... (run on real armv7l hardware for production images)"
		echo "Log: (chroot): [${qemu_command}]"
	fi
}

git_clone () {
	mkdir -p ${git_target_dir} || true
	qemu_command="git clone ${git_repo} ${git_target_dir} --depth 1 || true"
	qemu_warning
	git clone ${git_repo} ${git_target_dir} --depth 1 || true
	sync
	echo "${git_target_dir} : ${git_repo}" >> /opt/source/list.txt
}

system_patches () {
	#For when sed/grep/etc just gets way to complex...
	cd /
	if [ -f /opt/scripts/mods/debian-add-sbin-usr-sbin-to-default-path.diff ] ; then
		patch -p1 < /opt/scripts/mods/debian-add-sbin-usr-sbin-to-default-path.diff
	fi
}

setup_xorg () {
	if [ -d /etc/X11/ ] ; then
		echo "Section \"Monitor\"" > /etc/X11/xorg.conf
		echo "        Identifier      \"Builtin Default Monitor\"" >> /etc/X11/xorg.conf
		echo "EndSection" >> /etc/X11/xorg.conf
		echo "" >> /etc/X11/xorg.conf
		echo "Section \"Device\"" >> /etc/X11/xorg.conf
		echo "        Identifier      \"Builtin Default fbdev Device 0\"" >> /etc/X11/xorg.conf
		echo "        Driver          \"modesetting\"" >> /etc/X11/xorg.conf
		echo "        Option          \"SWCursor\"      \"true\"" >> /etc/X11/xorg.conf
		echo "EndSection" >> /etc/X11/xorg.conf
		echo "" >> /etc/X11/xorg.conf
		echo "Section \"Screen\"" >> /etc/X11/xorg.conf
		echo "        Identifier      \"Builtin Default fbdev Screen 0\"" >> /etc/X11/xorg.conf
		echo "        Device          \"Builtin Default fbdev Device 0\"" >> /etc/X11/xorg.conf
		echo "        Monitor         \"Builtin Default Monitor\"" >> /etc/X11/xorg.conf
		echo "        DefaultDepth    16" >> /etc/X11/xorg.conf
		echo "EndSection" >> /etc/X11/xorg.conf
		echo "" >> /etc/X11/xorg.conf
		echo "Section \"ServerLayout\"" >> /etc/X11/xorg.conf
		echo "        Identifier      \"Builtin Default Layout\"" >> /etc/X11/xorg.conf
		echo "        Screen          \"Builtin Default fbdev Screen 0\"" >> /etc/X11/xorg.conf
		echo "EndSection" >> /etc/X11/xorg.conf
	fi
}

setup_autologin () {
	if [ -f /etc/lightdm/lightdm.conf ] ; then
		sed -i -e 's:#autologin-user=:autologin-user='$user_name':g' /etc/lightdm/lightdm.conf
		sed -i -e 's:#autologin-session=UNIMPLEMENTED:autologin-session=LXDE:g' /etc/lightdm/lightdm.conf
	fi

	if [ -f /etc/slim.conf ] ; then
		echo "#!/bin/sh" > /home/${user_name}/.xinitrc
		echo "" >> /home/${user_name}/.xinitrc
		echo "exec startlxde" >> /home/${user_name}/.xinitrc
		chmod +x /home/${user_name}/.xinitrc

		#/etc/slim.conf modfications:
		sed -i -e 's:default,start:startlxde,default,start:g' /etc/slim.conf
		echo "default_user        ${user_name}" >> /etc/slim.conf
		echo "auto_login        yes" >> /etc/slim.conf
	fi
}

install_desktop_branding () {
	#FixMe: move to github beagleboard repo...
	wget --no-verbose --directory-prefix=/opt/ http://rcn-ee.net/deb/testing/beaglebg.jpg
	chown -R ${user_name}:${user_name} /opt/beaglebg.jpg

	mkdir -p /home/${user_name}/.config/pcmanfm/LXDE/ || true
	echo "[desktop]" > /home/${user_name}/.config/pcmanfm/LXDE/pcmanfm.conf
	echo "wallpaper_mode=1" >> /home/${user_name}/.config/pcmanfm/LXDE/pcmanfm.conf
	echo "wallpaper=/opt/beaglebg.jpg" >> /home/${user_name}/.config/pcmanfm/LXDE/pcmanfm.conf
	chown -R ${user_name}:${user_name} /home/${user_name}/.config/

	#Disable LXDE's screensaver on autostart
	if [ -f /etc/xdg/lxsession/LXDE/autostart ] ; then
		cat /etc/xdg/lxsession/LXDE/autostart | grep -v xscreensaver > /tmp/autostart
		mv /tmp/autostart /etc/xdg/lxsession/LXDE/autostart
		rm -rf /tmp/autostart || true
	fi
}

dogtag () {
	echo "BeagleBoard.org BeagleBone Debian Image ${time}" > /etc/dogtag
}

build_node () {
	mount -t tmpfs shmfs -o size=256M /dev/shm
	#df -Th

	cd /opt/source
	wget http://nodejs.org/dist/v${node_release}/node-v${node_release}.tar.gz
	tar xf node-v${node_release}.tar.gz
	cd node-v${node_release}
	./configure ${node_build_options} && make -j5 && make install
	cd /
	rm -rf /opt/source/node-v${node_release}/ || true
	rm -rf /opt/source/node-v${node_release}.tar.gz || true
	echo "node-v${node_release} : http://rcn-ee.net/pkgs/nodejs/node-v${node_release}.tar.gz" >> /opt/source/list.txt

	echo "debug: node: [`node --version`]"
	echo "debug: npm: [`npm --version`]"

	echo "debug: npm config ls -l (before)"
	echo "--------------------------------"
	npm config ls -l
	echo "--------------------------------"

	#fix npm in chroot.. (did i mention i hate npm...)
	npm config set cache /root/.npm
	npm config set group 0
	npm config set init-module /root/.npm-init.js
	npm config set tmp /root/tmp
	npm config set user 0
	npm config set userconfig /root/.npmrc

	echo "debug: npm config ls -l (after)"
	echo "--------------------------------"
	npm config ls -l
	echo "--------------------------------"

	echo "Installing bonescript"
	NODE_PATH=${node_prefix}/lib/node_modules/ npm install -g bonescript --arch=armhf

	sync
	umount -l /dev/shm || true
}

install_builds () {
	cd /opt/
	wget http://rcn-ee.net/pkgs/chromium/${chromium_release}-armhf.tar.xz
	tar xf ${chromium_release}-armhf.tar.xz -C /
	rm -rf ${chromium_release}-armhf.tar.xz || true
	echo "${chromium_release} : http://rcn-ee.net/pkgs/chromium/${chromium_release}.tar.xz" >> /opt/source/list.txt

	#link Chromium to /usr/bin/x-www-browser
	update-alternatives --install /usr/bin/x-www-browser x-www-browser /usr/bin/chromium 200
}

install_repos () {
	git_repo="git://github.com/ajaxorg/cloud9.git"
	git_target_dir="/opt/cloud9"
	if [ "x${chroot_cloud9_git_tag}" = "x" ] ; then
		git_clone
	else
		mkdir -p /opt/cloud9/ || true
		qemu_command="git clone --depth 1 -b ${chroot_cloud9_git_tag} ${git_repo} ${git_target_dir} || true"
		qemu_warning
{'fraction_non_alphanumeric': 0.18370883882149047, 'fraction_numerical': 0.015350334241148799, 'mean_word_length': 3.0637156270959087, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 129, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1763482', 'n_tokens_mistral': 5059, 'n_tokens_neox': 4748, 'n_words': 923}