|
3 | 3 | # Make sure script ends as soon as an error arises |
4 | 4 | set -e |
5 | 5 |
|
| 6 | +# Parse command line arguments |
| 7 | +VERBOSE=false |
| 8 | +while [[ $# -gt 0 ]]; do |
| 9 | + case $1 in |
| 10 | + --verbose) |
| 11 | + VERBOSE=true |
| 12 | + shift |
| 13 | + ;; |
| 14 | + *) |
| 15 | + echo "Unknown option: $1" |
| 16 | + exit 1 |
| 17 | + ;; |
| 18 | + esac |
| 19 | +done |
| 20 | + |
| 21 | +# Function to conditionally redirect output |
| 22 | +redirect_output() { |
| 23 | + if [ "$VERBOSE" = true ]; then |
| 24 | + cat |
| 25 | + else |
| 26 | + cat >/dev/null 2>&1 |
| 27 | + fi |
| 28 | +} |
| 29 | + |
6 | 30 | ################# |
7 | 31 | ### VARIABLES ### |
8 | 32 | ################# |
@@ -279,12 +303,12 @@ install_pipx() { |
279 | 303 |
|
280 | 304 | echo -e "\nInstalling pipx..." |
281 | 305 |
|
282 | | - python3 -m pip install --user pipx >/dev/null 2>&1 || python3 -m pip install --user --break-system-packages pipx >/dev/null 2>&1 |
| 306 | + python3 -m pip install --user pipx 2>&1 | redirect_output || python3 -m pip install --user --break-system-packages pipx 2>&1 | redirect_output |
283 | 307 |
|
284 | 308 | # ensure path for pipx |
285 | 309 | pipx_version=$(python3 -m pipx --version 2> /dev/null) |
286 | 310 | if [[ $pipx_version =~ $version_regex ]]; then |
287 | | - python3 -m pipx ensurepath >/dev/null 2>&1 |
| 311 | + python3 -m pipx ensurepath 2>&1 | redirect_output |
288 | 312 | echo "...pipx installed" |
289 | 313 | else |
290 | 314 | echo "...pipx ensurepath failed" |
@@ -312,7 +336,7 @@ install_froster() { |
312 | 336 | else |
313 | 337 |
|
314 | 338 | echo " Installing from PyPi package repository" |
315 | | - python3 -m pipx install froster >/dev/null 2>&1 & |
| 339 | + python3 -m pipx install froster 2>&1 | redirect_output & |
316 | 340 |
|
317 | 341 | if pipx list | grep froster >/dev/null 2>&1; then |
318 | 342 | echo -e "\nUninstalling old Froster..." |
@@ -363,24 +387,24 @@ install_pwalk() { |
363 | 387 | pwalk_path=filesystem-reporting-tools-${pwalk_commit} |
364 | 388 |
|
365 | 389 | # Delete previous downloaded pwalk files (if any) |
366 | | - rm -rf ${pwalk_path} >/dev/null 2>&1 |
| 390 | + rm -rf ${pwalk_path} 2>&1 | redirect_output |
367 | 391 |
|
368 | 392 | # Gather pwalk repository files |
369 | 393 | echo " Downloading pwalk files" |
370 | | - curl -s -L ${pwalk_repository} | tar xzf - >/dev/null 2>&1 & |
| 394 | + curl -s -L ${pwalk_repository} | tar xzf - 2>&1 | redirect_output & |
371 | 395 | spinner $! |
372 | 396 |
|
373 | 397 | # Compile pwalk tool and put exec file in froster's binaries folder |
374 | 398 | echo " Compiling pwalk" |
375 | | - gcc -pthread ${pwalk_path}/pwalk.c ${pwalk_path}/exclude.c ${pwalk_path}/fileProcess.c -o ${pwalk_path}/pwalk >/dev/null 2>&1 & |
| 399 | + gcc -pthread ${pwalk_path}/pwalk.c ${pwalk_path}/exclude.c ${pwalk_path}/fileProcess.c -o ${pwalk_path}/pwalk 2>&1 | redirect_output & |
376 | 400 | spinner $! |
377 | 401 |
|
378 | 402 | # Get the froster's binaries folder |
379 | 403 | froster_dir=$(dirname "$(readlink -f $(which froster))") |
380 | 404 | echo " Moving pwalk to froster's binaries folder" |
381 | 405 |
|
382 | 406 | # Move pwalk to froster's binaries folder |
383 | | - mv ${pwalk_path}/pwalk ${froster_dir}/pwalk >/dev/null 2>&1 |
| 407 | + mv ${pwalk_path}/pwalk ${froster_dir}/pwalk 2>&1 | redirect_output |
384 | 408 | echo " Installed pwalk at ${froster_dir}/pwalk" |
385 | 409 |
|
386 | 410 | # Delete downloaded pwalk files |
@@ -423,24 +447,24 @@ install_rclone() { |
423 | 447 | fi |
424 | 448 |
|
425 | 449 | # Remove previous downloaded zip file (if any) |
426 | | - rm -rf rclone-current-linux-*.zip rclone-v*/ >/dev/null 2>&1 |
| 450 | + rm -rf rclone-current-linux-*.zip rclone-v*/ 2>&1 | redirect_output |
427 | 451 |
|
428 | 452 | # Download the rclone zip file |
429 | 453 | echo " Downloading rclone files" |
430 | | - curl -LO $rclone_url >/dev/null 2>&1 & |
| 454 | + curl -LO $rclone_url 2>&1 | redirect_output & |
431 | 455 | spinner $! |
432 | 456 |
|
433 | 457 | # Extract the zip file |
434 | 458 | echo " Extracting rclone files" |
435 | | - unzip rclone-current-linux-*.zip >/dev/null 2>&1 & |
| 459 | + unzip rclone-current-linux-*.zip 2>&1 | redirect_output & |
436 | 460 | spinner $! |
437 | 461 |
|
438 | 462 | # Get the froster's binaries folder |
439 | 463 | froster_dir=$(dirname "$(readlink -f $(which froster))") |
440 | 464 | echo " Moving rclone to froster's binaries folder" |
441 | 465 |
|
442 | 466 | # Move rclone to froster's binaries folder |
443 | | - mv rclone-v*/rclone ${froster_dir}/rclone >/dev/null 2>&1 |
| 467 | + mv rclone-v*/rclone ${froster_dir}/rclone 2>&1 | redirect_output |
444 | 468 | echo " Installed rclone at ${froster_dir}/rclone" |
445 | 469 |
|
446 | 470 | # Remove the downloaded zip file |
|
0 commit comments