87 lines
2.5 KiB
Bash
87 lines
2.5 KiB
Bash
|
#!/bin/sh
|
||
|
|
||
|
# Variables
|
||
|
REMOTE_USER_JS_URL="https://raw.githubusercontent.com/arkenfox/user.js/master/user.js"
|
||
|
REMOTE_CLEANER_URL="https://raw.githubusercontent.com/arkenfox/user.js/master/prefsCleaner.sh"
|
||
|
CACHE_DIR="cache"
|
||
|
TEMP_DIR="${CACHE_DIR}/temp"
|
||
|
PROFILE_DIR="profiles"
|
||
|
GLOBAL_PREF_FILE="global.js"
|
||
|
|
||
|
# Functions
|
||
|
confirm_update() {
|
||
|
echo "You are about do download a new version of arkenfox user.js"
|
||
|
echo "and apply it to all profiles..."
|
||
|
local reply
|
||
|
read -p 'Continue? [y/N] ' reply
|
||
|
if [ "${reply}" != 'y' ] && [ "${reply}" != 'Y' ]; then
|
||
|
exit
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
update_cache() {
|
||
|
echo "Updating cache..."
|
||
|
if [ ! -e "${CACHE_DIR}" ]; then
|
||
|
mkdir -p "${CACHE_DIR}"
|
||
|
fi
|
||
|
if [ ! -e "${TEMP_DIR}" ]; then
|
||
|
mkdir -p "${TEMP_DIR}"
|
||
|
fi
|
||
|
curl -o "${CACHE_DIR}/user.js" "${REMOTE_USER_JS_URL}"
|
||
|
curl -o "${CACHE_DIR}/clean.sh" "${REMOTE_CLEANER_URL}"
|
||
|
chmod 0700 "${CACHE_DIR}/clean.sh"
|
||
|
echo "Cahce updated!"
|
||
|
}
|
||
|
|
||
|
clean_profile() {
|
||
|
echo "Cleaning profile '${1}'..."
|
||
|
real="${HOME}/.mozilla/firefox/${1}"
|
||
|
ln "${real}/user.js" "${real}/prefs.js" "${CACHE_DIR}/clean.sh" "${TEMP_DIR}"
|
||
|
old_dir="${PWD}"
|
||
|
cd "${TEMP_DIR}"
|
||
|
./clean.sh -s >/dev/null
|
||
|
rm -rf user.js prefs.js clean.sh prefsjs_backups
|
||
|
cd "${old_dir}"
|
||
|
echo "Done cleaning profile!"
|
||
|
}
|
||
|
|
||
|
update_profile() {
|
||
|
echo "Updating profile '${1}'..."
|
||
|
override_file="${PROFILE_DIR}/${1}.js"
|
||
|
user_js_content+="$(cat "${CACHE_DIR}/user.js")"
|
||
|
if [ -e "${GLOBAL_PREF_FILE}" ]; then
|
||
|
echo "Aplying global overrides..."
|
||
|
user_js_content+=$'\n\n'"$(cat "${GLOBAL_PREF_FILE}")"
|
||
|
fi
|
||
|
if [ -e "${override_file}" ] && [ "$(cat "${override_file}" | wc -l)" -ne 0 ]; then
|
||
|
echo "Aplying profile overrides..."
|
||
|
user_js_content+=$'\n\n'"$(cat "${override_file}")"
|
||
|
fi
|
||
|
printf '%s' "${user_js_content}" >"${HOME}/.mozilla/firefox/${1}/user.js"
|
||
|
echo "Done upating profile!"
|
||
|
}
|
||
|
|
||
|
update_profiles() {
|
||
|
echo "Updating profiles..."
|
||
|
if ! find "${PROFILE_DIR}" | read; then
|
||
|
echo "No profiles marked for update!"
|
||
|
echo "Exiting..."
|
||
|
exit 1
|
||
|
fi
|
||
|
for file in "${PROFILE_DIR}/"*; do
|
||
|
if printf "${file}" | grep -E '\.js$' >/dev/null 2>&1; then
|
||
|
profile="$(basename "${file::-3}")"
|
||
|
update_profile "${profile}"
|
||
|
clean_profile "${profile}"
|
||
|
else
|
||
|
echo "Not a profile config file: '${file}'!"
|
||
|
fi
|
||
|
done
|
||
|
echo "Update complete. Have a nice day! ^_^"
|
||
|
}
|
||
|
|
||
|
# Perform update
|
||
|
confirm_update
|
||
|
update_cache
|
||
|
update_profiles
|