changelog shortlog graph tags branches changeset files revisions annotate raw help

Mercurial > infra > box / airootfs/root/.automated_script.sh

changeset 2: 2fafbe22bd34
author: Richard Westhaver <ellis@rwest.io>
date: Fri, 31 May 2024 17:30:09 -0400
permissions: -rwxr-xr-x
description: init releng
1 #!/usr/bin/env bash
2 
3 script_cmdline() {
4  local param
5  for param in $(</proc/cmdline); do
6  case "${param}" in
7  script=*)
8  echo "${param#*=}"
9  return 0
10  ;;
11  esac
12  done
13 }
14 
15 automated_script() {
16  local script rt
17  script="$(script_cmdline)"
18  if [[ -n "${script}" && ! -x /tmp/startup_script ]]; then
19  if [[ "${script}" =~ ^((http|https|ftp|tftp)://) ]]; then
20  # there's no synchronization for network availability before executing this script
21  printf '%s: waiting for network-online.target\n' "$0"
22  until systemctl --quiet is-active network-online.target; do
23  sleep 1
24  done
25  printf '%s: downloading %s\n' "$0" "${script}"
26  curl "${script}" --location --retry-connrefused --retry 10 -s -o /tmp/startup_script
27  rt=$?
28  else
29  cp "${script}" /tmp/startup_script
30  rt=$?
31  fi
32  if [[ ${rt} -eq 0 ]]; then
33  chmod +x /tmp/startup_script
34  printf '%s: executing automated script\n' "$0"
35  # note that script is executed when other services (like pacman-init) may be still in progress, please
36  # synchronize to "systemctl is-system-running --wait" when your script depends on other services
37  /tmp/startup_script
38  fi
39  fi
40 }
41 
42 if [[ $(tty) == "/dev/tty1" ]]; then
43  automated_script
44 fi