Skip to content

Commit 6ecd634

Browse files
authored
Merge pull request #27 from moheladwy/enhance/add-update-flag-support
add update flag support and logging functionality in OCR4Linux.sh
2 parents 03c3f0a + 19233bf commit 6ecd634

6 files changed

Lines changed: 59 additions & 32 deletions

File tree

.github/workflows/bash-lint.yml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
name: Bash Lint
22

3+
permissions:
4+
contents: read
5+
36
on:
4-
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
7+
push:
8+
branches:
9+
- main
10+
pull_request:
11+
branches:
12+
- main
1013

1114
jobs:
12-
lint:
13-
runs-on: ubuntu-latest
15+
lint:
16+
runs-on: ubuntu-latest
1417

15-
steps:
16-
- name: Checkout code
17-
uses: actions/checkout@v2
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v2
1821

19-
- name: Install ShellCheck
20-
run: sudo apt-get install -y shellcheck
22+
- name: Install ShellCheck
23+
run: sudo apt-get install -y shellcheck
2124

22-
- name: Lint setup.sh
23-
run: shellcheck setup.sh
25+
- name: Lint setup.sh
26+
run: shellcheck setup.sh
2427

25-
- name: Lint OCR4Linux.sh
26-
run: shellcheck OCR4Linux.sh
28+
- name: Lint OCR4Linux.sh
29+
run: shellcheck OCR4Linux.sh

.github/workflows/python-lint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: Python Lint
22

3+
permissions:
4+
contents: read
5+
36
on:
47
push:
58
branches:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,5 @@ output*.txt
174174

175175
#Ignore vscode AI rules
176176
.github/instructions/codacy.instructions.md
177+
.github/plans/
178+
.codacy/

OCR4Linux.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ========================================================================================================================
22
# Author:
33
# Mohamed Hussein Al-Adawy
4-
# Version: 1.4.0
4+
# Version: 1.4.1
55
# Description:
66
# OCR4Linux.py is a Python script that handles image preprocessing and text extraction using Tesseract OCR.
77
# The script takes an input image, processes it for optimal OCR accuracy, and extracts text while preserving

OCR4Linux.sh

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
# ========================================================================================================================
33
# Author: Mohamed Hussein Al-Adawy
4-
# Version: 1.4.0
4+
# Version: 1.4.1
55
# Description:
66
# OCR4Linux is a versatile text extraction tool for Linux systems that:
77
# 1. Takes screenshots of selected areas using:
@@ -45,25 +45,52 @@ SPECIFIED_LANGS=""
4545

4646
langs=()
4747

48+
# Add log function
49+
log_message() {
50+
local message
51+
message="[$(date '+%Y-%m-%d %H:%M:%S')] $1"
52+
echo "$message" >&2
53+
if [ "$KEEP_LOGS" = true ]; then
54+
{
55+
echo "$message"
56+
} >>"$OCR4Linux_HOME/$LOGS_FILE_NAME"
57+
fi
58+
}
59+
60+
# Perform update by running setup.sh from source directory
61+
perform_update() {
62+
echo "To perform a full update, please git pull the latest version from the GitHub repository:"
63+
echo "1) cd ~/src/OCR4Linux # If you haven't cloned it yet, run: git clone https://github.com/moheladwy/OCR4Linux.git ~/src/OCR4Linux"
64+
echo "2) git pull"
65+
echo "3) Then run the setup script:"
66+
echo "4) chmod +x ./setup.sh"
67+
echo "5) ./setup.sh"
68+
echo "The setup script will update the OCR4Linux scripts and dependencies to the latest version."
69+
}
70+
4871
# Display help message
4972
show_help() {
5073
echo "Usage: $(basename "$0") [OPTIONS]"
5174
echo "Options:"
5275
echo " -r Remove screenshot in the screenshot directory"
5376
echo " -d DIRECTORY Set screenshot directory (default: $SCREENSHOT_DIRECTORY)"
5477
echo " -l Keep logs"
78+
echo " -u, --update Update OCR4Linux (scripts and dependencies)"
5579
echo " --lang LANGUAGES Specify OCR languages (e.g., 'all', 'eng', 'eng+ara')"
5680
echo " -h Show this help message, then exit"
5781
echo "Example:"
5882
echo " OCR4Linux.sh -d $HOME/screenshots -l"
5983
echo " OCR4Linux.sh --lang eng+ara"
6084
echo " OCR4Linux.sh --lang all -l"
85+
echo " OCR4Linux.sh -u"
86+
echo " OCR4Linux.sh --update"
6187
echo " OCR4Linux.sh -h"
6288
echo "Note:"
6389
echo " - If --lang is not specified, an interactive language selection menu will appear"
6490
echo " - Use 'all' to select all available languages"
6591
echo " - Use '+' to separate multiple languages (e.g., 'eng+ara+fra')"
6692
echo " - Without arguments, screenshots are saved to $SCREENSHOT_DIRECTORY"
93+
echo " - The -u or --update option gives instructions on how to update OCR4Linux."
6794
}
6895

6996
# Parse command line arguments
@@ -81,6 +108,10 @@ while [[ $# -gt 0 ]]; do
81108
KEEP_LOGS=true
82109
shift
83110
;;
111+
-u|--update)
112+
perform_update
113+
exit 0
114+
;;
84115
--lang)
85116
SPECIFIED_LANGS="$2"
86117
LANG_SPECIFIED=true
@@ -98,18 +129,6 @@ while [[ $# -gt 0 ]]; do
98129
esac
99130
done
100131

101-
# Add log function
102-
log_message() {
103-
local message
104-
message="[$(date '+%Y-%m-%d %H:%M:%S')] $1"
105-
echo "$message" >&2
106-
if [ "$KEEP_LOGS" = true ]; then
107-
{
108-
echo "$message"
109-
} >>"$OCR4Linux_HOME/$LOGS_FILE_NAME"
110-
fi
111-
}
112-
113132
# Check if the required files exist.
114133
check_if_files_exist() {
115134
log_message "Checking required files and directories..."

setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# ========================================================================================================================
33
# Author:
44
# Mohamed Hussein Al-Adawy
5-
# Version: 1.4.0
5+
# Version: 1.4.1
66
# Description:
77
# This setup script installs and configures OCR4Linux and its dependencies.
88
# It handles the installation of:

0 commit comments

Comments
 (0)