#!/usr/bin/env python3

import os
import sys

sys.argv[1]
profileid1 = str.replace(sys.argv[1], 'http://', '')
profileid2 = str.replace(profileid1, 'https://', '')
profileid = str.replace(profileid2, '/', '_')

profilepath = os.path.expanduser('~/.local/share/ice/firefox/' + str(profileid))
chromepath = os.path.expanduser('~/.local/share/ice/firefox/' + str(profileid) + '/chrome')
path = os.path.dirname(chromepath)

execute = 'firefox -profile ' + path + ' -no-remote -new-instance' + ' ' + sys.argv[1]

os.system('mkdir -p ' + chromepath)
os.system('echo "#nav-bar { max-height: 0 !important; margin-bottom: -20px !important; opacity: 0; } #identity-box, #navigator-toolbox::after, #tabbrowser-tabs {  --tab-min-height: 0px !important;  margin-left: 0px !important;  height: 0px !important; }" > ' + chromepath + '/userChrome.css')
os.system('echo "user_pref(\\"browser.cache.disk.enable\\", false);" > ' + profilepath + '/user.js')
os.system('echo "user_pref(\\"browser.cache.disk.capacity\\", 0);" >> ' + profilepath + '/user.js')
os.system('echo "user_pref(\\"browser.cache.disk.filesystem_reported\\", 1);" >> ' + profilepath + '/user.js')
os.system('echo "user_pref(\\"browser.cache.disk.smart_size.enabled\\", false);" >> ' + profilepath + '/user.js')
os.system('echo "user_pref(\\"browser.cache.disk.smart_size.first_run\\", false);" >> ' + profilepath + '/user.js')
os.system('echo "user_pref(\\"browser.cache.disk.smart_size.use_old_max\\", false);" >> ' + profilepath + '/user.js')
os.system('echo "user_pref(\\"browser.ctrlTab.previews\\", true);" >> ' + profilepath + '/user.js')
os.system('echo "user_pref(\\"browser.tabs.warnOnClose\\", false);" >> ' + profilepath + '/user.js')
os.system('echo "user_pref(\\"plugin.state.flash\\", 2);" >> ' + profilepath + '/user.js')
os.system('echo "user_pref(\\"toolkit.legacyUserProfileCustomizations.stylesheets\\", true);" >> ' + profilepath + '/user.js')
os.system('cp -n /usr/lib/pearllinux/ice/search.json.mozlz4 ' + profilepath + '/search.json.mozlz4')
os.system('cp -n /usr/lib/pearllinux/ice/places.sqlite ' + profilepath + '/places.sqlite')
os.system(execute)
os.system('rm -rf ' + path + '/cache2')
