Adding a shell layer to find python version on the box
This commit is contained in:
Родитель
c70de6aa39
Коммит
35f1405acc
|
@ -2,11 +2,11 @@
|
|||
{
|
||||
"version": 1.0,
|
||||
"handlerManifest": {
|
||||
"disableCommand": "./vmaccess.py -disable",
|
||||
"enableCommand": "./vmaccess.py -enable",
|
||||
"installCommand": "./vmaccess.py -install",
|
||||
"uninstallCommand": "./vmaccess.py -uninstall",
|
||||
"updateCommand": "./vmaccess.py -update",
|
||||
"disableCommand": "extension_shim.sh -c ./vmaccess.py -d",
|
||||
"enableCommand": "extension_shim.sh -c ./vmaccess.py -e",
|
||||
"installCommand": "extension_shim.sh -c ./vmaccess.py -i",
|
||||
"uninstallCommand": "extension_shim.sh -c ./vmaccess.py -u",
|
||||
"updateCommand": "extension_shim.sh -c ./vmaccess.py -p",
|
||||
"rebootAfterInstall": false,
|
||||
"reportHeartbeat": false
|
||||
}
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Keeping the default command
|
||||
COMMAND=""
|
||||
PYTHON=""
|
||||
|
||||
USAGE="$(basename "$0") [-h] [-i|--install] [-u|--uninstall] [-d|--disable] [-e|--enable] [-p|--update]
|
||||
|
||||
Program to find the installed python on the box and invoke a Python extension script.
|
||||
|
||||
where:
|
||||
-h|--help show this help text
|
||||
-i|--install install the extension
|
||||
-u|--uninstall uninstall the extension
|
||||
-d|--disable disable the extension
|
||||
-e|--enable enable the extension
|
||||
-p|--update update the extension
|
||||
-c|--command command to run
|
||||
|
||||
example:
|
||||
# Install usage
|
||||
$ bash extension_shim.sh -i
|
||||
python ./vmaccess.py -install
|
||||
|
||||
# Custom executable python file
|
||||
$ bash extension_shim.sh -c ""hello.py"" -i
|
||||
python hello.py -install
|
||||
|
||||
# Custom executable python file with arguments
|
||||
$ bash extension_shim.sh -c ""hello.py --install""
|
||||
python hello.py --install
|
||||
"
|
||||
|
||||
function find_python(){
|
||||
local python_exec_command=$1
|
||||
|
||||
# Check if there is python defined.
|
||||
if command -v python >/dev/null 2>&1 ; then
|
||||
eval ${python_exec_command}="python"
|
||||
else
|
||||
# Python was not found. Searching for Python3 now.
|
||||
if command -v python >/dev/null 2>&1 ; then
|
||||
eval ${python_exec_command}="python3"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Transform long options to short ones for getopts support (getopts doesn't support long args)
|
||||
for arg in "$@"; do
|
||||
shift
|
||||
case "$arg" in
|
||||
"--help") set -- "$@" "-h" ;;
|
||||
"--install") set -- "$@" "-i" ;;
|
||||
"--update") set -- "$@" "-p" ;;
|
||||
"--enable") set -- "$@" "-e" ;;
|
||||
"--disable") set -- "$@" "-d" ;;
|
||||
"--uninstall") set -- "$@" "-u" ;;
|
||||
*) set -- "$@" "$arg"
|
||||
esac
|
||||
done
|
||||
|
||||
if [ -z "$arg" ]
|
||||
then
|
||||
echo "$USAGE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the arguments
|
||||
while getopts "iudephc:?" o; do
|
||||
case "${o}" in
|
||||
h|\?)
|
||||
echo "$USAGE"
|
||||
exit 0
|
||||
;;
|
||||
i)
|
||||
operation="-install"
|
||||
;;
|
||||
u)
|
||||
operation="-uninstall"
|
||||
;;
|
||||
d)
|
||||
operation="-disable"
|
||||
;;
|
||||
e)
|
||||
operation="-enable"
|
||||
;;
|
||||
p)
|
||||
operation="-update"
|
||||
;;
|
||||
c)
|
||||
COMMAND="$OPTARG"
|
||||
;;
|
||||
*)
|
||||
echo "$USAGE" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
shift $((OPTIND-1))
|
||||
|
||||
# If find_python is not able to find a python installed, $PYTHON will be null.
|
||||
find_python PYTHON
|
||||
|
||||
|
||||
if [ -z "$PYTHON" ]; then
|
||||
echo "No Python interpreter found on the box" >&2
|
||||
exit 51 # Not Supported
|
||||
else
|
||||
`${PYTHON} --version`
|
||||
fi
|
||||
|
||||
${PYTHON} ${COMMAND} ${operation}
|
||||
# DONE
|
|
@ -2,7 +2,7 @@
|
|||
<ExtensionImage xmlns="http://schemas.microsoft.com/windowsazure">
|
||||
<ProviderNameSpace>Microsoft.OSTCExtensions</ProviderNameSpace>
|
||||
<Type>VMAccessForLinux</Type>
|
||||
<Version>1.5.0</Version>
|
||||
<Version>1.5.1</Version>
|
||||
<Label>Microsoft Azure VM Access Extension for Linux Virtual Machines</Label>
|
||||
<HostingResources>VmRole</HostingResources>
|
||||
<MediaLink></MediaLink>
|
||||
|
|
|
@ -100,13 +100,6 @@ def enable():
|
|||
hutil.log("Succeeded in reset sshd_config.")
|
||||
|
||||
if remove_user:
|
||||
if re.match("^[a-z][-a-z0-9_]*$", remove_user) is None:
|
||||
waagent.AddExtensionEvent(name=hutil.get_name(),
|
||||
op=waagent.WALAEventOperation.Enable,
|
||||
isSuccess=False,
|
||||
message="(03002)Argument error, invalid remove_user")
|
||||
raise Exception("'remove_user' does not match the regular expression '^[a-z][-a-z0-9_]*$'")
|
||||
|
||||
waagent.AddExtensionEvent(name=hutil.get_name(), op="scenario", isSuccess=True, message="remove-user")
|
||||
_remove_user_account(remove_user, hutil)
|
||||
|
||||
|
@ -190,13 +183,6 @@ def _set_user_account_pub_key(protect_settings, hutil):
|
|||
return
|
||||
|
||||
user_name = protect_settings['username']
|
||||
if re.match("^[a-z][-a-z0-9_]*$", user_name) is None:
|
||||
waagent.AddExtensionEvent(name=hutil.get_name(),
|
||||
op=waagent.WALAEventOperation.Enable,
|
||||
isSuccess=False,
|
||||
message="(03002)Argument error, invalid username")
|
||||
raise Exception("'username' does not match the regular expression '^[a-z][-a-z0-9_]*$'")
|
||||
|
||||
user_pass = protect_settings.get('password')
|
||||
cert_txt = protect_settings.get('ssh_key')
|
||||
expiration = protect_settings.get('expiration')
|
||||
|
|
Загрузка…
Ссылка в новой задаче