summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSrikant Patnaik2015-02-16 22:49:04 +0530
committerSrikant Patnaik2015-02-16 22:49:04 +0530
commitb067febdf2e35ee58b2668f80dee4dafc0a90bfb (patch)
treec09b99e06cbdd1b8b341268f373fb414dd7944dc
parent1c305d915ff24ec32916cb894883a034597f0f88 (diff)
downloadFOSSEE-netbook-patcher-b067febdf2e35ee58b2668f80dee4dafc0a90bfb.tar.gz
FOSSEE-netbook-patcher-b067febdf2e35ee58b2668f80dee4dafc0a90bfb.tar.bz2
FOSSEE-netbook-patcher-b067febdf2e35ee58b2668f80dee4dafc0a90bfb.zip
A complete tested version ready to merge with master, tried cherry-pick but it fails, so need to carry other useless commits too :(
-rwxr-xr-xpatcher.sh100
1 files changed, 77 insertions, 23 deletions
diff --git a/patcher.sh b/patcher.sh
index 93ceca1..3c4f6ee 100755
--- a/patcher.sh
+++ b/patcher.sh
@@ -1,12 +1,33 @@
#!/bin/bash
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+# This program is intended to write/copy images to any media or drive.
+
+# This script depends on 'easybashgui'.
+# The password function has extra dependency on 'zenity' & 'dialog'
+# programs, which can be modified to work with other libraries too
+
+
+# For title of each Window
export supertitle="FOSSEE Netbook Updates"
source easybashgui
-#for Debugging
+# For global debugging(opens flood gates)
#set -x
+# For local debugging
logfile=patcher.log
+
+# Intermediate files/directories. Will be removed after each interation
testfile=robots.txt
files_in_all_commits=files_in_all_commits.txt
all_commits_one_liner_with_date=all_commits_one_liner_with_date.txt
@@ -15,9 +36,10 @@ past_applied_commits=past_applied_commits.txt
local_updates=local_updates
unique_tags=unique_tags
[ ! -d $unique_tags ] && mkdir -p $unique_tags
-updated_file=updates.txt
+# Default is no internet
INET_AVAILABLE=0
+# Its good to have them together
generic_return_code='Working offline. Select Ok to continue.'
return_code_1="Unknown error occured. $generic_return_code"
return_code_3="File I/0 error. $generic_return_code"
@@ -26,8 +48,12 @@ return_code_5="SSL verification failure. Check system date. $generic_return_code
return_code_7="Protocol error. $generic_return_code"
return_code_8="Server error. $generic_return_code"
+# =====================================================================================
+# Functions in order they get called #
+# =====================================================================================
+
function clean_up() {
- echo "================================ New iteration =============================">>$logfile
+ echo "=========================== New iteration =========================">>$logfile
date >> $logfile
[ -f $testfile ] && rm -v $testfile>>$logfile
[ -f $files_in_all_commits ] && rm -v $files_in_all_commits>>$logfile
@@ -38,6 +64,8 @@ function clean_up() {
}
+# ======================================================================================
+
function check_internet() {
#wait_for internet
for each in {fossee.in,github.com};
@@ -54,42 +82,56 @@ function check_internet() {
[ $return_code -eq 8 ] && alert_message $return_code_8
}
+# ======================================================================================
-#fetch updates from github and show
+# Fetch updates if internet is available and formulate a CSV
function format_list_updates() {
- #make a local copy for editing
- [ $INET_AVAILABLE -eq 1 ] && git log --pretty=\;\(%ar\)\;%d\;%s\;\(%h\) --no-walk --tags >\
+ # If internet available just merge the changes (won't update patches automatically)
+ [ $INET_AVAILABLE -eq 1 ] && git pull
+ # Create CSV of commits with only tags( git tags are used to group similar patches)
+ git log --pretty=\;\(%ar\)\;%d\;%s\;\(%h\) --no-walk --tags >\
$all_commits_one_liner_with_date
+ # Find out files in each commit(with tag)
for each in $(cat $all_commits_one_liner_with_date | cut -d ';' -f 5 | tr -d '(|)')
do
files_in_each_commit=$(git show --first-parent --pretty="format:" --name-only $each)
echo $files_in_each_commit | tr ' ' ',' >> $files_in_all_commits
done
+ # Create a file with [Not Updated] flag on the first column for all the tags, we will
+ # selectively change it to [Updated] based on previously applied patches(git tags)
paste -d ';' $all_commits_one_liner_with_date \
$files_in_all_commits | \
awk 'BEGIN{FS=";";OFS=";"} {$1="[Not Updated]"} 1' > \
$all_commits_dates_with_file_paths
}
+# ======================================================================================
+
function select_updates() {
+ # If no new/old update available, just quit (Ignoring HEAD based tags to avoid confusion)
+ no_updates=$(cat $all_commits_dates_with_file_paths | sed '/HEAD/d' | wc -c)
+ [ $no_updates -eq 0 ] && alert_message "No available updates !!!" && exit 0
+ # Look for previously applied updates(git tags)
for hash in $(cat unique_tags/*);
do
line=$(grep -on $hash $all_commits_dates_with_file_paths | cut -d ':' -f 1);\
sed -i $line's/\[Not\ Updated\]/\[Updated\]/g' $all_commits_dates_with_file_paths;
done
-
- selected_update=$(menu -w 1000 -h 550 "$(cat $all_commits_dates_with_file_paths | sed '/HEAD,\ origin/d' | \
+ selected_update=$(menu -w 1000 -h 550 "$(cat $all_commits_dates_with_file_paths | sed '/HEAD/d' | \
cut -d ';' -f 1,2,3,4,5| tr ';' ' ' )" 2>&1)
[ $? -eq 1 ] && exit 0
#get hash for selected_update
selected_hash=$(echo $selected_update | grep -o \([0-9a-z]*\) | tr -d '(|)')
selected_tag=$(echo $selected_update | grep -o \(tag:\ [A-Za-z0-9._-]*\) | sed 's/(tag:\ //' |sed 's/)//')
- #At a time only one version from associated tag
+ # At a time only one version from similar group of tags will be applied, for eg: AudioMic-1 and
+ # AudioMic-2 (tags/commits/patches) can't be applied simultaneously as they affect same file
find $unique_tags -iname $(echo $selected_tag | cut -d '-' -f 1)\* | grep '' && [ $? -eq 0 ] && \
rm $(find $unique_tags -iname $(echo $selected_tag | cut -d '-' -f 1)\*)
+ # This will help identifying the unique tags among group of tags(commits/patches)
echo $selected_hash > $unique_tags/$selected_tag
+ # This for loop creates a copy of file(s) from given tag/commit
files_in_selected_hash=$(grep $selected_hash $all_commits_dates_with_file_paths | cut -d ';' -f6)
- #for more than one file
+ # For more than one file in a commit
for each_file in $(echo $files_in_selected_hash|tr ',' '\n');
do
mkdir -p $local_updates/$(dirname $each_file)
@@ -99,12 +141,17 @@ function select_updates() {
}
+# ======================================================================================
function sudo_access() {
+# Clear remember password
sudo -K
-# The only place easybashgui fails. So adding separate functions for both tty(consoles) and pts(terminals)
-# If tty not found, returns 1, so use zenity
-tty | grep tty && \
+# The only place 'easybashgui' fails. So adding separate functions for both tty(consoles)
+# and pts(terminals). If tty not found, it returns 1, and 'zenity' is used
+
+tty | grep tty
+if [ $? -eq 1 ]; then
+
while true
do
password=$(zenity --title "Enter your password to continue" --password)
@@ -115,12 +162,11 @@ while true
# If wrong password then brek
[ $? -eq 0 ] && break
done
+else
-
-tty | grep pts && \
while true
do
- password=$(dialog --title "Password" \
+ password=$(dialog --title "Password" \
--clear \
--passwordbox "Enter your password" 10 30 \
--stdout)
@@ -129,34 +175,42 @@ while true
# If wrong password then brek
[ $? -eq 0 ] && break
done
-
+fi
}
+# ======================================================================================
function apply_updates() {
- question "Do you want to apply the selected update? This will affect the following file(s): '/$files_in_selected_hash'" 2>&1
+ question "Do you want to apply the selected update? This will affect the following file(s):\
+ '/$files_in_selected_hash'" 2>&1
[ $? -eq 1 ] && exit 0
for each_file in $(echo $files_in_selected_hash | tr ',' '\n');
do
echo "##### applying updates #####">>$logfile
mv -v $local_updates/$each_file /$each_file>>$logfile
done
- question "Update done. Select 'Ok/Yes' to revisit update selection menu. Select 'Cancel/No' to 'Quit' this program"
+ question "Update done. Select 'Yes' to revisit update selection menu.
+ Select 'Cancel' to 'Quit' this program"
[ $? -eq 1 ] && exit 0
call_functions
}
+# ======================================================================================
+
function call_functions() {
#Function calls
clean_up
-# check_internet
-# format_list_updates
-# select_updates
+ check_internet
+ format_list_updates
+ select_updates
sudo_access
-# apply_updates
+ apply_updates
}
+
+# ======================================================================================
+
# __init__
call_functions