
mkdir -p file/portable/chromium/profile/Default

#this 0-byte file is needed so chromium will start at our puppy home page on 1st startup...
touch "file/portable/chromium/profile/First Run"

[ -e usr/bin/chromium ] && CBEXE='chromium'
[ -e usr/bin/chromium-browser ] && CBEXE='chromium-browser' #note, pinstall.sh create chromium symlink.

#have a go at editing the startup script...
CBPARAM=''
if [ "`file usr/bin/${CBEXE} | grep 'shell'`" != "" ];then
 cbPTN='s%exec \$LIBDIR/\$APPNAME \$CHROMIUM_FLAGS%exec $LIBDIR/$APPNAME $CHROMIUM_FLAGS --user-data-dir=/file/portable/chromium/profile%'
 sed -i -e "$cbPTN" usr/bin/${CBEXE}
else
 CBPARAM=" --user-data-dir=/file/portable/chromium/profile"
fi

CBDSK=''
[ -f usr/share/applications/chromium.desktop ] && CBDSK='chromium.desktop'
[ -f usr/share/applications/chromium-browser.desktop ] && CBDSK='chromium-browser.desktop'

if [ "$CBDSK" ];then
 echo "[Desktop Entry]
Version=1.0
Name=Chromium web browser
GenericName=Chromium
Comment=Chromium web browser
Exec=chromium${CBPARAM}
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=chromium-browser.png
Categories=X-Internet-browser
MimeType=text/html;text/xml;application/xhtml_xml;x-scheme-handler/http;x-scheme-handler/https;
StartupWMClass=Chromium-browser
StartupNotify=true
Actions=NewWindow;Incognito;TempProfile;
X-AppInstall-Package=chromium-browser" > usr/share/applications/${CBDSK}
fi

#preset some preferences...
echo '{
   "download": {
      "default_directory": "/file/downloads",
      "directory_upgrade": true,
      "extensions_to_open": "",
      "prompt_for_download": true
   },
   "savefile": {
      "default_directory": "/file/downloads"
   },
   "homepage": "file:///usr/share/doc/home.htm",
   "homepage_is_newtabpage": false
}' > file/portable/chromium/profile/Default/Preferences
