-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Clean up additional YUM repositories, typically used for security patches. | ||
# The format of ADDITIONAL_YUM_REPOS is: "repo=patches-repo,name=Install patches,baseurl=http://amazonlinux.$awsregion.$awsdomain/xxxx,priority=10" | ||
# Multiple yum repos can be specified, separated by ';' | ||
|
||
if [ -z "${ADDITIONAL_YUM_REPOS}" ]; then | ||
echo "no additional yum repo, skipping" | ||
exit 0 | ||
fi | ||
|
||
|
||
AWK_CMD=' | ||
BEGIN {RS=";";FS=","} | ||
{ | ||
delete vars; | ||
for(i = 1; i <= NF; ++i) { | ||
n = index($i, "="); | ||
if(n) { | ||
vars[substr($i, 1, n-1)] = substr($i, n + 1) | ||
} | ||
} | ||
Repo = "/etc/yum.repos.d/"vars["repo"]".repo" | ||
} | ||
{cmd="rm -f " Repo; system(cmd)} | ||
' | ||
sudo awk "$AWK_CMD" <<< "${ADDITIONAL_YUM_REPOS}" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Install additional YUM repositories, typically used for security patches. | ||
# The format of ADDITIONAL_YUM_REPOS is: "repo=patches-repo,name=Install patches,baseurl=http://amazonlinux.$awsregion.$awsdomain/xxxx,priority=10" | ||
# which will create the file '/etc/yum.repos.d/patches-repo.repo' having the following content: | ||
# ``` | ||
# [patches-repo] | ||
# name=Install patches | ||
# baseurl=http://amazonlinux.$awsregion.$awsdomain/xxxx | ||
# priority=10 | ||
# ``` | ||
# Note that priority is optional, but the other parameters are required. Multiple yum repos can be specified, each one separated by ';' | ||
|
||
if [ -z "${ADDITIONAL_YUM_REPOS}" ]; then | ||
echo "no additional yum repo, skipping" | ||
exit 0 | ||
fi | ||
|
||
|
||
AWK_CMD=' | ||
BEGIN {RS=";";FS=","} | ||
{ | ||
delete vars; | ||
for(i = 1; i <= NF; ++i) { | ||
n = index($i, "="); | ||
if(n) { | ||
vars[substr($i, 1, n-1)] = substr($i, n + 1) | ||
} | ||
} | ||
Repo = "/etc/yum.repos.d/"vars["repo"]".repo" | ||
} | ||
{print "["vars["repo"]"]" > Repo} | ||
{print "name="vars["name"] > Repo} | ||
{print "baseurl="vars["baseurl"] > Repo} | ||
{if (length(vars["priority"]) != 0) print "priority="vars["priority"] > Repo} | ||
' | ||
sudo awk "$AWK_CMD" <<< "${ADDITIONAL_YUM_REPOS}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Do basic validation of the generated AMI | ||
|
||
# Validates that a file or blob doesn't exist | ||
# | ||
# Arguments: | ||
# a file name or blob | ||
# Returns: | ||
# 1 if a file exists, after printing an error | ||
validate_file_nonexists() { | ||
local file_blob=$1 | ||
for f in $file_blob; do | ||
if [ -e "$f" ]; then | ||
echo "$f shouldn't exists" | ||
exit 1 | ||
fi | ||
done | ||
} | ||
|
||
validate_file_nonexists '/etc/hostname' | ||
validate_file_nonexists '/etc/resolv.conf' | ||
validate_file_nonexists '/etc/ssh/ssh_host*' | ||
validate_file_nonexists '/home/ec2-user/.ssh/authorized_keys' | ||
validate_file_nonexists '/root/.ssh/authorized_keys' | ||
validate_file_nonexists '/var/lib/cloud/data' | ||
validate_file_nonexists '/var/lib/cloud/instance' | ||
validate_file_nonexists '/var/lib/cloud/instances' | ||
validate_file_nonexists '/var/lib/cloud/sem' | ||
validate_file_nonexists '/var/lib/dhclient/*' | ||
validate_file_nonexists '/var/lib/dhcp/dhclient.*' | ||
validate_file_nonexists '/var/lib/yum/history' | ||
validate_file_nonexists '/var/log/cloud-init-output.log' | ||
validate_file_nonexists '/var/log/cloud-init.log' | ||
validate_file_nonexists '/var/log/secure' | ||
validate_file_nonexists '/var/log/wtmp' |