#!/bin/bash

# launcher script for welcome - occasionally on
# first login - but especially on the live-session
# snapd takes a little while to fully initialise
# the welcome mountpoint
# preventing budgie-welcome snap from starting
# we keep looping until we get welcome to start
# or eventually timeout after a three minutes

COUNTER=0
while [  $COUNTER -lt 60 ]; do
    if [ -f /snap/ubuntu-budgie-welcome/current/usr/bin/budgie-welcome ]; then
        output=`df | grep "^/cow"`
        if [ ! -z "$output" ]; then
       	    sleep 1
        else
            sleep 10
        fi
    	snap run ubuntu-budgie-welcome.budgie-welcome &
        exit 0
    fi

    sleep 3

    let COUNTER=COUNTER+1
done

echo "Failed to launch welcome"

exit 1
