Skip to content

Commit 05d3c50

Browse files
committed
Improved scripts (stage 1)
1 parent 688dc41 commit 05d3c50

3 files changed

Lines changed: 261 additions & 38 deletions

File tree

check_fb.sh

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,78 @@
11
#!/bin/bash
2-
if [ -z "$1" ] || [ -z "$2" ]
3-
then
4-
echo "Supply the file containing the names (or numbers) to check and at least one leaked txt"
2+
3+
# Function to display usage
4+
usage() {
5+
echo "Usage: $0 [-h] [-i] <names_file> <leaked_files...>"
6+
echo "Options:"
7+
echo " -h Show this help message"
8+
echo " -i Case insensitive search"
59
exit 1
10+
}
11+
12+
# Parse arguments
13+
CASE_SENSITIVE=true
14+
15+
while getopts "hi" opt; do
16+
case $opt in
17+
h)
18+
usage
19+
;;
20+
i)
21+
CASE_SENSITIVE=false
22+
;;
23+
\?)
24+
usage
25+
;;
26+
esac
27+
done
28+
29+
shift $((OPTIND-1))
30+
31+
# Check for required arguments
32+
if [ $# -lt 2 ]; then
33+
echo "Error: Missing required arguments"
34+
usage
635
fi
736

837
namesfile=$1
938
shift
1039

11-
mapfile -t names < $namesfile
40+
# Validate input file
41+
if [ ! -f "$namesfile" ]; then
42+
echo "Error: Names file '$namesfile' does not exist"
43+
exit 1
44+
fi
45+
46+
# Check if leaked files exist
47+
for file in "$@"; do
48+
if [ ! -f "$file" ]; then
49+
echo "Error: Leaked file '$file' does not exist"
50+
exit 1
51+
fi
52+
done
53+
54+
# Read names into array
55+
mapfile -t names < "$namesfile"
56+
57+
if [ ${#names[@]} -eq 0 ]; then
58+
echo "Error: Names file is empty"
59+
exit 1
60+
fi
1261

13-
echo "Checking..."
62+
echo "Checking ${#names[@]} entries against ${#@} file(s)..."
63+
64+
# Set grep options based on case sensitivity
65+
GREP_OPTS="--color=always"
66+
if [ "$CASE_SENSITIVE" = false ]; then
67+
GREP_OPTS="$GREP_OPTS -i"
68+
fi
1469

15-
for name in "${names[@]}"
16-
do
17-
echo "$name"
18-
cat $@ | grep --color=always $name
70+
# Process each name
71+
for name in "${names[@]}"; do
72+
if [ -n "$name" ]; then
73+
echo "Checking: $name"
74+
cat "$@" | grep $GREP_OPTS "$name" || echo "No matches found"
75+
fi
1976
done
2077

2178
exit 0

commit_mail_changer.sh

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,84 @@
11
#!/bin/bash
22
# Script to change email and username of existing commit in a repo
33

4-
git filter-branch --commit-filter '
5-
if [ "$GIT_AUTHOR_EMAIL" = "email_to_remove" ];
6-
then
7-
GIT_AUTHOR_NAME="git_username";
8-
GIT_AUTHOR_EMAIL="new_git_email";
9-
git commit-tree "$@";
10-
else
11-
git commit-tree "$@";
12-
fi' HEAD
4+
usage() {
5+
echo "Usage: $0 [-h] -o <old_email> -n <new_email> -u <new_username>"
6+
echo "Options:"
7+
echo " -h Show this help message"
8+
echo " -o Old email address to replace"
9+
echo " -n New email address"
10+
echo " -u New git username"
11+
exit 1
12+
}
13+
14+
# Parse arguments
15+
while getopts "ho:n:u:" opt; do
16+
case $opt in
17+
h)
18+
usage
19+
;;
20+
o)
21+
OLD_EMAIL="$OPTARG"
22+
;;
23+
n)
24+
NEW_EMAIL="$OPTARG"
25+
;;
26+
u)
27+
NEW_USERNAME="$OPTARG"
28+
;;
29+
\?)
30+
usage
31+
;;
32+
esac
33+
done
34+
35+
# Validate required arguments
36+
if [ -z "$OLD_EMAIL" ] || [ -z "$NEW_EMAIL" ] || [ -z "$NEW_USERNAME" ]; then
37+
echo "Error: Missing required arguments"
38+
usage
39+
fi
40+
41+
# Validate email format
42+
email_regex="^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"
43+
if ! [[ "$OLD_EMAIL" =~ $email_regex ]] || ! [[ "$NEW_EMAIL" =~ $email_regex ]]; then
44+
echo "Error: Invalid email format"
45+
exit 1
46+
fi
47+
48+
# Check if we're in a git repository
49+
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
50+
echo "Error: Not in a git repository"
51+
exit 1
52+
fi
53+
54+
# Show what will be changed
55+
echo "The following changes will be made:"
56+
echo "Old email: $OLD_EMAIL"
57+
echo "New email: $NEW_EMAIL"
58+
echo "New username: $NEW_USERNAME"
59+
echo
60+
read -p "Do you want to proceed? [y/N] " -n 1 -r
61+
echo
62+
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
63+
echo "Operation cancelled"
64+
exit 1
65+
fi
66+
67+
# Perform the change
68+
git filter-branch --env-filter "
69+
if [ \"\$GIT_AUTHOR_EMAIL\" = \"$OLD_EMAIL\" ]; then
70+
export GIT_AUTHOR_NAME=\"$NEW_USERNAME\"
71+
export GIT_AUTHOR_EMAIL=\"$NEW_EMAIL\"
72+
fi
73+
if [ \"\$GIT_COMMITTER_EMAIL\" = \"$OLD_EMAIL\" ]; then
74+
export GIT_COMMITTER_NAME=\"$NEW_USERNAME\"
75+
export GIT_COMMITTER_EMAIL=\"$NEW_EMAIL\"
76+
fi
77+
" --tag-name-filter cat -- --branches --tags
78+
79+
echo
80+
echo "Changes completed. Please verify the changes and force push if needed."
81+
echo "To push changes: git push --force --all"
82+
echo "To push tags: git push --force --tags"
1383

1484
exit 0

convert_webp.sh

Lines changed: 116 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,130 @@
11
#!/bin/bash
22

3-
# Check if the user has provided input and output directory arguments
3+
# Function to display usage
4+
usage() {
5+
echo "Usage: $0 [-h] [-r] [-q quality] <input_directory> <output_directory>"
6+
echo "Options:"
7+
echo " -h Show this help message"
8+
echo " -r Process directories recursively"
9+
echo " -q quality WebP quality (0-100, default: 75)"
10+
exit 1
11+
}
12+
13+
# Default values
14+
RECURSIVE=false
15+
QUALITY=75
16+
TOTAL_FILES=0
17+
PROCESSED_FILES=0
18+
19+
# Parse arguments
20+
while getopts "hrq:" opt; do
21+
case $opt in
22+
h)
23+
usage
24+
;;
25+
r)
26+
RECURSIVE=true
27+
;;
28+
q)
29+
if ! [[ "$OPTARG" =~ ^[0-9]+$ ]] || [ "$OPTARG" -lt 0 ] || [ "$OPTARG" -gt 100 ]; then
30+
echo "Error: Quality must be a number between 0 and 100"
31+
exit 1
32+
fi
33+
QUALITY=$OPTARG
34+
;;
35+
\?)
36+
usage
37+
;;
38+
esac
39+
done
40+
41+
shift $((OPTIND-1))
42+
43+
# Check for required arguments
444
if [ "$#" -ne 2 ]; then
5-
echo "Usage: $0 <input_directory> <output_directory>"
6-
exit 1
45+
echo "Error: Missing required arguments"
46+
usage
747
fi
848

