#!/usr/bin/sh

## We only want this to script to do things when s6-rc is detected
if [ $(ps -p1 | grep -ic "s6-svscan") -eq 1 ] && [ -e /run/s6-rc ]; then
	
	export PATH=$PATH:/usr/sbin:/usr/lib/execline/bin:/usr/libexec
	[ -p "/run/turnstiled/$(id -u)/ready" ] && echo "$0" > "/run/turnstiled/$(id -u)/ready"
	mkdir -p "/tmp/$(id -u)/service"
	bash -c "coproc s6-svscan /tmp/$(id -u)/service"
	s6-rc-init -c "$(/usr/lib/execline/bin/homeof $(whoami))/.s6-rc/compiled" -l "/tmp/$(id -u)/s6-rc" "/tmp/$(id -u)/service"
	s6-rc -l "/tmp/$(id -u)/s6-rc" -up change default
    
	echo "$0" started &
	true
fi
