#!/bin/sh
# upgrade OneDrive scopes

DEF_UID=$(grep "^UID_MIN" /etc/login.defs |  tr -s " " | cut -d " " -f2)
DEVICEUSER=$(getent passwd $DEF_UID | sed 's/:.*//')
if [ ! -d "/home/$DEVICEUSER/.config/libaccounts-glib" ]; then
    # not running as nemo; return failure so that we get rescheduled.
    exit 1
fi

# exit script with error if any of the commands below exit with error
set -xe

/usr/bin/sailfish-accounts-tool -p onedrive -s --global -m auth/oauth2/web_server/Scope stringlist "wl.signin","onedrive.readwrite","onedrive.appfolder","wl.skydrive_update","wl.skydrive","wl.offline_access","wl.photos"
/usr/bin/sailfish-accounts-tool -p onedrive -s onedrive-images -m auth/oauth2/web_server/Scope stringlist "wl.signin","onedrive.readwrite","onedrive.appfolder","wl.skydrive_update","wl.skydrive","wl.offline_access","wl.photos"
/usr/bin/sailfish-accounts-tool -p onedrive -s onedrive-sharing -m auth/oauth2/web_server/Scope stringlist "wl.signin","onedrive.readwrite","onedrive.appfolder","wl.skydrive_update","wl.skydrive","wl.offline_access","wl.photos"
/usr/bin/sailfish-accounts-tool -p onedrive -s onedrive-backup -m auth/oauth2/web_server/Scope stringlist "wl.signin","onedrive.readwrite","onedrive.appfolder","wl.skydrive_update","wl.skydrive","wl.offline_access","wl.photos"
/usr/bin/sailfish-accounts-tool -p onedrive -s onedrive-sync -m auth/oauth2/web_server/Scope stringlist "wl.signin","onedrive.readwrite","onedrive.appfolder","wl.skydrive_update","wl.skydrive","wl.offline_access","wl.photos"

exit 0
