upater.sh: correct paths when updating in a different dir

This commit is contained in:
overdodactyl 2018-11-21 18:59:42 -07:00
parent 5a2c110b13
commit 0c824af8d2

View file

@ -12,6 +12,7 @@
# Base variables # # Base variables #
######################### #########################
# Colors used for printing
RED='\033[0;31m' RED='\033[0;31m'
BLUE='\033[0;34m' BLUE='\033[0;34m'
BBLUE='\033[1;34m' BBLUE='\033[1;34m'
@ -41,13 +42,20 @@ set_wd () {
if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi if [ -z "$sfp" ]; then sfp=${BASH_SOURCE[0]}; fi
ff_profile="$(dirname "${sfp}")" ff_profile="$(dirname "${sfp}")"
elif [ "$PROFILE_PATH" = "list" ]; then elif [ "$PROFILE_PATH" = "list" ]; then
if [ "$(uname)" == "Darwin" ]; then
firefox_dir=~/Library/Application\ Support/Firefox/Profiles/
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
firefox_dir=~/.mozilla/firefox/
else
echo -e ${RED}"Error: Sorry, -l is not suppported for your OS"${NC}
exit 1
fi
echo -e ${GREEN}"The following profiles were found:\n"${ORANGE} echo -e ${GREEN}"The following profiles were found:\n"${ORANGE}
ls -d ~/Library/Application\ Support/Firefox/Profiles/*/ ls -d "$firefox_dir"*
echo -e ${RED}"\nWhich profile would you like to update?"${NC} echo -e ${RED}"\nWhich profile would you like to update?"${NC}
read -p "" read -p ""
echo -e "" echo -e ""
ff_profile=$(echo $REPLY | sed s'/.$//') ff_profile=$REPLY
echo $ff_profile
else else
ff_profile="$PROFILE_PATH" ff_profile="$PROFILE_PATH"
fi fi
@ -213,7 +221,8 @@ confirmation () {
get_updater_version () { get_updater_version () {
filename=$1 filename=$1
version_regex='5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p' version_regex='5 s/.*[[:blank:]]\([[:digit:]]*\.[[:digit:]]*\)/\1/p'
echo "$(sed -n "$version_regex" "${ff_profile}/${filename}")" echo "$(sed -n "$version_regex" "$filename")"
#echo "$(sed -n "$version_regex" "${ff_profile}/${filename}")"
} }
# Update updater.sh # Update updater.sh
@ -229,7 +238,13 @@ update_updater () {
download_file "https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/updater.sh" &>/dev/null download_file "https://raw.githubusercontent.com/ghacksuserjs/ghacks-user.js/master/updater.sh" &>/dev/null
if [[ $(get_updater_version updater.sh) < $(get_updater_version userjs_temps/updater.sh) ]]; then if ! [ "$PROFILE_PATH" = false ]; then
rm -rf "${currdir}/userjs_temps"
mv "$ff_profile/userjs_temps/" "$currdir"
fi
if [[ $(get_updater_version "${currdir}/updater.sh") < $(get_updater_version "${currdir}/userjs_temps/updater.sh") ]]; then
if [ $UPDATE = "check" ]; then if [ $UPDATE = "check" ]; then
echo -e "There is a newer version of updater.sh available. ${RED}Download and execute Y/N?${NC}" echo -e "There is a newer version of updater.sh available. ${RED}Download and execute Y/N?${NC}"
read -p "" -n 1 -r read -p "" -n 1 -r
@ -243,10 +258,9 @@ update_updater () {
# No update available # No update available
return 0 return 0
fi fi
# Backup current updater, execute latest version mv "${currdir}/userjs_temps/updater.sh" "${currdir}/updater.sh"
backup_file updater.sh chmod +x "${currdir}/updater.sh"
chmod +x updater.sh "${currdir}/updater.sh" "$@ -d"
./updater.sh "$@ -d"
exit 1 exit 1
} }
@ -395,3 +409,4 @@ create_diff
view_userjs view_userjs
rm -rf userjs_temps rm -rf userjs_temps
cd "${currdir}" cd "${currdir}"
rm -rf userjs_temps