a/trunk/wharfie/lib/makefile.py | b/trunk/wharfie/lib/makefile.py | ||
---|---|---|---|
... |
... |
||
79 | l = env.lstrip().split(" ") |
79 | l = env.lstrip().split(" ") |
80 | f.write("export %s=%s\n" % (l[0], " ".join(l[1:]))); |
80 | f.write("export %s=%s\n" % (l[0], " ".join(l[1:]))); |
81 | 81 | ||
82 | # write all targets |
82 | # write all targets |
83 | for target in makeTargets: |
83 | for target in makeTargets: |
84 | postpath = '' |
||
85 | |||
84 | if 'comment' in target: |
86 | if 'comment' in target: |
85 | f.write("# %s\n" % target['comment']); |
87 | f.write("# %s\n" % target['comment']); |
86 | if 'trgcmd' in target or 'hostcmd' in target or 'temporary' in target: |
88 | if 'trgcmd' in target or 'hostcmd' in target or 'temporary' in target: |
87 | # independent of if the command was successful or not, we cleanup the directory |
89 | # independent of if the command was successful or not, we cleanup the directory |
88 | # - killall processes running inside |
90 | # - killall processes running inside |
... |
... |
||
110 | f.write("\t${Q}echo '%s: %s'\n" % (target['name'], target['comment'])); |
112 | f.write("\t${Q}echo '%s: %s'\n" % (target['name'], target['comment'])); |
111 | f.write("\t${Q}echo '******************************'\n"); |
113 | f.write("\t${Q}echo '******************************'\n"); |
112 | f.write("\t${Q}(echo -e \"%s\") | ${SUDO} tee .trg.sh\n" % cmd.replace('\\n', '\\\\\\n').replace('\n', '\\n').replace('!', '"\'!\'"')); |
114 | f.write("\t${Q}(echo -e \"%s\") | ${SUDO} tee .trg.sh\n" % cmd.replace('\\n', '\\\\\\n').replace('\n', '\\n').replace('!', '"\'!\'"')); |
113 | f.write("\t${Q}${SUDO} chmod a+x .trg.sh\n"); |
115 | f.write("\t${Q}${SUDO} chmod a+x .trg.sh\n"); |
114 | 116 | ||
115 | if 'hostcmd' in target: |
117 | if 'trgcmdpost' in target: |
116 | cmd = templateHostCmd % (target['hostcmd'].replace('$', '\\$$').replace('"', '\\"')); |
118 | cmd = templateTrgCmd % (target['trgcmdpost'].replace('$', '\\$$').replace('"', '\\"')); |
117 | f.write("\t${Q}echo '******************************'\n"); |
119 | f.write("\t${Q}echo '******************************'\n"); |
118 | f.write("\t${Q}echo '%s: %s'\n" % (target['name'], target['comment'])); |
120 | f.write("\t${Q}echo '%s: %s'\n" % (target['name'], target['comment'])); |
119 | f.write("\t${Q}echo '******************************'\n"); |
121 | f.write("\t${Q}echo '******************************'\n"); |
120 | f.write("\t${Q}(echo -e \"%s\") | ${SUDO} tee .hst.sh\n" % cmd.replace('\\n', '\\\\\\\\n').replace('\n', '\\n').replace('!', '"\'!\'"')); |
122 | f.write("\t${Q}(echo -e \"%s\") | ${SUDO} tee .trg-post.sh\n" % cmd.replace('\\n', '\\\\\\n').replace('\n', '\\n').replace('!', '"\'!\'"')); |
121 | f.write("\t${Q}${SUDO} chmod a+x .hst.sh\n"); |
123 | f.write("\t${Q}${SUDO} chmod a+x .trg-post.sh\n"); |
124 | |||
125 | if 'trgcmdpostpath' in target: |
||
126 | postpath = target['trgcmdpostpath'] |
||
127 | |||
128 | if 'hostcmd' in target: |
||
129 | cmd = templateHostCmd % (target['hostcmd'].replace('$', '\\$$').replace('"', '\\"')); |
||
130 | f.write("\t${Q}echo '******************************'\n"); |
||
131 | f.write("\t${Q}echo '%s: %s'\n" % (target['name'], target['comment'])); |
||
132 | f.write("\t${Q}echo '******************************'\n"); |
||
133 | f.write("\t${Q}(echo -e \"%s\") | ${SUDO} tee .hst.sh\n" % cmd.replace('\\n', '\\\\\\\\n').replace('\n', '\\n').replace('!', '"\'!\'"')); |
||
134 | f.write("\t${Q}${SUDO} chmod a+x .hst.sh\n"); |
||
135 | |||
136 | if 'hostcmdpost' in target: |
||
137 | cmd = templateHostCmd % (target['hostcmdpost'].replace('$', '\\$$').replace('"', '\\"')); |
||
138 | f.write("\t${Q}echo '******************************'\n"); |
||
139 | f.write("\t${Q}echo '%s: %s'\n" % (target['name'], target['comment'])); |
||
140 | f.write("\t${Q}echo '******************************'\n"); |
||
141 | f.write("\t${Q}(echo -e \"%s\") | ${SUDO} tee .hst-post.sh\n" % cmd.replace('\\n', '\\\\\\\\n').replace('\n', '\\n').replace('!', '"\'!\'"')); |
||
142 | f.write("\t${Q}${SUDO} chmod a+x .hst-post.sh\n"); |
||
122 | 143 | ||
123 | # start command here ... |
144 | # start command here ... |
124 | f.write("\t${Q}${SUDO} bash -c \""); |
145 | f.write("\t${Q}${SUDO} bash -c \""); |
125 | 146 | ||
126 | # extracting from multiple backup levels |
147 | # extracting from multiple backup levels |
... |
... |
||
146 | if proc: |
167 | if proc: |
147 | f.write("if [ -d proc ]; then mount -t proc proc proc; fi;"); |
168 | f.write("if [ -d proc ]; then mount -t proc proc proc; fi;"); |
148 | f.write("if [ -f ../.trg.sh ]; then mv ../.trg.sh .; chroot . ./.trg.sh || exit 1; fi; rm -f ./.trg.sh;"); |
169 | f.write("if [ -f ../.trg.sh ]; then mv ../.trg.sh .; chroot . ./.trg.sh || exit 1; fi; rm -f ./.trg.sh;"); |
149 | if proc: |
170 | if proc: |
150 | f.write("if [ -d proc ]; then umount proc || umount -l proc; fi;"); |
171 | f.write("if [ -d proc ]; then umount proc || umount -l proc; fi;"); |
172 | |||
151 | # - host |
173 | # - host |
152 | f.write("if [ -f ../.hst.sh ]; then ../.hst.sh || exit 1; fi; rm -f ../.hst.sh;"); |
174 | f.write("if [ -f ../.hst.sh ]; then ../.hst.sh || exit 1; fi; rm -f ../.hst.sh;"); |
153 | 175 | ||
176 | # - target post |
||
177 | if proc: |
||
178 | f.write("if [ -d proc ]; then mount -t proc proc proc; fi;"); |
||
179 | f.write("if [ -f ../.trg-post.sh ]; then mv ../.trg-post.sh ./%s; chroot ./%s ./.trg-post.sh || exit 1; fi; rm -f ./.trg-post.sh;" % (postpath, postpath)); |
||
180 | if proc: |
||
181 | f.write("if [ -d proc ]; then umount proc || umount -l proc; fi;"); |
||
182 | |||
183 | # - host post |
||
184 | f.write("if [ -f ../.hst-post.sh ]; then ../.hst-post.sh || exit 1; fi; rm -f ../.hst-post.sh;"); |
||
185 | |||
154 | 186 | ||
155 | # pack result |
187 | # pack result |
156 | if not 'temporary' in target or not target['temporary']: |
188 | if not 'temporary' in target or not target['temporary']: |
157 | # copy over snar file from previous level and add changes to the new one |
189 | # copy over snar file from previous level and add changes to the new one |
158 | f.write("[ ! -f ../%s.snar ] || cp ../%s.snar ../%s.snar;" % (target['dep'][0], target['dep'][0], target['name'])); |
190 | f.write("[ ! -f ../%s.snar ] || cp ../%s.snar ../%s.snar;" % (target['dep'][0], target['dep'][0], target['name'])); |