File: //sbin/azure-repo-svc
#!/bin/bash
PATH=/sbin:/bin:/usr/bin:/usr/sbin
export PATH
Debug=1
ProtocolFile="/var/lib/waagent/Protocol"
RepoConf="/etc/yum.repos.d/CentOS-Base.repo"
main() {
let try=0
while [ "$try" -lt 10 ]
do
if [ ! -r "$ProtocolFile" ]; then
((try++))
sleep 2
else
break
fi
done
if [ "$try" -eq 10 ]; then
RETVAL=1
exit $RETVAL
fi
if [ -r "$ProtocolFile" ]; then
protocol=$(cat $ProtocolFile)
if [ "$protocol" = "WireProtocol" ]; then
# Public Azure
[ "$Debug" -eq 1 ] && echo "Azure wire server detected."
if ( `grep -qe '^[\s\t]*\#[\s\t]*baseurl=' $RepoConf` ); then
yum clean all 1>/dev/null 2>&1
fi
sed -i 's/^[\s\t]*mirrorlist=/\#mirrorlist=/g' $RepoConf
sed -i 's/^[\s\t]*\#[\s\t]*baseurl=/baseurl=/g' $RepoConf
elif [ "$protocol" = "MetadataProtocol" ]; then
# Azure Stack
[ "$Debug" -eq 1 ] && echo "Azure Stack metadata endpoint detected."
if ( `grep -qe '^[\s\t]*\#[\s\t]*mirrorlist=' $RepoConf` ); then
yum clean all 1>/dev/null 2>&1
fi
sed -i 's/^[\s\t]*\#[\s\t]*mirrorlist=/mirrorlist=/g' $RepoConf
sed -i 's/^[\s\t]*baseurl=/\#baseurl=/g' $RepoConf
else
echo "Error: $ProtocolFile contents do not match any known endpoint types."
RETVAL=1
exit $RETVAL
fi
else
RETVAL=1
echo "File not found: $ProtocolFile"
exit $RETVAL
fi
return 0
}
main "$@"