-
Notifications
You must be signed in to change notification settings - Fork 0
/
os.sh
482 lines (438 loc) · 15.9 KB
/
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
#!/bin/bash
# Define some color variables
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
MAGENTA='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color
# Define some variables
# storage="$HOME/storage/shared"
REPO_DIR="$HOME/ms3"
BASHRC_SOURCE="$REPO_DIR/bashrc"
TERMUX_PROPERTIES_SOURCE="$REPO_DIR/termux.properties"
BASHRC_DEST="$HOME/.bashrc"
TERMUX_PROPERTIES_DEST="$HOME/.termux/termux.properties"
NVIM_INIT_SOURCE="$REPO_DIR/dotfiles/neovim/init.lua"
NVIM_CONFIG_DEST="$HOME/.config/nvim"
# Function to install necessary packages
packages=(
"bash"
"bat"
"chafa"
"curl"
"fzf"
"git"
"lsd"
"mpv"
"nano"
"neovim"
"oh-my-posh"
"openssh"
"rclone"
"sshpass"
"vim"
"wget"
"yazi"
"zsh"
"fastfetch"
"termux-api"
# "x11-repo"
# "xdotool"
)
# Function to install necessary packages
install_packages() {
clear
echo -e "${GREEN}Updating package list...${NC}"
pkg update -y
echo -e "${GREEN}Upgrading installed packages...${NC}"
pkg upgrade -y
echo -e "${GREEN}Installing necessary packages...${NC}"
for pkg in "${packages[@]}"; do
# Check if the package is already installed
if ! command -v $pkg &> /dev/null; then
echo -e "${GREEN}Installing $pkg...${NC}"
if pkg install "$pkg" -y; then
echo -e "${GREEN}$pkg installed successfully.${NC}"
else
echo -e "${RED}Failed to install $pkg. Please check your network or package name.${NC}"
fi
else
echo -e "${GREEN}$pkg is already installed.${NC}"
fi
done
}
# Function to set up storage and password
setup_storage_passwd() {
echo -e "${GREEN}Setting up storage...${NC}"
termux-setup-storage
echo -e "${GREEN}Storage setup completed.${NC}"
echo -e "${GREEN}Setting up password...${NC}"
passwd
echo -e "${GREEN}Password setup completed.${NC}"
}
# Font Download and Setup
install_font_with_oh_my_posh() {
clear
echo -e "\e[34mInstalling JetBrainsMono NFP font using oh-my-posh...\e[0m"
oh-my-posh font install
FONT_PATH="$HOME/.local/share/fonts/jetbrainsmono-nfp/JetBrainsMonoNerdFontPropo-Regular.ttf"
TERMUX_FONT_DIR="$HOME/.termux"
# Check if the font is installed
if [ -f "$FONT_PATH" ]; then
echo -e "\e[32mJetBrainsMono NFP font found. Setting it as the default...\e[0m"
# Create .termux directory if it doesn't exist
mkdir -p "$TERMUX_FONT_DIR"
# Copy the font file to the .termux directory as font.ttf
cp "$FONT_PATH" "$TERMUX_FONT_DIR/font.ttf"
# Reload Termux settings to apply the font
termux-reload-settings
echo -e "\e[32mFont has been set as default and Termux settings reloaded.\e[0m"
else
echo -e "\e[31mJetBrainsMono NFP font not found after installation. Please ensure it is installed at $FONT_PATH\e[0m"
fi
}
# Copy .bashrc and termux.properties
copy_files() {
clear
echo -e "${CYAN}Copying .bashrc and termux.properties...${NC}"
cp "$BASHRC_SOURCE" "$BASHRC_DEST"
mkdir -p "$(dirname $TERMUX_PROPERTIES_DEST)"
cp "$TERMUX_PROPERTIES_SOURCE" "$TERMUX_PROPERTIES_DEST"
termux-reload-settings
echo -e "${CYAN}Files copied and settings reloaded.${NC}"
}
# Function to remove the repository
remove_repo() {
clear
echo -e "${RED}Removing the repository folder ($REPO_DIR)...${NC}"
rm -rf "$REPO_DIR"
echo -e "${RED}Repository folder removed successfully.${NC}"
}
# Neovim setup function
nvim_setup() {
clear
echo -e "${BLUE}Setting up Neovim configuration...${NC}"
# Create the Neovim config directory if it doesn't exist
mkdir -p "$NVIM_CONFIG_DEST"
# Copy the init.lua file to the Neovim config directory
cp "$NVIM_INIT_SOURCE" "$NVIM_CONFIG_DEST/init.lua"
if [ $? -eq 0 ]; then
echo -e "${GREEN}Neovim configuration setup successfully.${NC}"
else
echo -e "${RED}Failed to set up Neovim configuration.${NC}"
fi
}
# Git push repository function
git_push_repo() {
clear
echo -e "${BLUE}Pushing the repository to the remote...${NC}"
cd "$REPO_DIR"
git add .
echo -e "${CYAN}Enter commit message:${NC}"
read commit_message
git commit -m "$commit_message"
git push
if [ $? -eq 0 ]; then
echo -e "${GREEN}Repository pushed successfully.${NC}"
else
echo -e "${RED}Failed to push the repository. Please check your Git configuration.${NC}"
fi
}
update_ms3_repo() {
clear
local ms3_folder="$HOME/ms3"
if [ -d "$ms3_folder" ]; then
echo "Changing directory to $ms3_folder..."
cd "$ms3_folder" || {
echo "Failed to change directory to $ms3_folder."
return 1
}
echo "Pulling latest changes from the repository..."
git pull || {
echo "Failed to pull changes. Please check your repository setup."
return 1
}
echo "Repository updated successfully."
else
echo "The folder $ms3_folder does not exist."
return 1
fi
}
# Function to create an rclone folder and copy rclone.conf file
rclone_setup() {
clear
RCLONE_CONFIG_DIR="$HOME/.config/rclone"
SOURCE_CONF_FILE="$HOME/storage/shared/rclone.conf"
# Create the rclone folder if it doesn't exist
echo -e "Creating rclone configuration directory at $RCLONE_CONFIG_DIR..."
mkdir -p "$RCLONE_CONFIG_DIR" || {
echo -e "Failed to create rclone directory. Please check permissions."
return 1
}
echo -e "Directory created or already exists: $RCLONE_CONFIG_DIR"
# Copy rclone.conf to the new directory
echo -e "Copying rclone.conf from $SOURCE_CONF_FILE to $RCLONE_CONFIG_DIR..."
if [ -f "$SOURCE_CONF_FILE" ]; then
cp "$SOURCE_CONF_FILE" "$RCLONE_CONFIG_DIR/" || {
echo -e "Failed to copy rclone.conf. Please check permissions or the file path."
return 1
}
echo -e "rclone.conf copied successfully to $RCLONE_CONFIG_DIR"
else
echo -e "Source file $SOURCE_CONF_FILE does not exist. Please ensure the file exists."
return 1
fi
}
# Function to restore songs from the web using rclone
Restore_Songs() {
clear
DEST_DIR="$HOME/storage/shared/song"
REMOTE="gu:/song"
# Sync the songs from the remote to the destination directory
echo -e "Starting rclone sync from $REMOTE to $DEST_DIR..."
rclone sync "$REMOTE" "$DEST_DIR" -P --check-first --transfers=1 --track-renames --fast-list || {
echo -e "Failed to sync songs from $REMOTE to $DEST_DIR. Please check your rclone configuration."
return 1
}
echo -e "Songs restored successfully from $REMOTE to $DEST_DIR"
}
# Function to handle exit
exit_script() {
clear
echo -e "${GREEN}Exiting the script. Goodbye!${NC}"
exit 0
}
quick_file_search() {
clear
local file_name=$1
local search_dir=${2:-$PWD}
if [ -z "$file_name" ]; then
echo "Usage: quick_file_search <file_name> [directory]"
return 1
fi
echo "Searching for $file_name in $search_dir..."
find "$search_dir" -type f -name "$file_name"
}
network_speed_test() {
clear
echo "Testing network speed..."
if command -v speedtest &> /dev/null; then
speedtest
else
echo "speedtest-cli not installed. Installing now..."
sudo apt install -y speedtest-cli
speedtest
fi
}
list_large_files() {
clear
local target_dir=${1:-$PWD}
echo "Finding large files in $target_dir..."
find "$target_dir" -type f -exec du -h {} + | sort -rh | head -n 10
}
remote_access_goto_d2() {
clear
local remote_password="1823"
local remote_user="nahid"
local remote_host="192.168.0.101"
local psexec_path="C:/msBackups/PSTools/PsExec64.exe"
local displayswitch_path="C:/msBackups/Display/DisplaySwitch.exe"
echo -e "Connecting to the remote server to execute DisplaySwitch..."
# Run the PsExec command on the Windows remote system
sshpass -p "$remote_password" ssh "$remote_user@$remote_host" \
"cmd.exe /c '$psexec_path' -i 1 '$displayswitch_path' /external" || {
echo -e "${RED}Failed to execute DisplaySwitch on the remote server.${NC}"
return 1
}
echo -e "${GREEN}Remote DisplaySwitch execution completed successfully.${NC}"
}
remote_access_goto_d1() {
clear
local remote_password="1823"
local remote_user="nahid"
local remote_host="192.168.0.101"
local psexec_path="C:/msBackups/PSTools/PsExec64.exe"
local displayswitch_path="C:/msBackups/Display/DisplaySwitch.exe"
echo -e "Connecting to the remote server to execute script..."
# Run the taskkill commands to kill the processes
sshpass -p "$remote_password" ssh "$remote_user@$remote_host" \
"taskkill /F /IM dnplayer.exe || echo 'dnplayer.exe not running';
taskkill /F /IM python.exe || echo 'python.exe not running';" || {
echo -e "${RED}Failed to kill processes on the remote server.${NC}"
return 1
}
echo -e "Processes killed successfully. Now executing DisplaySwitch..."
# Run the PsExec command on the Windows remote system to run DisplaySwitch
sshpass -p "$remote_password" ssh "$remote_user@$remote_host" \
"cmd.exe /c '$psexec_path' -i 1 '$displayswitch_path' /internal" || {
echo -e "${RED}Failed to execute DisplaySwitch on the remote server.${NC}"
return 1
}
echo -e "${GREEN}Remote operations completed successfully.${NC}"
}
about_device() {
clear
fastfetch
}
# ntfy_notify() {
# clear
# # Initialize counter
# not_found_count=0
# # Infinite loop to check continuously
# while true; do
# # Check if "ntfy" exists in the output
# if rclone ls g00: | grep -i ntfy; then
# # Play the music file using mpv if "ntfy" is found
# mpv /storage/emulated/0/song/wwe/ww.mp3
# else
# # Increment the counter and display the message
# not_found_count=$((not_found_count + 1))
# echo "No 'ntfy' found in the output. Count: $not_found_count"
# fi
# # Wait for 30 seconds before checking again
# sleep 30
# done
# }
# ntfy_notify() {
# clear
# # Prevent the device from going into sleep mode
# termux-wake-lock
# # Initialize counter
# not_found_count=0
# # Infinite loop to check continuously
# while true; do
# # Check if "ntfy" exists in the output
# if rclone ls g00: | grep -iq "ntfy"; then
# # Play the music file using mpv if "ntfy" is found
# mpv /storage/emulated/0/song/wwe/ww.mp3 &
# # Get the PID of mpv
# mpv_pid=$!
# # Wait for mpv to finish or be killed
# wait $mpv_pid
# # Check if the exit status indicates that mpv was closed properly
# if [ $? -eq 0 ]; then
# echo "mpv was closed. Exiting function."
# break
# fi
# else
# # Increment the counter and display the message
# not_found_count=$((not_found_count + 1))
# echo "No 'ntfy' found in the output. Count: $not_found_count"
# fi
# # Wait for 30 seconds before checking again
# sleep 30
# done
# # Release the wake lock once the script finishes
# termux-wake-unlock
# }
# ntfy_notify() {
# clear
# # Prevent the device from going into sleep mode
# termux-wake-lock
# # Initialize counter
# not_found_count=0
# # Infinite loop to check continuously
# while true; do
# # Check if "ntfy" exists in the output
# if rclone ls g00: | grep -i ntfy; then
# # Run the specified command if "ntfy" is found
# am start rk.android.app.shortcutmaker/rk.android.app.shortcutmaker.CommonMethods.SplashScreenActivity
# # Exit the function after executing the command
# echo "Command executed. Exiting function."
# break
# else
# # Increment the counter and display the message
# not_found_count=$((not_found_count + 1))
# echo "No 'ntfy' found in the output. Count: $not_found_count"
# fi
# # Wait for 30 seconds before checking again
# sleep 30
# done
# # Release the wake lock once the script finishes
# termux-wake-unlock
# }
ntfy_notify() {
clear
# Prevent the device from going into sleep mode
termux-wake-lock
# Initialize counter
not_found_count=0
# Infinite loop to check continuously
while true; do
# Check if "ntfy" exists in the output
if rclone ls g00: | grep -i ntfy; then
# Start the Automate flow
am start -a com.llamalab.automate.intent.action.START_FLOW \
-d "content://com.llamalab.automate.provider/flows/10/statements/6" \
-n com.llamalab.automate/.StartServiceActivity
# Exit the function after executing the command
echo "Automate flow started. Exiting function."
break
else
# Increment the counter and display the message
not_found_count=$((not_found_count + 1))
echo "No 'ntfy' found in the output. Count: $not_found_count"
fi
# Wait for 30 seconds before checking again
sleep 30
done
# Release the wake lock once the script finishes
termux-wake-unlock
}
ntfy_remove() {
# remove te ntfy file
clear
echo "Deleting g00:ntfy file ...."
rclone delete g00:ntfy
}
# Declare a combined array of menu options and function bindings
menu_items=(
"1 :Goto D_1: remote_access_goto_d1 :$CYAN"
"2 :Goto D_2: remote_access_goto_d2 :$CYAN"
"3 :Git Pull [ms3]: update_ms3_repo :$BLUE"
"4 :Copy Files: copy_files :$BLUE"
"5 :Install Necessary Packages: install_packages setup_storage_passwd:$BLUE"
"6 :Font Setup: install_font_with_oh_my_posh :$BLUE"
"7 :Rclone Setup: rclone_setup :$BLUE"
"8 :Song [rs]: Restore_Songs :$BLUE"
"9 :Neovim Setup: nvim_setup :$BLUE"
"10:Git Push: git_push_repo :$BLUE"
"11:Remove Folder [ms3]: remove_repo :$RED"
"12:Exit: exit_script :$RED"
"13:About: about_device :$BLUE"
"14:Notify: ntfy_notify :$BLUE"
"15:Notify Remove: ntfy_remove :$RED"
)
# Display the menu and handle user input
while true; do
echo ""
echo -e "${YELLOW}Select an option:${NC}"
# Display menu options dynamically with assigned colors
for item in "${menu_items[@]}"; do
IFS=":" read -r number description functions color <<< "$item"
echo -e "${color}$number. $description${NC}"
done
echo ""
read -p "Enter choice: " choice
# Check if the choice is valid before executing the functions
valid_choice=false
for item in "${menu_items[@]}"; do
IFS=":" read -r number description functions color <<< "$item"
if [ "$choice" -eq "$number" ]; then
valid_choice=true
IFS=" " read -r -a function_array <<< "$functions"
for function in "${function_array[@]}"; do
$function
done
break
fi
done
# If the choice is invalid, show an error message
if [ "$valid_choice" = false ]; then
echo -e "${RED}Invalid option. Please try again.${NC}"
fi
# Reload the os.sh script to refresh functions and variables
source $HOME/ms3/os.sh
done