mirror of
https://github.com/arkenfox/user.js.git
synced 2025-05-03 15:33:38 +02:00
updater.sh add diff option
This commit is contained in:
parent
1830a5037c
commit
d6401a3f31
1 changed files with 35 additions and 3 deletions
38
updater.sh
38
updater.sh
|
@ -38,13 +38,14 @@ ff_profile="$(dirname "${sfp}")"
|
||||||
#########################
|
#########################
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo -e ${BLUE}"\nUsage: $0 [-h] [-u] [-d] [-s] [-n] [-b] [-o OVERRIDE]\n"${NC} 1>&2 # Echo usage string to standard error
|
echo -e ${BLUE}"\nUsage: $0 [-h] [-u] [-d] [-s] [-n] [-b] [-c] [-o OVERRIDE]\n"${NC} 1>&2 # Echo usage string to standard error
|
||||||
echo -e "Optional Arguments:"
|
echo -e "Optional Arguments:"
|
||||||
echo -e "\t-h,\t\t Show this help message and exit."
|
echo -e "\t-h,\t\t Show this help message and exit."
|
||||||
echo -e "\t-u,\t\t Update updater.sh and execute silently. Do not seek confirmation."
|
echo -e "\t-u,\t\t Update updater.sh and execute silently. Do not seek confirmation."
|
||||||
echo -e "\t-d,\t\t Do not look for updates to updater.sh."
|
echo -e "\t-d,\t\t Do not look for updates to updater.sh."
|
||||||
echo -e "\t-s,\t\t Silently update user.js. Do not seek confirmation."
|
echo -e "\t-s,\t\t Silently update user.js. Do not seek confirmation."
|
||||||
echo -e "\t-b,\t\t Only keep one backup of each file."
|
echo -e "\t-b,\t\t Only keep one backup of each file."
|
||||||
|
echo -e "\t-c,\t\t Create a diff file comparing old and new user.js within userjs_diffs. "
|
||||||
echo -e "\t-o OVERRIDE,\t Filename or path to overrides file (if different than user-overrides.js)."
|
echo -e "\t-o OVERRIDE,\t Filename or path to overrides file (if different than user-overrides.js)."
|
||||||
echo -e "\t\t\t If given a directory, all files inside will be appended recursively."
|
echo -e "\t\t\t If given a directory, all files inside will be appended recursively."
|
||||||
echo -e "\t\t\t You can pass multiple files or directories by passing a comma separated list."
|
echo -e "\t\t\t You can pass multiple files or directories by passing a comma separated list."
|
||||||
|
@ -73,6 +74,7 @@ UPDATE="check"
|
||||||
CONFIRM="yes"
|
CONFIRM="yes"
|
||||||
OVERRIDE="user-overrides.js"
|
OVERRIDE="user-overrides.js"
|
||||||
BACKUP="multiple"
|
BACKUP="multiple"
|
||||||
|
COMPARE=false
|
||||||
|
|
||||||
if [ $# != 0 ]; then
|
if [ $# != 0 ]; then
|
||||||
legacy_lc="$(echo $1 | tr '[A-Z]' '[a-z]')"
|
legacy_lc="$(echo $1 | tr '[A-Z]' '[a-z]')"
|
||||||
|
@ -86,7 +88,7 @@ if [ $# != 0 ]; then
|
||||||
UPDATE="yes"
|
UPDATE="yes"
|
||||||
legacy_argument $1
|
legacy_argument $1
|
||||||
else
|
else
|
||||||
while getopts ":hudsno:b" opt; do
|
while getopts ":hudsno:bc " opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
h)
|
h)
|
||||||
usage
|
usage
|
||||||
|
@ -109,6 +111,9 @@ if [ $# != 0 ]; then
|
||||||
b)
|
b)
|
||||||
BACKUP="single"
|
BACKUP="single"
|
||||||
;;
|
;;
|
||||||
|
c)
|
||||||
|
COMPARE=true
|
||||||
|
;;
|
||||||
\?)
|
\?)
|
||||||
echo -e ${RED}"\n Error! Invalid option: -$OPTARG"${NC} >&2
|
echo -e ${RED}"\n Error! Invalid option: -$OPTARG"${NC} >&2
|
||||||
usage
|
usage
|
||||||
|
@ -122,6 +127,8 @@ if [ $# != 0 ]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo $OVERRIDE
|
||||||
|
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# File Handeling #
|
# File Handeling #
|
||||||
|
@ -282,7 +289,7 @@ add_override () {
|
||||||
echo -e "Status: ${GREEN}Override file appended:${NC} ${input}"
|
echo -e "Status: ${GREEN}Override file appended:${NC} ${input}"
|
||||||
elif [ -d "$input" ]; then
|
elif [ -d "$input" ]; then
|
||||||
FSAVEIFS=$IFS
|
FSAVEIFS=$IFS
|
||||||
IFS=$(echo -en "\n\b") # Set IFS
|
IFS=$'\n\b' # Set IFS # Set IFS
|
||||||
FILES="${input}"/*.js
|
FILES="${input}"/*.js
|
||||||
for f in $FILES
|
for f in $FILES
|
||||||
do
|
do
|
||||||
|
@ -296,6 +303,11 @@ add_override () {
|
||||||
|
|
||||||
# Applies latest version of user.js and any custom overrides
|
# Applies latest version of user.js and any custom overrides
|
||||||
update_userjs () {
|
update_userjs () {
|
||||||
|
# Copy a version of user.js to diffs folder for later comparison
|
||||||
|
if [ "$COMPARE" = true ]; then
|
||||||
|
mkdir -p userjs_diffs
|
||||||
|
cp user.js userjs_diffs/past_user.js
|
||||||
|
fi
|
||||||
backup_file user.js
|
backup_file user.js
|
||||||
if [ "$OVERRIDE" != "none" ]; then
|
if [ "$OVERRIDE" != "none" ]; then
|
||||||
IFS=',' read -ra FILES <<< "$OVERRIDE"
|
IFS=',' read -ra FILES <<< "$OVERRIDE"
|
||||||
|
@ -305,6 +317,25 @@ update_userjs () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
remove_comments () {
|
||||||
|
from_file=$1
|
||||||
|
to_file=$2
|
||||||
|
sed -e 's/^[[:space:]]*\/\/.*$//' -e '/^\/\*/,/\*\//d' -e '/^[[:space:]]*$/d' -e 's/);[[:space:]]\/\/.*/);/' $from_file > $to_file
|
||||||
|
}
|
||||||
|
|
||||||
|
create_diff () {
|
||||||
|
if [ "$COMPARE" = true ]; then
|
||||||
|
pastuserjs=userjs_diffs/past_user.js
|
||||||
|
past_nocomments=userjs_diffs/past_userjs.txt
|
||||||
|
current_nocomments=userjs_diffs/current_userjs.txt
|
||||||
|
remove_comments $pastuserjs $past_nocomments
|
||||||
|
remove_comments user.js $current_nocomments
|
||||||
|
diffname="userjs_diffs/diff_$(date +"%Y-%m-%d_%H%M").txt"
|
||||||
|
diff -w -B -U 0 $past_nocomments $current_nocomments > $diffname
|
||||||
|
rm $past_nocomments $current_nocomments $pastuserjs
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# Execute #
|
# Execute #
|
||||||
|
@ -316,5 +347,6 @@ cd "$ff_profile"
|
||||||
initiate
|
initiate
|
||||||
update_updater
|
update_updater
|
||||||
confirmation && update_userjs
|
confirmation && update_userjs
|
||||||
|
create_diff
|
||||||
rm -rf userjs_temps
|
rm -rf userjs_temps
|
||||||
cd "${currdir}"
|
cd "${currdir}"
|
||||||
|
|
Loading…
Add table
Reference in a new issue