diff options
author | erdgeist <erdgeist@erdgeist.org> | 2008-01-02 07:03:59 +0000 |
---|---|---|
committer | erdgeist <erdgeist@erdgeist.org> | 2008-01-02 07:03:59 +0000 |
commit | 3953315c474ea737305c7a8ae8d63a240938f1f0 (patch) | |
tree | de1c9d01a03fc0be6681d5ae44f427bb19a70615 /ezjail-admin | |
parent | e9f9774ff663dc35749623fc9c1604893927ba8d (diff) |
Guess archive name on restores
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-x | ezjail-admin | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/ezjail-admin b/ezjail-admin index 648247c..02e9594 100755 --- a/ezjail-admin +++ b/ezjail-admin | |||
@@ -860,7 +860,7 @@ archive) | |||
860 | ####################### ezjail-admin RESTORE ######################## | 860 | ####################### ezjail-admin RESTORE ######################## |
861 | restore) | 861 | restore) |
862 | # Clean variables, prevent polution | 862 | # Clean variables, prevent polution |
863 | unset ezjail_fromarchive ezjail_archivedir | 863 | unset ezjail_archivedir |
864 | 864 | ||
865 | #ezjail_usage_restore="Usage: ${ezjail_admin} restore [-d archivedir] (archive|jailname)..." | 865 | #ezjail_usage_restore="Usage: ${ezjail_admin} restore [-d archivedir] (archive|jailname)..." |
866 | 866 | ||
@@ -871,9 +871,27 @@ restore) | |||
871 | 871 | ||
872 | [ $# -eq 0 ] && exerr ${ezjail_usage_restore} | 872 | [ $# -eq 0 ] && exerr ${ezjail_usage_restore} |
873 | 873 | ||
874 | # Jail name mandatory | 874 | # Default archive directory to . |
875 | fetchjailinfo $1 | 875 | ezjail_archivedir=${ezjail_archivedir:-`pwd -P`} |
876 | 876 | ||
877 | while [ $# -gt 0 ]; do | ||
878 | ezjail_fromarchive=$1 | ||
879 | |||
880 | # if archive location is absolute and doesn't exist, fail | ||
881 | [ "${ezjail_fromarchive%%[!/]*}" -a ! -f "${ezjail_fromarchive}" ] && exerr "Error: File for archive ${ezjail_fromarchive} not found." | ||
882 | if [ -z "${ezjail_fromarchive%%[!/]*}" ]; then | ||
883 | # Try archive location | ||
884 | if [ -r "${ezjail_archivedir}/${ezjail_fromarchive}" ]; then | ||
885 | ezjail_fromarchive="${ezjail_archivedir}/${ezjail_fromarchive}" | ||
886 | else | ||
887 | # If archive is not found, try guessing by jail name | ||
888 | ezjail_safename=`echo -n "$1" | tr -c '[:alnum:]' _` | ||
889 | ezjail_fromarchive=`ls -tr ${ezjail_archivedir}/${ezjail_safename}* | head -n 1` | ||
890 | [ -f "${ezjail_fromarchive}" ] || exerr "Error: No archive for pattern $1 can be found." | ||
891 | fi | ||
892 | fi | ||
893 | echo ${ezjail_fromarchive} | ||
894 | done | ||
877 | ;; | 895 | ;; |
878 | ######################## ezjail-admin CONFIG ######################## | 896 | ######################## ezjail-admin CONFIG ######################## |
879 | config) | 897 | config) |