-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZen-OS.sh
292 lines (235 loc) · 9.17 KB
/
Zen-OS.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#!/bin/bash
#-------------------------- Function to display a main menu --------------------------
show_main_menu() {
main_menu=$(zenity --title="ZEN-OS" --width=400 --height=500 --list --column="Options" --column="Description" \
"1" "Display System Information" \
"2" "Create a New Directory" \
"3" "Delete Directory" \
"4" "View Files in Specific Directory" \
"5" "Search for a File" \
"6" "Add File" \
"7" "Delete File" \
"8" "Update File" \
"9" "Copy and Paste File" \
"10" "Show Users" \
"11" "Add User" \
"12" "Delete User" \
"13" "List Processes" \
"14" "Shut Down")
case $main_menu in
1)
display_system_info
;;
2)
create_directory
;;
3)
delete_directory
;;
4)
view_files
;;
5)
search_file
;;
6)
add_file
;;
7)
delete_file
;;
8)
update_file
;;
9)
copypaste_file
;;
10)
show_users
;;
11)
add_user
;;
12)
delete_user
;;
13)
list_processes
;;
14)
shutdown_system
;;
*)
zenity --error --title="Error" --text="Invalid option"
show_main_menu
;;
esac
}
#-------------------------- Function to display system information --------------------------
display_system_info() {
system_info=$(echo -e "System Information:\n\nHostname: $(hostname)\n\nKernel Version: $(uname -r)\n\nCPU: $(grep 'model name' /proc/cpuinfo | head -n1 | cut -d ':' -f2 | sed -e 's/^ //')\n\nMemory: $(free -h | awk '/^Mem/ {print $2}')\n\nDisk Space:\n$(df -h)\n\nCurrent User: $(whoami)")
zenity --info --title="System Information" --width=600 --height=500 --text="$system_info"
show_main_menu
}
#-------------------------- Function to create a new directory --------------------------
create_directory() {
new_dir=$(zenity --entry --title="Create Directory" --text="Enter the name of the new directory:")
if [[ -z $new_dir ]]; then
zenity --error --title="Error" --text="Directory name cannot be empty"
create_directory
fi
mkdir $new_dir
zenity --info --title="Success" --text="Directory '$new_dir' created successfully"
show_main_menu
}
#-------------------------- Function to delete a directory --------------------------
delete_directory() {
dir_to_delete=$(zenity --file-selection --directory --title="Select Directory to Delete")
if [[ -z $dir_to_delete ]]; then
show_main_menu
fi
rm -r $dir_to_delete
zenity --info --title="Success" --text="Directory '$dir_to_delete' deleted successfully"
show_main_menu
}
#-------------------------- Function to view files in the current directory- -------------------------
view_files() {
current_dir=$(zenity --file-selection --directory --title="Select Directory")
if [[ -z $current_dir ]]; then
show_main_menu
fi
file_list=$(ls -al $current_dir)
zenity --info --title="Files in $current_dir" --width=600 --height=300 --text="$file_list"
show_main_menu
}
#-------------------------- Function to search for a file --------------------------
search_file() {
file_name=$(zenity --entry --title="Search File" --text="Enter the name of the file to search:")
if [[ -z $file_name ]]; then
zenity --error --title="Error" --text="File name cannot be empty"
search_file
fi
result=$(find / -name $file_name 2>/dev/null)
if [[ -n $result ]]; then
zenity --info --title="Search Result" --text="File '$file_name' found at:\n$result"
else
zenity --info --title="Search Result" --text="No files found with name '$file_name'"
fi
show_main_menu
}
#-------------------------- Function to add a new file --------------------------
add_file() {
file_name=$(zenity --entry --title="Add File" --text="Enter the name of the new file:")
if [[ -z $file_name ]]; then
zenity --error --title="Error" --text="File name cannot be empty"
add_file
fi
touch $file_name
zenity --info --title="Success" --text="File '$file_name' added successfully"
show_main_menu
}
#-------------------------- Function to delete a file --------------------------
delete_file() {
file_to_delete=$(zenity --file-selection --title="Select File to Delete")
if [[ -z $file_to_delete ]]; then
show_main_menu
fi
rm $file_to_delete
zenity --info --title="Success" --text="File '$file_to_delete' deleted successfully"
show_main_menu
}
#-------------------------- Function to update a file --------------------------
update_file() {
file_to_update=$(zenity --file-selection --title="Select File to Update")
if [[ -z $file_to_update ]]; then
show_main_menu
fi
new_content=$(zenity --text-info --title="Update File" --width=600 --height=400 --editable --filename="$file_to_update")
echo "$new_content" > "$file_to_update"
zenity --info --title="Success" --text="File '$file_to_update' updated successfully"
show_main_menu
}
#-------------------------- Function to copy and paste a file --------------------------
copypaste_file() {
file_name=$(zenity --file-selection --title="Select File to Move")
destination_dir=$(zenity --file-selection --directory --title="Select Destination Directory")
if [[ -z $file_name ]] || [[ -z $destination_dir ]]; then
show_main_menu
fi
cp $file_name $destination_dir
zenity --info --title="Success" --text="File '$file_name' copied and paste to '$destination_dir' successfully"
show_main_menu
}
#-------------------------- Function to show users --------------------------
show_users() {
users=$(awk -F: '$3 >= 1000 && $1 != "nobody" {print $1}' /etc/passwd)
zenity --info --title="Users" --width=200 --height=150 --text="$users"
show_main_menu
}
#-------------------------- Function to add a user --------------------------
add_user() {
new_user=$(zenity --entry --title="Add User" --text="Enter the username of the new user:")
if [[ -z $new_user ]]; then
zenity --error --title="Error" --text="Username cannot be empty"
add_user
fi
# Prompt for root password
root_password=$(zenity --password --title="Root Password" --text="Enter the root password:")
# Execute adduser command with sudo
echo "$root_password" | sudo -S adduser $new_user
zenity --info --title="Success" --text="User '$new_user' added successfully"
show_main_menu
}
#-------------------------- Function to delete a user --------------------------
delete_user() {
user_to_delete=$(zenity --entry --title="Delete User" --text="Enter the username of the user to delete:")
if [[ -z $user_to_delete ]]; then
zenity --error --title="Error" --text="Username cannot be empty"
delete_user
fi
# Prompt for root password
root_password=$(zenity --password --title="Root Password" --text="Enter the root password:")
# Execute deluser command with sudo
echo "$root_password" | sudo -S deluser $user_to_delete
zenity --info --title="Success" --text="User '$user_to_delete' deleted successfully"
show_main_menu
}
#-------------------------- Funtion to show all the running processes --------------------------
list_processes() {
ps -e -o pid,user,%mem,%cpu,vsz,rss,tty,stat,start,time,command --sort=-%mem > processes.txt
table_start="<table border='1' cellpadding='5' cellspacing='0'>"
table_end="</table>"
tr_start="<tr>"
tr_end="</tr>"
th_start="<th>"
th_end="</th>"
td_start="<td>"
td_end="</td>"
html_content="<html><head><style>th { background-color: #ddd; }</style></head><body>"
html_content+="$table_start"
html_content+="$tr_start$th_start PID $th_end$th_start User $th_end$th_start %MEM $th_end$th_start %CPU $th_end$th_start VSZ $th_end$th_start RSS $th_end$th_start TTY $th_end$th_start STAT $th_end$th_start Start $th_end$th_start Time $th_end$th_start Command $th_end$tr_end"
while IFS= read -r line; do
fields=($line)
html_content+="$tr_start"
for field in "${fields[@]}"; do
html_content+="$td_start $field $td_end"
done
html_content+="$tr_end"
done < "processes.txt"
html_content+="$table_end</body></html>"
echo "$html_content" > processes.html
zenity --text-info --title="Running Processes" --width=1000 --height=600 --filename="processes.html" --html
rm processes.txt processes.html
show_main_menu
}
#-------------------------- Function to initiate system shutdown --------------------------
shutdown_system() {
zenity --question --title="Shutdown" --text="Are you sure you want to shut down Zen-OS?" --default-cancel
if [[ $? -eq 0 ]]; then
zenity --info --title="Shutdown" --text="Shutting down ZEN-OS..."
pkill -f OS_Project.sh
fi
exit 0
}
#-------------------------- Start the application by displaying the main menu --------------------------
show_main_menu