| 223 | |
| 224 | |
| 225 | class ShellScriptAction(ShellCommandAction): |
| 226 | def __init__( |
| 227 | self, |
| 228 | name, |
| 229 | action_exec_id, |
| 230 | script_local_path_abs, |
| 231 | named_args=None, |
| 232 | positional_args=None, |
| 233 | env_vars=None, |
| 234 | user=None, |
| 235 | sudo=False, |
| 236 | timeout=None, |
| 237 | cwd=None, |
| 238 | sudo_password=None, |
| 239 | ): |
| 240 | super(ShellScriptAction, self).__init__( |
| 241 | name=name, |
| 242 | action_exec_id=action_exec_id, |
| 243 | command=None, |
| 244 | user=user, |
| 245 | env_vars=env_vars, |
| 246 | sudo=sudo, |
| 247 | timeout=timeout, |
| 248 | cwd=cwd, |
| 249 | sudo_password=sudo_password, |
| 250 | ) |
| 251 | self.script_local_path_abs = script_local_path_abs |
| 252 | self.named_args = named_args |
| 253 | self.positional_args = positional_args |
| 254 | |
| 255 | def get_full_command_string(self): |
| 256 | return self._format_command() |
| 257 | |
| 258 | def _format_command(self): |
| 259 | script_arguments = self._get_script_arguments( |
| 260 | named_args=self.named_args, positional_args=self.positional_args |
| 261 | ) |
| 262 | if self.sudo: |
| 263 | if script_arguments: |
| 264 | command = quote_unix( |
| 265 | "%s %s" % (self.script_local_path_abs, script_arguments) |
| 266 | ) |
| 267 | else: |
| 268 | command = quote_unix(self.script_local_path_abs) |
| 269 | |
| 270 | sudo_arguments = " ".join(self._get_common_sudo_arguments()) |
| 271 | command = "sudo %s -- bash -c %s" % (sudo_arguments, command) |
| 272 | else: |
| 273 | if self.user and self.user != LOGGED_USER_USERNAME: |
| 274 | # Need to use sudo to run as a different user |
| 275 | user = quote_unix(self.user) |
| 276 | |
| 277 | if script_arguments: |
| 278 | command = quote_unix( |
| 279 | "%s %s" % (self.script_local_path_abs, script_arguments) |
| 280 | ) |
| 281 | else: |
| 282 | command = quote_unix(self.script_local_path_abs) |
no outgoing calls