2022-09-29 13:56:39 +00:00
|
|
|
#!/bin/sh
|
|
|
|
# 2022-03-18, ungleich (foss at ungleich.ch)
|
|
|
|
# Copying: GPL3+
|
|
|
|
|
|
|
|
if [ $# -lt 2 ] ; then
|
|
|
|
echo "$0 network asn [nodryrun]"
|
|
|
|
echo "ASN needs to be in ASXXXXXX format"
|
|
|
|
echo "By default uses dry-run and does not create objects"
|
2022-09-29 13:57:27 +00:00
|
|
|
echo "Requires environment variable RIPE_API_PASSWORD to be set"
|
2022-09-29 13:56:39 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
network=$1; shift
|
|
|
|
asn=$1; shift
|
|
|
|
|
|
|
|
if [ $# -ge 1 ]; then
|
|
|
|
dryrun=""
|
|
|
|
else
|
|
|
|
dryrun="&dry-run"
|
|
|
|
fi
|
|
|
|
|
2022-09-29 13:57:27 +00:00
|
|
|
if [ -z "$RIPE_API_PASSWORD" ]; then
|
|
|
|
echo "You need to set RIPE_API_PASSWORD" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2022-09-29 13:56:39 +00:00
|
|
|
form=$(mktemp)
|
|
|
|
|
|
|
|
case ${network} in
|
|
|
|
*:*)
|
|
|
|
obj_type=route6
|
|
|
|
;;
|
|
|
|
*.*)
|
|
|
|
obj_type=route
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "No idea what to do with $network"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
cat > $form <<EOF
|
|
|
|
{
|
|
|
|
"objects": {
|
|
|
|
"object": [
|
|
|
|
{
|
|
|
|
"source": {
|
|
|
|
"id": "RIPE"
|
|
|
|
},
|
|
|
|
"attributes": {
|
|
|
|
"attribute": [
|
|
|
|
{
|
|
|
|
"name": "${obj_type}",
|
|
|
|
"value": "${network}"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "mnt-by",
|
|
|
|
"value": "mnt-ungleich"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "source",
|
|
|
|
"value": "RIPE"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "origin",
|
|
|
|
"value": "${asn}"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
cat ${form}
|
|
|
|
|
|
|
|
curl -X POST \
|
|
|
|
-H 'Content-Type: application/json' \
|
|
|
|
-H 'Accept: application/json' \
|
|
|
|
--data @${form} \
|
|
|
|
"https://rest.db.ripe.net/ripe/${obj_type}?password=${RIPE_API_PASSWORD}${dryrun}"
|
|
|
|
|
|
|
|
rm -f ${form}
|