parent
b57c047c4a
commit
ef254cb0af
@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
NETWORK_EC2=yes
|
||||
SERVICES='one-context'
|
||||
|
@ -1,4 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
rm /etc/one-context.d/loc-05-grow-rootfs /etc/one-context.d/loc-10-network-pci /etc/one-context.d/loc-14-mount-swap
|
||||
rm /etc/one-context.d/loc-30-console /etc/one-context.d/net-11-fix-loopback /etc/one-context.d/net-99-report-ready
|
@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SERVICES='one-context'
|
||||
|
@ -1,15 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
activate_swaps() {
|
||||
|
||||
activate_swaps_linux() {
|
||||
SWAP_DRIVES=$(blkid -t TYPE="swap" -o device)
|
||||
for SWAP in $SWAP_DRIVES ; do
|
||||
if [ -z "$(swapon -s | grep $SWAP)" ]; then
|
||||
swapon $SWAP
|
||||
fi
|
||||
done
|
||||
|
||||
}
|
||||
|
||||
activate_swaps
|
||||
|
||||
if [ "$(uname -s)" = 'Linux' ]; then
|
||||
activate_swaps_linux
|
||||
fi
|
||||
|
@ -1,66 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# -------------------------------------------------------------------------- #
|
||||
# Copyright 2010-2016, OpenNebula Systems #
|
||||
# #
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
|
||||
# not use this file except in compliance with the License. You may obtain #
|
||||
# a copy of the License at #
|
||||
# #
|
||||
# http://www.apache.org/licenses/LICENSE-2.0 #
|
||||
# #
|
||||
# Unless required by applicable law or agreed to in writing, software #
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, #
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
|
||||
# See the License for the specific language governing permissions and #
|
||||
# limitations under the License. #
|
||||
#--------------------------------------------------------------------------- #
|
||||
|
||||
# defaults
|
||||
USERNAME=${USERNAME:-root}
|
||||
USERNAME_SHELL=${USERNAME_SHELL:-/usr/local/bin/bash}
|
||||
USERNAME_SUDO=${USERNAME_SUDO:-${GRANT_SUDO:-YES}}
|
||||
USERNAME_SUDO=$(echo "${USERNAME_SUDO}" | tr '[:lower:]' '[:upper:]')
|
||||
USERNAME_PASSWORD_RESET=${USERNAME_PASSWORD_RESET:-NO}
|
||||
USERNAME_PASSWORD_RESET=$(echo "${USERNAME_PASSWORD_RESET}" | tr '[:lower:]' '[:upper:]')
|
||||
|
||||
if ! getent passwd "${USERNAME}" > /dev/null 2>&1; then
|
||||
pw useradd "${USERNAME}" -m -s "${USERNAME_SHELL}"
|
||||
fi
|
||||
|
||||
if [ "${USERNAME_SUDO}" == "YES" ] && [ "${USERNAME}" != "root" ]; then
|
||||
echo "${USERNAME} ALL=(ALL) NOPASSWD:ALL" >/usr/local/etc/sudoers.d/one-context
|
||||
chmod 0440 /etc/sudoers.d/one-context
|
||||
elif [ -f /etc/sudoers.d/one-context ]; then
|
||||
unlink /etc/sudoers.d/one-context
|
||||
fi
|
||||
|
||||
if [ -n "${CRYPTED_PASSWORD_BASE64}" ]; then
|
||||
CRYPTED_PASSWORD=$(echo $CRYPTED_PASSWORD_BASE64 | base64 -d)
|
||||
echo $CRYPTED_PASSWORD | pw mod user $USERNAME -H 0
|
||||
elif [ -n "${PASSWORD_BASE64}" ]; then
|
||||
PASSWORD=$(echo $PASSWORD_BASE64 | base64 -d)
|
||||
echo $PASSWORD | pw mod user $USERNAME -h 0
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
passwd "${USERNAME}" <<EOF
|
||||
${PASSWORD}
|
||||
${PASSWORD}
|
||||
EOF
|
||||
fi
|
||||
elif [ -n "${CRYPTED_PASSWORD}" ]; then
|
||||
echo $CRYPTED_PASSWORD | pw mod user $USERNAME -H 0
|
||||
elif [ -n "${PASSWORD}" ]; then
|
||||
echo $PASSWORD | pw mod user $USERNAME -h 0
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
passwd "${USERNAME}" <<EOF
|
||||
${PASSWORD}
|
||||
${PASSWORD}
|
||||
EOF
|
||||
fi
|
||||
elif [ "${USERNAME_PASSWORD_RESET}" = 'YES' ]; then
|
||||
if command -v usermod >/dev/null 2>&1; then
|
||||
pw usermod -p '*' "${USERNAME}"
|
||||
fi
|
||||
fi
|
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
for DEV_TTY in /dev/tty[0-9]*; do
|
||||
TERM=linux setterm -blank 0 -powerdown 0 >>"${DEV_TTY}"
|
||||
# Linux
|
||||
for _dev_tty in $(find /dev -type c -name 'tty[0-9]*'); do
|
||||
TERM=linux setterm -blank 0 -powerdown 0 >>"${_dev_tty}"
|
||||
done
|
||||
|
@ -1,133 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
function set_hostname() {
|
||||
local hostname=$1
|
||||
|
||||
if [ -d /run/systemd/system/ ]; then
|
||||
hostnamectl set-hostname --static "${hostname}"
|
||||
else
|
||||
if [ -f /etc/sysconfig/network ]; then
|
||||
sed -i '/^HOSTNAME=.*$/d' /etc/sysconfig/network
|
||||
echo "HOSTNAME=${hostname}" >>/etc/sysconfig/network
|
||||
else
|
||||
echo "${hostname}" >/etc/hostname
|
||||
fi
|
||||
|
||||
hostname "${hostname}"
|
||||
fi
|
||||
}
|
||||
|
||||
function set_domainname() {
|
||||
domain=$1
|
||||
sed -i '/^domain .*/d' /etc/resolv.conf
|
||||
echo "domain ${domain}" >>/etc/resolv.conf
|
||||
}
|
||||
|
||||
function get_first_ip() {
|
||||
local ip
|
||||
|
||||
ip=${ip:-$(ifconfig | grep inet | head -n 1 | awk '{print $2}')}
|
||||
echo "${ip}"
|
||||
}
|
||||
|
||||
function get_dns_name() {
|
||||
text=$(LC_ALL=C getent hosts "$1" 2>/dev/null)
|
||||
[ $? = 0 ] || exit 0
|
||||
[[ $text == *"has no PTR record" ]] && exit 0
|
||||
name=$(echo "$text" | awk '/(has address|name pointer)/ {print $(NF)}' | sed 's/\.$//')
|
||||
echo $name
|
||||
}
|
||||
|
||||
function update_hosts() {
|
||||
ip=$1
|
||||
name=$2
|
||||
hostname=$3
|
||||
|
||||
if [ "x${hostname}" = "x${name}" ]; then
|
||||
hosts="${name}"
|
||||
else
|
||||
hosts="${name} ${hostname}"
|
||||
fi
|
||||
|
||||
note='# one-contextd'
|
||||
entry="${ip}$(printf '\t')${hosts}$(printf '\t')$(printf '\t')${note}"
|
||||
newline="$(printf '\n')"
|
||||
|
||||
# update our old entry
|
||||
if grep -qi "${note}" /etc/hosts; then
|
||||
sed -i -e "s/^.*${note}/${entry}/" /etc/hosts
|
||||
# update entry with same IP (but not localhost)
|
||||
elif grep -E "^${ip}\s" /etc/hosts | grep -qv localhost; then
|
||||
sed -i -e "/localhost/! s/^${ip}\s.*\$/${entry}/" /etc/hosts
|
||||
# update entry with same name
|
||||
elif grep -qE "\s${name}(\s|#|\$)" /etc/hosts; then
|
||||
sed -i -re "s/^.*\s${name}([ #\t].*|$)/${entry}/" /etc/hosts
|
||||
# create new entry
|
||||
elif [ -f /etc/hosts ]; then
|
||||
sed -i -e '1s/^/'"${entry}"$'\\\n/' /etc/hosts
|
||||
else
|
||||
echo -e "${entry}" >>/etc/hosts
|
||||
fi
|
||||
}
|
||||
|
||||
#####
|
||||
|
||||
first_ip=$(get_first_ip)
|
||||
|
||||
if [ -n "$SET_HOSTNAME" ]; then
|
||||
name=$(echo "$SET_HOSTNAME" | \
|
||||
sed -e 's/[^-a-zA-Z0-9\.]/-/g' -e 's/^-*//g' -e 's/-*$//g')
|
||||
|
||||
elif [ -n "$DNS_HOSTNAME" ]; then
|
||||
name=$(get_dns_name "${first_ip}")
|
||||
|
||||
elif [ "${EC2_HOSTNAME}" = 'YES' ]; then
|
||||
# try to quickly get hostname from the EC2 metadata server or
|
||||
# create hostname based on the first IPv4 (format: "ip-1-2-3-4")
|
||||
name=$(curl -sf -m 5 'http://169.254.169.254/latest/meta-data/local-hostname' 2>/dev/null)
|
||||
if [ -z "${name}" ]; then
|
||||
name="$(echo "${first_ip}" | grep -x '[0-9\.]\+' | tr . -)"
|
||||
if [ -n "${name}" ]; then
|
||||
name="ip-${name}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${name}" ]; then
|
||||
# split host and domain names
|
||||
hostname=${name%%.*}
|
||||
domain=${name#*.}
|
||||
if [ "x${domain}" = "x${hostname}" ]; then
|
||||
domain=''
|
||||
fi
|
||||
|
||||
if [ -n "${domain}" ]; then
|
||||
set_hostname "${hostname}.${domain}"
|
||||
else
|
||||
set_hostname "${hostname}"
|
||||
fi
|
||||
|
||||
if [ -n "${domain}" ]; then
|
||||
set_domainname "${domain}"
|
||||
fi
|
||||
|
||||
if [ -n "${DNS_HOSTNAME}" ]; then
|
||||
host_ip=$first_ip
|
||||
else
|
||||
# If selected hostname resolves on first IP,
|
||||
# use first IP for local hostname in /etc/hosts.
|
||||
# Otherwise use loopback IP.
|
||||
name_ip=$(get_dns_name "${name}")
|
||||
if [ "x${first_ip}" = "x${name_ip}" ]; then
|
||||
host_ip=$first_ip
|
||||
elif [ -f /etc/debian_version ]; then
|
||||
host_ip='127.0.1.1'
|
||||
else
|
||||
host_ip='127.0.0.1'
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${host_ip}" ]; then
|
||||
update_hosts "${host_ip}" "${name}" "${hostname}"
|
||||
fi
|
||||
fi
|
Loading…
Reference in new issue