diff --git a/net/Makefile b/net/Makefile index 18284d28e286..54fab77d143a 100644 --- a/net/Makefile +++ b/net/Makefile @@ -157,6 +157,7 @@ SUBDIR += gogoc SUBDIR += google-cloud-sdk SUBDIR += google-daemon + SUBDIR += google-startup-scripts SUBDIR += googlecl SUBDIR += gopher SUBDIR += gotthard diff --git a/net/google-startup-scripts/Makefile b/net/google-startup-scripts/Makefile new file mode 100644 index 000000000000..47d51739ebdd --- /dev/null +++ b/net/google-startup-scripts/Makefile @@ -0,0 +1,55 @@ +# Created by: Steve Wills +# $FreeBSD$ + +PORTNAME= google-startup-scripts +PORTVERSION= 1.2.1 +CATEGORIES= net +MASTER_SITES= GHR + +MAINTAINER= swills@FreeBSD.org +COMMENT= Startup scripts that interact with Google Compute Engine VMs + +BUILD_DEPENDS= python:${PORTSDIR}/lang/python +RUN_DEPENDS= python:${PORTSDIR}/lang/python \ + curl:${PORTSDIR}/ftp/curl \ + bash:${PORTSDIR}/shells/bash \ + flock:${PORTSDIR}/sysutils/flock + +USES= python shebangfix +USE_GITHUB= yes +GH_ACCOUNT= GoogleCloudPlatform +GH_PROJECT= compute-image-packages +USE_RC_SUBR= google-startup +WRKSRC_SUBDIR= ${PORTNAME} + +SHEBANG_FILES= usr/share/google/fetch_script \ + usr/share/google/first-boot \ + usr/share/google/get_metadata_value \ + usr/share/google/onboot \ + usr/share/google/regenerate-host-keys \ + usr/share/google/run-scripts \ + usr/share/google/run-shutdown-scripts \ + usr/share/google/run-startup-scripts \ + usr/share/google/set-hostname \ + usr/share/google/boto/boot_setup.py + +post-patch: + @${RM} ${WRKSRC}/usr/share/google/safe_format_and_mount \ + ${WRKSRC}/usr/share/google/virtionet-irq-affinity + @${REINPLACE_CMD} -e 's|%%PREFIX%%|${PREFIX}|g' \ + ${WRKSRC}/usr/share/google/fetch_script \ + ${WRKSRC}/usr/share/google/first-boot \ + ${WRKSRC}/usr/share/google/onboot \ + ${WRKSRC}/usr/share/google/run-shutdown-scripts \ + ${WRKSRC}/usr/share/google/run-startup-scripts \ + ${WRKSRC}/usr/share/google/boto/boot_setup.py + @${RM} ${WRKSRC}/usr/share/google/*.bak \ + ${WRKSRC}/usr/share/google/*.orig + +do-build: + ${PYTHON_CMD} -m compileall ${WRKSRC}/usr/share/google/boto + +do-install: + cd ${WRKSRC}/usr/share ; ${COPYTREE_BIN} google ${STAGEDIR}${PREFIX}/share + +.include diff --git a/net/google-startup-scripts/distinfo b/net/google-startup-scripts/distinfo new file mode 100644 index 000000000000..1ff04deb539a --- /dev/null +++ b/net/google-startup-scripts/distinfo @@ -0,0 +1,2 @@ +SHA256 (google-startup-scripts-1.2.1.tar.gz) = e70805809bd3e1a52f191391bd5a2255dd794169ba6402f0a3c46f2def67e13a +SIZE (google-startup-scripts-1.2.1.tar.gz) = 65967 diff --git a/net/google-startup-scripts/files/google-startup.in b/net/google-startup-scripts/files/google-startup.in new file mode 100644 index 000000000000..32538e131d71 --- /dev/null +++ b/net/google-startup-scripts/files/google-startup.in @@ -0,0 +1,36 @@ +#!/bin/sh + +# $FreeBSD$ +# +# PROVIDE: google-startup +# BEFORE: LOGIN +# REQUIRE: syslogd +# KEYWORD: shutdown +# +# Add the following line to /etc/rc.conf to enable google-startup: +# +# google_startup_enable="YES" +# + +. /etc/rc.subr + +name="google_startup" +rcvar="google_startup_enable" +start_cmd="google_start" +stop_cmd="google_stop" + +google_start() +{ + %%PREFIX%%/share/google/onboot + %%PREFIX%%/share/google/run-startup-scripts +} + +google_stop() +{ + %%PREFIX%%/share/google/run-shutdown-scripts +} + +google_startup_enable=${google_startup_enable:-"NO"} + +load_rc_config "${name}" +run_rc_command "$1" diff --git a/net/google-startup-scripts/files/patch-usr_share_google_boto_boot__setup.py b/net/google-startup-scripts/files/patch-usr_share_google_boto_boot__setup.py new file mode 100644 index 000000000000..0dea4598e04a --- /dev/null +++ b/net/google-startup-scripts/files/patch-usr_share_google_boto_boot__setup.py @@ -0,0 +1,15 @@ +--- usr/share/google/boto/boot_setup.py.orig 2014-12-05 20:59:35 UTC ++++ usr/share/google/boto/boot_setup.py +@@ -31,9 +31,9 @@ import urllib2 + + NUMERIC_PROJECT_ID_URL=('http://169.254.169.254/' + 'computeMetadata/v1/project/numeric-project-id') +-SYSTEM_BOTO_CONFIG_TEMPLATE='/etc/boto.cfg.template' +-SYSTEM_BOTO_CONFIG='/etc/boto.cfg' +-AUTH_PLUGIN_DIR='/usr/share/google/boto/boto_plugins' ++SYSTEM_BOTO_CONFIG_TEMPLATE='%%PREFIX%%/etc/boto.cfg.template' ++SYSTEM_BOTO_CONFIG='%%PREFIX%%/etc/boto.cfg' ++AUTH_PLUGIN_DIR='%%PREFIX%%/share/google/boto/boto_plugins' + + + def GetNumericProjectId(): diff --git a/net/google-startup-scripts/files/patch-usr_share_google_fetch__script b/net/google-startup-scripts/files/patch-usr_share_google_fetch__script new file mode 100644 index 000000000000..f0dcbc754e1e --- /dev/null +++ b/net/google-startup-scripts/files/patch-usr_share_google_fetch__script @@ -0,0 +1,29 @@ +--- usr/share/google/fetch_script.orig 2014-12-24 22:40:30 UTC ++++ usr/share/google/fetch_script +@@ -84,7 +84,7 @@ function download_url_with_logfile() { + + # Unauthenticated download of the object. + log "Downloading url from ${url} to ${dest} using curl" +- curl --max-time "${CURL_TIMEOUT}" --retry "${CURL_RETRY_LIMIT}" \ ++ curl -s --max-time "${CURL_TIMEOUT}" --retry "${CURL_RETRY_LIMIT}" \ + 2>> "${logfile}" -o "${dest}" -- "${url}" && return 0; + + log "Failed to download $url" +@@ -108,7 +108,7 @@ function download_url() { + + function get_metadata_attribute() { + local readonly varname=$1 +- /usr/share/google/get_metadata_value "attributes/${varname}" ++ %%PREFIX%%/share/google/get_metadata_value "attributes/${varname}" + return $? + } + +@@ -135,7 +135,7 @@ function fetch_script() { + echo "${metadata_script}" > "${script}" + log "${script_type} script found in metadata." + else +- log $(curl "http://metadata.google.internal/computeMetadata/v1/instance/?recursive=True" -H "Metadata-Flavor: Google") ++ log $(curl -s "http://metadata.google.internal/computeMetadata/v1/instance/?recursive=True" -H "Metadata-Flavor: Google") + log "No ${script_type} script found in metadata." + fi + fi diff --git a/net/google-startup-scripts/files/patch-usr_share_google_first-boot b/net/google-startup-scripts/files/patch-usr_share_google_first-boot new file mode 100644 index 000000000000..2507cd3fea65 --- /dev/null +++ b/net/google-startup-scripts/files/patch-usr_share_google_first-boot @@ -0,0 +1,22 @@ +--- usr/share/google/first-boot.orig 2014-12-24 22:40:30 UTC ++++ usr/share/google/first-boot +@@ -31,7 +31,7 @@ function log() { + + function get_instance_id() { + # Do not retry to get the metadata value on failures. +- MDS_TRIES=1 ${PREFIX}/usr/share/google/get_metadata_value id 2>/dev/null ++ MDS_TRIES=1 ${PREFIX}%%PREFIX%%/share/google/get_metadata_value id 2>/dev/null + } + + # Output the instance id. +@@ -80,8 +80,8 @@ log "Running first-boot" + declare -r INSTANCE_ID=$(cat ${INSTANCE_FILE}) + + # Regenerate host keys for ssh. +-if [[ -x ${PREFIX}/usr/share/google/regenerate-host-keys ]]; then +- ${PREFIX}/usr/share/google/regenerate-host-keys ++if [[ -x ${PREFIX}%%PREFIX%%/share/google/regenerate-host-keys ]]; then ++ ${PREFIX}%%PREFIX%%/share/google/regenerate-host-keys + fi + + # Make a per-instance data directory. diff --git a/net/google-startup-scripts/files/patch-usr_share_google_get__metadata__value b/net/google-startup-scripts/files/patch-usr_share_google_get__metadata__value new file mode 100644 index 000000000000..23d619e17384 --- /dev/null +++ b/net/google-startup-scripts/files/patch-usr_share_google_get__metadata__value @@ -0,0 +1,11 @@ +--- usr/share/google/get_metadata_value.orig 2014-12-24 22:41:29 UTC ++++ usr/share/google/get_metadata_value +@@ -26,7 +26,7 @@ function metadata_get_url_code() { + + function print_metadata_value() { + local readonly tmpfile=$(mktemp) +- curl -f "${1}" -H "Metadata-Flavor: Google" > ${tmpfile} 2>/dev/null ++ curl -s -f "${1}" -H "Metadata-Flavor: Google" > ${tmpfile} 2>/dev/null + local readonly return_code=$? + # If the command completed successfully, print the metadata value to stdout. + if [[ ${return_code} == 0 ]]; then diff --git a/net/google-startup-scripts/files/patch-usr_share_google_onboot b/net/google-startup-scripts/files/patch-usr_share_google_onboot new file mode 100644 index 000000000000..9960a31103b3 --- /dev/null +++ b/net/google-startup-scripts/files/patch-usr_share_google_onboot @@ -0,0 +1,46 @@ +--- usr/share/google/onboot.orig 2014-12-24 22:40:30 UTC ++++ usr/share/google/onboot +@@ -33,7 +33,7 @@ else + declare -r LOGGER=/bin/logger + fi + +-declare -r BOTO_SETUP_SCRIPT=/usr/share/google/boto/boot_setup.py ++declare -r BOTO_SETUP_SCRIPT=%%PREFIX%%/share/google/boto/boot_setup.py + declare -r GOOGLE_ENVIRONMENT=/var/run/google.environment + + function log() { +@@ -42,20 +42,20 @@ function log() { + } + + function virtionet_irq_affinity() { +- if [[ -x /usr/share/google/virtionet-irq-affinity ]]; then +- /usr/share/google/virtionet-irq-affinity ++ if [[ -x %%PREFIX%%/share/google/virtionet-irq-affinity ]]; then ++ %%PREFIX%%/share/google/virtionet-irq-affinity + fi + } + + function first_boot() { +- if [[ -x /usr/share/google/first-boot ]]; then +- /usr/share/google/first-boot ++ if [[ -x %%PREFIX%%/share/google/first-boot ]]; then ++ %%PREFIX%%/share/google/first-boot + fi + } + + function get_metadata_value() { + local readonly varname=$1 +- /usr/share/google/get_metadata_value ${varname} ++ %%PREFIX%%/share/google/get_metadata_value ${varname} + return $? + } + +@@ -106,7 +106,7 @@ function print_ssh_key_fingerprints() { + return 0 + } + +-virtionet_irq_affinity ++#virtionet_irq_affinity + first_boot + do_init + print_ssh_key_fingerprints diff --git a/net/google-startup-scripts/files/patch-usr_share_google_regenerate-host-keys b/net/google-startup-scripts/files/patch-usr_share_google_regenerate-host-keys new file mode 100644 index 000000000000..a6421c8d2785 --- /dev/null +++ b/net/google-startup-scripts/files/patch-usr_share_google_regenerate-host-keys @@ -0,0 +1,20 @@ +--- usr/share/google/regenerate-host-keys.orig 2014-12-24 22:40:30 UTC ++++ usr/share/google/regenerate-host-keys +@@ -29,7 +29,7 @@ sshd_cmd() { + if [[ -x /etc/init.d/ssh || -f /etc/init/ssh.conf ]]; then + service ssh ${cmd} + fi +- if [[ -x /etc/init.d/sshd || -f /etc/init/sshd.conf ]]; then ++ if [[ -x /etc/init.d/sshd || -f /etc/init/sshd.conf || -f /etc/rc.d/sshd ]]; then + service sshd ${cmd} + fi + } +@@ -55,7 +55,7 @@ generate_key() { + + regenerate_host_keys() { + log "Regenerating SSH Host Keys for: $new_ip_address (previously $old_ip_address)." +- rm -f /etc/ssh/ssh_host_key /etc/ssh_host_key.pub # SSH1 RSA key. ++ rm -f /etc/ssh/ssh_host_key /etc/ssh/ssh_host_key.pub # SSH1 RSA key. + for key_file in /etc/ssh/ssh_host_*_key; do + # Parse out the type of key, matching the * in the for loop command above. + key_type=$(basename "${key_file}" _key) diff --git a/net/google-startup-scripts/files/patch-usr_share_google_run-shutdown-scripts b/net/google-startup-scripts/files/patch-usr_share_google_run-shutdown-scripts new file mode 100644 index 000000000000..dda22124aedc --- /dev/null +++ b/net/google-startup-scripts/files/patch-usr_share_google_run-shutdown-scripts @@ -0,0 +1,10 @@ +--- usr/share/google/run-shutdown-scripts.orig 2014-12-24 22:40:30 UTC ++++ usr/share/google/run-shutdown-scripts +@@ -27,5 +27,5 @@ declare -r SHUTDOWN_SCRIPT=/var/run/goog + # buffers to disk. + # + # The shutdown script blocks other shutdown operations from proceeding. +-/usr/share/google/fetch_script ${SHUTDOWN_SCRIPT} shutdown +-/usr/share/google/run-scripts ${SHUTDOWN_SCRIPT} shutdown ++%%PREFIX%%/share/google/fetch_script ${SHUTDOWN_SCRIPT} shutdown ++%%PREFIX%%/share/google/run-scripts ${SHUTDOWN_SCRIPT} shutdown diff --git a/net/google-startup-scripts/files/patch-usr_share_google_run-startup-scripts b/net/google-startup-scripts/files/patch-usr_share_google_run-startup-scripts new file mode 100644 index 000000000000..97e7ce663de7 --- /dev/null +++ b/net/google-startup-scripts/files/patch-usr_share_google_run-startup-scripts @@ -0,0 +1,13 @@ +--- usr/share/google/run-startup-scripts.orig 2014-12-24 22:40:30 UTC ++++ usr/share/google/run-startup-scripts +@@ -21,7 +21,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/ + declare -r STARTUP_SCRIPT=/var/run/google.startup.script + + # Make sure all udev changes settle before running startup scripts. +-udevadm settle ++#udevadm settle + +-/usr/share/google/fetch_script ${STARTUP_SCRIPT} startup +-/usr/share/google/run-scripts ${STARTUP_SCRIPT} startup ++%%PREFIX%%/share/google/fetch_script ${STARTUP_SCRIPT} startup ++%%PREFIX%%/share/google/run-scripts ${STARTUP_SCRIPT} startup diff --git a/net/google-startup-scripts/pkg-descr b/net/google-startup-scripts/pkg-descr new file mode 100644 index 000000000000..b862fabad266 --- /dev/null +++ b/net/google-startup-scripts/pkg-descr @@ -0,0 +1,3 @@ +A set of startup scripts that interact with the virtual machine environment. + +WWW: https://github.com/GoogleCloudPlatform/compute-image-packages/tree/master/google-startup-scripts diff --git a/net/google-startup-scripts/pkg-plist b/net/google-startup-scripts/pkg-plist new file mode 100644 index 000000000000..1879f77dc7f9 --- /dev/null +++ b/net/google-startup-scripts/pkg-plist @@ -0,0 +1,13 @@ +share/google/boto/boot_setup.py +share/google/boto/boot_setup.pyc +share/google/boto/boto_plugins/compute_auth.py +share/google/boto/boto_plugins/compute_auth.pyc +share/google/fetch_script +share/google/first-boot +share/google/get_metadata_value +share/google/onboot +share/google/regenerate-host-keys +share/google/run-scripts +share/google/run-shutdown-scripts +share/google/run-startup-scripts +share/google/set-hostname