-
Notifications
You must be signed in to change notification settings - Fork 1
/
7zip_GUI.sh
executable file
·56 lines (50 loc) · 2.18 KB
/
7zip_GUI.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
function display_error() {
zenity --error --text="$1"
exit 1
}
function check_dependencies() {
local dependencies=("zenity" "7z")
for dep in "${dependencies[@]}"; do
message="Error: $dep is not installed. Please install it before running this script."
command -v "$dep" &> /dev/null || display_error "$message"
done
}
action_chooser() {
action=$(zenity --list --title="7zip GUI" --column="Action" "Compress" "Extract" --width=400 --height=400 --ok-label="OK" --cancel-label="Cancel")
case "$action" in
"Compress")
archive_operation=$(zenity --list --title="Archive Operation" --column="Operation" "Create New Archive" "Add to Existing Archive")
case "$archive_operation" in
"Create New Archive")
archive_name=$(zenity --entry --title="Archive Name")
compression_method=$(zenity --list --title="Compression Method" --column="Method" "7z" "zip" "tar" "tar.gz" "tar.bz2")
compression_level=$(zenity --scale --title="Compression Level" --min-value=1 --max-value=9 --value=5 --step=1)
file_names=$(zenity --file-selection --multiple --title="Select Files")
# Compress the files
7z a -t${compression_method} -mx${compression_level} "${archive_name}" ${file_names//|/ } || display_error "Compression failed"
;;
"Add to Existing Archive")
archive_name=$(zenity --file-selection --title="Select Existing Archive")
add_file_names=$(zenity --file-selection --multiple --title="Select Files to Add")
7z u "${archive_name}" ${add_file_names//|/ } || display_error "Adding files failed"
;;
*)
display_error "Invalid Archive Operation"
;;
esac
;;
"Extract")
archive_name=$(zenity --file-selection --multiple --title="Select Archive to Extract")
output_directory=$(zenity --file-selection --directory --title="Select Output Directory")
# Extract the files
7z x "${archive_name}" -o"${output_directory}" || display_error "Extraction failed"
;;
*)
display_error "Invalid Action"
;;
esac
}
check_dependencies
action_chooser
zenity --info --text="Operation completed successfully"