@@ -73,6 +73,52 @@ function renew() {
7373 git push --tag
7474}
7575
76+ function patch() {
77+ # Validate arguments
78+ if [[ $# -ne 3 ]]; then
79+ echo " Usage: ${FUNCNAME[0]} <tar.gz> <inner_file> <replacement>" >&2
80+ return 1
81+ fi
82+ local tar_file=" $1 "
83+ local inner_file=" $2 "
84+ local replacement_file=" $3 "
85+ # Check if files exist
86+ if [[ ! -f " $tar_file " ]]; then
87+ echo " Error: Tar file '$tar_file ' not found" >&2
88+ return 1
89+ fi
90+ if [[ ! -f " $replacement_file " ]]; then
91+ echo " Error: Replacement file '$replacement_file ' not found" >&2
92+ return 1
93+ fi
94+ # Create temporary directory
95+ local temp_dir
96+ temp_dir=$( mktemp -d) || {
97+ echo " Error: Failed to create temporary directory" >&2
98+ return 1
99+ }
100+ trap " rm -rf '$temp_dir '" EXIT
101+ # Extract tar file
102+ if ! tar -xzf " $tar_file " -C " $temp_dir " 2> /dev/null; then
103+ echo " Error: Failed to extract '$tar_file '" >&2
104+ return 1
105+ fi
106+ # Check if inner file exists in archive
107+ if [[ ! -f " ${temp_dir} /${inner_file} " ]]; then
108+ echo " Error: File '$inner_file ' not found in archive" >&2
109+ return 1
110+ fi
111+ # Replace the file
112+ if ! cp " $replacement_file " " ${temp_dir} /${inner_file} " ; then
113+ echo " Error: Failed to replace file" >&2
114+ return 1
115+ fi
116+
117+ tar --numeric-owner -czf " ${tar_file: :- 7} .patched.tar.gz" -C " $temp_dir " . --transform=' s,^./,,'
118+ echo " Success: File replaced in '$tar_file '"
119+ return 0
120+ }
121+
76122function clean-tags() {
77123 for tag in $( git tag --sort creatordate| head -n " $1 " )
78124 do
@@ -99,4 +145,4 @@ if ! _is_sourced; then
99145 action=$1
100146 shift 1
101147 $action " $@ "
102- fi
148+ fi
0 commit comments