Required arguments:
[ -u | --url <url> ]: The OCI image URL
+Optional arguments:
+[ --username <username> ]: The username for the registry
+[ --password <password> ]: The password for the registry
+
LXC internal arguments (do not pass manually!):
[ --name <name> ]: The container name
[ --path <path> ]: The path to the container
return 0
}
-options=$(getopt -o u:h -l help,url:,name:,path:,\
-rootfs:,mapped-uid:,mapped-gid: -- "$@")
+options=$(getopt -o u:h -l help,url:,username:,password:,\
+name:,path:,rootfs:,mapped-uid:,mapped-gid: -- "$@")
if [ $? -ne 0 ]; then
usage
eval set -- "$options"
OCI_URL=""
+OCI_USERNAME=
+OCI_PASSWORD=
+
LXC_MAPPED_GID=
LXC_MAPPED_UID=
LXC_NAME=
case "$1" in
-h|--help) usage && exit 1;;
-u|--url) OCI_URL=$2; shift 2;;
+ --username) OCI_USERNAME=$2; shift 2;;
+ --password) OCI_PASSWORD=$2; shift 2;;
--name) LXC_NAME=$2; shift 2;;
--path) LXC_PATH=$2; shift 2;;
--rootfs) LXC_ROOTFS=$2; shift 2;;
exit 1
fi
+if [ -n "$OCI_PASSWORD" ] && [ -z "$OCI_USERNAME" ]; then
+ echo "ERROR: password given but no username specified"
+ exit 1
+fi
+
USERNS=$(in_userns)
if [ "$USERNS" != "no" ]; then
fi
# Download the image - TODO - cache
-skopeo copy "${OCI_URL}" "oci:${DOWNLOAD_TEMP}:latest"
+skopeo_args=("")
+if [ -n "$OCI_USERNAME" ]; then
+ CREDENTIALS="${OCI_USERNAME}"
+ if [ -n "$OCI_PASSWORD" ]; then
+ CREDENTIALS="${CREDENTIALS}:${OCI_PASSWORD}"
+ fi
+ skopeo_args+=(--src-creds "${CREDENTIALS}")
+fi
+skopeo copy ${skopeo_args[@]} "${OCI_URL}" "oci:${DOWNLOAD_TEMP}:latest"
# Unpack the rootfs
echo "Unpacking the rootfs"