nebraska: Redirecting update URL

Update engine will be redirected to update using the locally running
nebraska when configs are updated.

```
// Start/stop verification.
localhost ~ # start nebraska
nebraska start/running, process 9092
localhost ~ # cat /mnt/stateful_partition/etc/lsb-release
CHROMEOS_AUSERVER=http://localhost:36343/update
localhost ~ # stop nebraska
nebraska stop/waiting
localhost ~ # cat /mnt/stateful_partition/etc/lsb-release
localhost ~ #

// Request redirection verification.
localhost ~ # update_engine_client --check_for_update
2021-08-12T00:01:57.708356Z INFO update_engine_client:
[update_engine_client.cc(513)] Initiating update check.
...
// Check update_engine.log
2021-08-12T00:01:57.714194Z INFO update_engine:
[omaha_request_action.cc(268)] Posting an Omaha request to
http://localhost:36855/update
```

BUG=b:184980277
TEST=# comment above

Change-Id: Ib7c36fea3205170ab8a833d6bf5088d9a0b5df91
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/dev-util/+/3089772
Tested-by: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: David Haddock <dhaddock@chromium.org>
Commit-Queue: Jae Hoon Kim <kimjae@chromium.org>
diff --git a/nebraska/nebraska.conf b/nebraska/nebraska.conf
index 6b97b01..5c4d684 100644
--- a/nebraska/nebraska.conf
+++ b/nebraska/nebraska.conf
@@ -13,6 +13,8 @@
 oom score -100
 
 env NEBRASKA_CONFIG_FILE=/usr/local/nebraska/config.json
+env OMAHA_FIELD="CHROMEOS_AUSERVER="
+env STATEFUL_LSB_RELEASE_FILE=/mnt/stateful_partition/etc/lsb-release
 
 pre-start script
   # If no JSON file for updating nebraska's config was provided, don't run
@@ -37,8 +39,17 @@
     exit 0
   fi
 
-  PORT="$(cat /run/nebraska/port)"
+  NEBRASKA_URL="http://localhost:$(cat /run/nebraska/port)"
   curl -X POST -d @"${NEBRASKA_CONFIG_FILE}" \
-      "http://localhost:${PORT}/update_config"
+      "${NEBRASKA_URL}/update_config"
 
+  # Redirect the requests of update_engine to nebraska.
+  mkdir -p "$(dirname "${STATEFUL_LSB_RELEASE_FILE}")" && \
+    touch "${STATEFUL_LSB_RELEASE_FILE}"
+  sed -i "/${OMAHA_FIELD}/d" "${STATEFUL_LSB_RELEASE_FILE}"
+  echo "${OMAHA_FIELD}${NEBRASKA_URL}/update" >> "${STATEFUL_LSB_RELEASE_FILE}"
+end script
+
+post-stop script
+  sed -i "/${OMAHA_FIELD}/d" "${STATEFUL_LSB_RELEASE_FILE}"
 end script