Advertisement
Guest User

Untitled

a guest
May 15th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.35 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3. #Usage:
  4. #There are 3 argument structures:
  5. #-a <name : string> <type : string> <compress : bool> <delete: bool> <destination : string> <address : string>
  6. #-m <name :string> <current_dir : string> <new_dir : string>
  7. #-r <name : string> <directory : string>
  8.  
  9. #list of sources to download.
  10. repo_list="repo_list.txt"
  11.  
  12. error() {
  13.     echo "error: $@" 1>&2
  14.     exit 1
  15. }
  16.  
  17. assert_cmd() {
  18.     command -v "$1" &>/dev/null || error "command $1 does not exist"
  19. }
  20.  
  21. verify_add() {
  22.     printf "%s\n" "$@" "" >> "${repo_list}"
  23. }
  24.  
  25. verify_backup() {
  26.     # ??? dude what ???
  27.  
  28.     #files.
  29.     if [ -f "$2"+"$1"+".*" ]; then
  30.         rm -rf "$2"+="$1"+=".*"
  31.     fi
  32.    
  33.     #folders.
  34.     if [ -d "$2"+"$1"+".*" ]; then
  35.         rm -rf "$2"+"$1"
  36.     fi
  37. }
  38.  
  39. verify_repository() {
  40.     case "$1" in
  41.     git)
  42.         assert_cmd git
  43.         git ls-remote --exit-code --heads "$2" master || return
  44.         ;;
  45.     svn)
  46.         assert_cmd svn
  47.         # ...
  48.         ;;
  49.     *)
  50.         error "invalid repository type $1"
  51.         ;;
  52.     esac
  53. }
  54.  
  55. # etc ...
  56.  
  57. while getopts amr opt; do
  58.     case "${opt}" in
  59.     a)
  60.         (( $# < 7 )) && error "missing command line arguments"
  61.  
  62.         # these commands don't fail
  63.         verify_add "$1" "$3" "$6" "$7"
  64.         verify_backup "$2" "$6"
  65.  
  66.         # this one might
  67.         verify_repository "$3" "$7" || error "cannot verify repository"
  68.  
  69.         # ...
  70.         ;;
  71.     [mr])
  72.         error "not yet implemented"
  73.         ;;
  74.     *)
  75.         error "unknown option"
  76.         ;;
  77.     esac
  78. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement