1 | #!/bin/bash |
---|
2 | # |
---|
3 | # 2014/09/09 Gabriel Moreau <Gabriel Moreau(A)univ-grenoble-alpes.fr> - Initial release |
---|
4 | # 2017/06/20 Gabriel Moreau - Trokata Integration |
---|
5 | |
---|
6 | export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin |
---|
7 | export LANG=C |
---|
8 | |
---|
9 | |
---|
10 | function usage() { |
---|
11 | cat <<END_USAGE |
---|
12 | NAME |
---|
13 | $(basename $0) - fast and robust deploy tool |
---|
14 | |
---|
15 | SYNOPSIS |
---|
16 | $0 -a arch -n soft_name -r release_number [-o os_name] [-d] [-v] [-h] |
---|
17 | |
---|
18 | OPTIONS |
---|
19 | -a arch : 32_bit / 64_bit |
---|
20 | -n name of the soft, example: matlab |
---|
21 | -r release number of the soft, example: 2.3.1 |
---|
22 | -o os distribution name |
---|
23 | -d delete (mirror) mode |
---|
24 | -v verbose |
---|
25 | -h help |
---|
26 | |
---|
27 | AUTHOR |
---|
28 | Gabriel Moreau |
---|
29 | |
---|
30 | COPYRIGHT |
---|
31 | Copyright (C) 2014-2018, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France |
---|
32 | Licence : GNU GPL version 2 or later |
---|
33 | END_USAGE |
---|
34 | } |
---|
35 | |
---|
36 | # Default values |
---|
37 | rsync_cmd='/usr/bin/ionice -c 3 /usr/bin/nice -18 /usr/bin/rsync' |
---|
38 | rsync_opt="--contimeout=3 --timeout=3 --bwlimit=5000 --rsync-path='/usr/bin/ionice -c 3 /usr/bin/nice -18 /usr/bin/rsync'" |
---|
39 | rsync_share='legilnx40::opt/${os_arch}' |
---|
40 | dest_dir='/opt' |
---|
41 | |
---|
42 | if [ -e "/etc/softsyncrc" ] |
---|
43 | then |
---|
44 | . "/etc/softsyncrc" |
---|
45 | fi |
---|
46 | |
---|
47 | # get options |
---|
48 | if [ $# -eq 0 ]; then usage; exit 1; fi |
---|
49 | while getopts "a:n:r:o:dvh" options |
---|
50 | do |
---|
51 | case ${options} in |
---|
52 | a) |
---|
53 | if echo ${OPTARG} | egrep -q '^[[:digit:]]+' |
---|
54 | then |
---|
55 | export os_arch=${OPTARG} |
---|
56 | else |
---|
57 | usage |
---|
58 | exit 2 |
---|
59 | fi |
---|
60 | ;; |
---|
61 | |
---|
62 | n) |
---|
63 | if echo ${OPTARG} | egrep -q '[[:alpha:]]' |
---|
64 | then |
---|
65 | export soft_name=${OPTARG} |
---|
66 | else |
---|
67 | usage |
---|
68 | exit 2 |
---|
69 | fi |
---|
70 | ;; |
---|
71 | |
---|
72 | r) |
---|
73 | if echo ${OPTARG} | egrep -q '[[:digit:]]' |
---|
74 | then |
---|
75 | export soft_version=${OPTARG} |
---|
76 | else |
---|
77 | usage |
---|
78 | exit 2 |
---|
79 | fi |
---|
80 | ;; |
---|
81 | |
---|
82 | o) |
---|
83 | if echo ${OPTARG} | egrep -q '[[:alpha:]]' |
---|
84 | then |
---|
85 | export os_name=${OPTARG} |
---|
86 | else |
---|
87 | usage |
---|
88 | exit 2 |
---|
89 | fi |
---|
90 | ;; |
---|
91 | |
---|
92 | d) |
---|
93 | export rsync_opt="${rsync_opt} --delete" |
---|
94 | ;; |
---|
95 | |
---|
96 | v) |
---|
97 | export verbose='yes' |
---|
98 | ;; |
---|
99 | |
---|
100 | h|*) |
---|
101 | usage |
---|
102 | exit 3 |
---|
103 | ;; |
---|
104 | esac |
---|
105 | done |
---|
106 | |
---|
107 | |
---|
108 | soft_version_server=${soft_version} |
---|
109 | if [ -n "${os_name}" ] |
---|
110 | then |
---|
111 | soft_version_server="${soft_version}..dist.${os_name}" |
---|
112 | fi |
---|
113 | |
---|
114 | [ -d "${dest_dir}/${soft_name}" ] || mkdir -p "${dest_dir}/${soft_name}" |
---|
115 | if eval ${rsync_cmd} -avn ${rsync_opt} ${rsync_share}/${soft_name}/.zz-end.${soft_version_server} ${dest_dir}/${soft_name}/.zz-end.${soft_version} \ |
---|
116 | | /bin/grep -q ^\.zz-end |
---|
117 | then |
---|
118 | rm -f ${dest_dir}/${soft_name}/.zz-end.${soft_version} |
---|
119 | [ "${verbose}" == "yes" ] && \ |
---|
120 | eval echo ${rsync_cmd} -avz ${rsync_opt} ${rsync_share}/${soft_name}/${soft_version_server}/ ${dest_dir}/${soft_name}/${soft_version}/ |
---|
121 | if eval ${rsync_cmd} -avz ${rsync_opt} ${rsync_share}/${soft_name}/${soft_version_server}/ ${dest_dir}/${soft_name}/${soft_version}/ |
---|
122 | then |
---|
123 | chmod ugo+rX ${dest_dir}/${soft_name}/ |
---|
124 | eval ${rsync_cmd} -aq ${rsync_opt} ${rsync_share}/${soft_name}/.zz-end.${soft_version_server} ${dest_dir}/${soft_name}/.zz-end.${soft_version} |
---|
125 | fi |
---|
126 | fi |
---|