9-
INPUT_DIR=$1
10-
OUTPUT_DIR=$2
49+
INPUT_DIR="$1"
50+
OUTPUT_DIR="$2"
51+
52+
# Validate directories
53+
if [ ! -d "$INPUT_DIR" ]; then
54+
echo "Error: Input directory '$INPUT_DIR' does not exist"
55+
exit 1
56+
fi
57+
58+
# Create output directory if it doesn't exist
59+
mkdir -p "$OUTPUT_DIR"
1160

1261
# Check if ImageMagick is installed
13-
if ! command -v magick &> /dev/null
14-
then
15-
echo "ImageMagick is not installed. Please install ImageMagick to proceed."
62+
if ! command -v magick &> /dev/null; then
63+
echo "Error: ImageMagick is not installed. Please install ImageMagick to proceed."
1664
exit 1
1765
fi
1866

19-
# Process each image in the input directory
20-
for input_image in "$INPUT_DIR"/*; do
21-
if [[ -f "$input_image" ]]; then
22-
filename=$(basename -- "$input_image")
23-
output_image="$OUTPUT_DIR/${filename%.*}.webp"
67+
# Function to show progress
68+
show_progress() {
69+
local percent=$((100 * PROCESSED_FILES / TOTAL_FILES))
70+
printf "\rProgress: [%-50s] %d%% (%d/%d files)" \
71+
"$(printf '#%.0s' $(seq 1 $((percent/2))))" \
72+
"$percent" \
73+
"$PROCESSED_FILES" \
74+
"$TOTAL_FILES"
75+
}
76+
77+
# Function to process images
78+
process_image() {
79+
local input_file="$1"
80+
local rel_path="${input_file#$INPUT_DIR/}"
81+
local output_subdir="$OUTPUT_DIR/$(dirname "$rel_path")"
82+
local output_file="$output_subdir/$(basename "${input_file%.*}").webp"
2483

25-
# Use ImageMagick to convert to WebP
26-
magick "$input_image" "$output_image"
84+
# Create output subdirectory if needed
85+
mkdir -p "$output_subdir"
2786

28-
if [ $? -eq 0 ]; then
29-
echo "Image converted to WebP successfully: $output_image"
87+
# Convert image
88+
if magick "$input_file" -quality "$QUALITY" "$output_file" 2>/dev/null; then
89+
((PROCESSED_FILES++))
90+
show_progress
3091
else
31-
echo "An error occurred during processing: $input_image"
92+
echo -e "\nError processing: $input_file"
3293
fi
33-
fi
34-
done
94+
}
95+
96+
# Count total files
97+
if [ "$RECURSIVE" = true ]; then
98+
TOTAL_FILES=$(find "$INPUT_DIR" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" \) | wc -l)
99+
else
100+
TOTAL_FILES=$(ls -1 "$INPUT_DIR"/*.{jpg,jpeg,png,gif} 2>/dev/null | wc -l)
101+
fi
102+
103+
if [ "$TOTAL_FILES" -eq 0 ]; then
104+
echo "No image files found in the input directory"
105+
exit 1
106+
fi
107+
108+
echo "Converting $TOTAL_FILES files to WebP format (quality: $QUALITY)"
109+
echo "From: $INPUT_DIR"
110+
echo "To: $OUTPUT_DIR"
111+
echo
112+
113+
# Process images
114+
if [ "$RECURSIVE" = true ]; then
115+
find "$INPUT_DIR" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" \) -print0 |
116+
while IFS= read -r -d '' file; do
117+
process_image "$file"
118+
done
119+
else
120+
for ext in jpg jpeg png gif; do
121+
for file in "$INPUT_DIR"/*."$ext" "$INPUT_DIR"/*."${ext^^}"; do
122+
if [ -f "$file" ]; then
123+
process_image "$file"
124+
fi
125+
done
126+
done
127+
fi
128+
129+
echo -e "\nConversion completed: $PROCESSED_FILES files processed"
130+
exit 0

0 commit comments

Comments
 (0)