From c7a56139e2fa100aebf368d6c46810d034fdca0f Mon Sep 17 00:00:00 2001 From: Albert Hopkins Date: Mon, 9 Jan 2012 21:21:06 +0000 Subject: [PATCH] Added "Airport" virtual appliance: see https://bitbucket.org/marduk/airport --- Makefile | 8 ++ airport/Makefile | 45 ++++++++++ airport/airport.service | 7 ++ airport/airport.wsgi | 16 ++++ airport/critical | 37 +++++++++ airport/default_vhost.include | 80 ++++++++++++++++++ airport/firstboot.start | 13 +++ airport/issue | 15 ++++ airport/package.keywords | 0 airport/package.use | 7 ++ airport/settings.py | 152 ++++++++++++++++++++++++++++++++++ airport/world | 3 + fstab | 1 + rsync-excludes-critical | 4 + 14 files changed, 388 insertions(+) create mode 100644 airport/Makefile create mode 100644 airport/airport.service create mode 100644 airport/airport.wsgi create mode 100644 airport/critical create mode 100644 airport/default_vhost.include create mode 100755 airport/firstboot.start create mode 100644 airport/issue create mode 100644 airport/package.keywords create mode 100644 airport/package.use create mode 100644 airport/settings.py create mode 100644 airport/world diff --git a/Makefile b/Makefile index 09f0e78..8ee2309 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ M4C = $(M4) $(M4_DEFS) NBD_DEV = /dev/nbd0 USEPKG = --usepkg --binpkg-respect-use=y RSYNC_MIRROR = rsync://rsync.gtlib.gatech.edu/gentoo/ +EMERGE_RSYNC = NO KERNEL = gentoo-sources PACKAGE_FILES = $(wildcard $(APPLIANCE)/package.*) WORLD = $(APPLIANCE)/world @@ -111,6 +112,9 @@ sync_portage: portage: sync_portage stage3 tar xjf portage-latest.tar.bz2 -C $(CHROOT)/usr +ifeq ($(EMERGE_RSYNC),YES) + $(inroot) emerge --sync --quiet +endif ifdef PKGDIR mkdir -p $(CHROOT)/var/portage/packages mount -o bind "$(PKGDIR)" $(CHROOT)/var/portage/packages @@ -275,6 +279,9 @@ image: kernel software device-map grub.shell grub dev.tar.bz2 motd.sh mkdir -p gentoo mount -o bind $(CHROOT) gentoo rsync -ax $(COPY_ARGS) gentoo/ loop/ +ifeq ($(PRUNE_CRITICAL),YES) + rsync -ax gentoo/usr/include/python* loop/usr/include/ +endif ./motd.sh $(EXTERNAL_KERNEL) $(VIRTIO) $(DISK_SIZE) $(SWAP_SIZE) $(UDEV) $(DASH) $(ARCH) > loop/etc/motd ifneq ($(EXTERNAL_KERNEL),YES) loop/sbin/grub --device-map=device-map --no-floppy --batch < grub.shell @@ -290,6 +297,7 @@ endif umount loop sleep 3 rmdir loop + e2fsck -fyD $(NBD_DEV)p1 || true qemu-nbd -d $(NBD_DEV) touch image diff --git a/airport/Makefile b/airport/Makefile new file mode 100644 index 0000000..4aca658 --- /dev/null +++ b/airport/Makefile @@ -0,0 +1,45 @@ +APP_ROOT := /var/airport +HG_REPO := https://bitbucket.org/marduk/airport + +preinstall: + sed -i '/^APACHE2_/d' $(CHROOT)/etc/make.conf + echo 'APACHE2_MPMS="prefork"' >> $(CHROOT)/etc/make.conf + echo 'APACHE2_MODULES="auth_basic authz_host env include info"' >> $(CHROOT)/etc/make.conf + + +postinstall: airport.service settings.py airport.wsgi default_vhost.include firstboot.start issue + sed -i 's/^APACHE2_OPTS=.*/APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D WSGI"/' $(CHROOT)/etc/conf.d/apache2 + $(inroot) rc-update add apache2 default + sed -i 's/^PG_INITDB_OPTS.*/PG_INITDB_OPTS="--locale=en_US.UTF-8"/' $(CHROOT)/etc/conf.d/postgresql-9.1 + $(inroot) eselect postgresql set 9.1 + rm -rf $(CHROOT)/var/lib/postgresql/9.1 + #[ -d $(CHROOT)/var/lib/postgresql/9.1/data ] || yes | $(inroot) $(EMERGE) --config postgresql-server:9.1 + yes | $(inroot) $(EMERGE) --config postgresql-server:9.1 + $(inroot) rc-update add postgresql-9.1 default + $(inroot) chsh -s /bin/sh postgres + $(inroot) $(EMERGE) -1n $(USEPKG) dev-python/virtualenv + rm -rf $(CHROOT)/$(APP_ROOT) + hg clone $(HG_REPO) $(CHROOT)/$(APP_ROOT) + echo 'VERSION="'`date +1.%y%m%d.%H%m`'"' > $(CHROOT)/$(APP_ROOT)/djangoproject/airport/__init__.py + chroot $(CHROOT) virtualenv --no-site-packages $(APP_ROOT) + $(inroot) bash -c ". $(APP_ROOT)/bin/activate ; pip install -r $(APP_ROOT)/requirements.txt" + $(inroot) bash -c ". $(APP_ROOT)/bin/activate ; pip install psycopg2" + mkdir -p $(CHROOT)/$(APP_ROOT)/etc + touch $(CHROOT)/$(APP_ROOT)/etc/__init__.py + cp settings.py $(CHROOT)/$(APP_ROOT)/etc + cp default_vhost.include $(CHROOT)/etc/apache2/vhosts.d + cp airport.wsgi $(CHROOT)/var/www/localhost + $(inroot) id -u airport >/dev/null || $(inroot) useradd -d $(APP_ROOT) -M -s /bin/false -U -G postgres airport + $(inroot) gpasswd -a apache postgres + cp firstboot.start $(CHROOT)/etc/local.d + cp issue $(CHROOT)/etc/issue +ifeq ($(AVAHI),YES) + $(inroot) $(EMERGE) -n $(USEPKG) net-dns/avahi + $(inroot) rm -f /etc/avahi/services/* + cp airport.service $(CHROOT)/etc/avahi/services + $(inroot) ln -sf /etc/init.d/avahi-daemon $(rcdefault)/avahi-daemon +endif + + +clean: + diff --git a/airport/airport.service b/airport/airport.service new file mode 100644 index 0000000..5c8a5ee --- /dev/null +++ b/airport/airport.service @@ -0,0 +1,7 @@ + + Airport + + _http._tcp + 80 + + diff --git a/airport/airport.wsgi b/airport/airport.wsgi new file mode 100644 index 0000000..8338228 --- /dev/null +++ b/airport/airport.wsgi @@ -0,0 +1,16 @@ +import os +import sys +sys.stdout = sys.stderr + +import site +site.addsitedir('/var/airport/lib/python2.7/site-packages') + +sys.path.append('/var/airport') +sys.path.append('/var/airport/djangoproject') +os.environ['DJANGO_SETTINGS_MODULE'] = 'etc.settings' +os.environ['VIRTUAL_ENV'] = '/var/airport/' + +import django.core.handlers.wsgi +application = django.core.handlers.wsgi.WSGIHandler() + +# vim: filetype=python diff --git a/airport/critical b/airport/critical new file mode 100644 index 0000000..aaed4f2 --- /dev/null +++ b/airport/critical @@ -0,0 +1,37 @@ +app-editors/nano +net-misc/openssh +net-misc/rsync +net-misc/wget +sys-kernel/gentoo-sources +sys-kernel/linux-headers +sys-devel/gcc +sys-devel/automake +sys-devel/bison +sys-devel/make +sys-devel/flex +sys-devel/automake-wrapper +sys-devel/autoconf-wrapper +sys-devel/autoconf +sys-devel/m4 +sys-devel/gcc-config +sys-devel/libtool +sys-devel/binutils +sys-devel/binutils-config +sys-devel/patch +sys-devel/gnuconfig +app-admin/python-updater +app-admin/perl-cleaner +sys-apps/man-pages +sys-apps/man +sys-apps/file +sys-apps/less +sys-apps/texinfo +sys-apps/busybox +sys-apps/debianutils +sys-apps/man-pages-posix +sys-apps/sandbox +sys-apps/which +dev-lang/perl +sys-devel/libperl +sys-apps/portage +dev-lang/python diff --git a/airport/default_vhost.include b/airport/default_vhost.include new file mode 100644 index 0000000..8b85da6 --- /dev/null +++ b/airport/default_vhost.include @@ -0,0 +1,80 @@ +# ServerAdmin: Your address, where problems with the server should be +# e-mailed. This address appears on some server-generated pages, such +# as error documents. e.g. admin@your-domain.com +ServerAdmin root@localhost + +# DocumentRoot: The directory out of which you will serve your +# documents. By default, all requests are taken from this directory, but +# symbolic links and aliases may be used to point to other locations. +# +# If you change this to something that isn't under /var/www then suexec +# will no longer work. +DocumentRoot "/var/www/localhost/htdocs" + +# This should be changed to whatever you set DocumentRoot to. + + # Possible values for the Options directive are "None", "All", + # or any combination of: + # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews + # + # Note that "MultiViews" must be named *explicitly* --- "Options All" + # doesn't give it to you. + # + # The Options directive is both complicated and important. Please see + # http://httpd.apache.org/docs/2.2/mod/core.html#options + # for more information. + Options Indexes FollowSymLinks + + # AllowOverride controls what directives may be placed in .htaccess files. + # It can be "All", "None", or any combination of the keywords: + # Options FileInfo AuthConfig Limit + AllowOverride All + + # Controls who can get stuff from this server. + Order allow,deny + Allow from all + + + + # Redirect: Allows you to tell clients about documents that used to + # exist in your server's namespace, but do not anymore. The client + # will make a new request for the document at its new location. + # Example: + # Redirect permanent /foo http://www.example.com/bar + + # Alias: Maps web paths into filesystem paths and is used to + # access content that does not live under the DocumentRoot. + # Example: + # Alias /webpath /full/filesystem/path + # + # If you include a trailing / on /webpath then the server will + # require it to be present in the URL. You will also likely + # need to provide a section to allow access to + # the filesystem path. + + # ScriptAlias: This controls which directories contain server scripts. + # ScriptAliases are essentially the same as Aliases, except that + # documents in the target directory are treated as applications and + # run by the server when requested rather than as documents sent to the + # client. The same rules about trailing "/" apply to ScriptAlias + # directives as to Alias. + ScriptAlias /cgi-bin/ "/var/www/localhost/cgi-bin/" + + +# "/var/www/localhost/cgi-bin" should be changed to whatever your ScriptAliased +# CGI directory exists, if you have that configured. + + AllowOverride None + Options None + Order allow,deny + Allow from all + + +WSGIDaemonProcess airport display-name=airport user=airport processes=2 threads=15 +WSGISCriptAlias / /var/www/localhost/airport.wsgi + + AllowOverride None + Order Deny,Allow + + +# vim: ts=4 filetype=apache diff --git a/airport/firstboot.start b/airport/firstboot.start new file mode 100755 index 0000000..abea7ba --- /dev/null +++ b/airport/firstboot.start @@ -0,0 +1,13 @@ +#!/bin/sh -e + +echo Creating Airport database... +createuser -U postgres -D -l -R -S airport +createdb -U postgres -E utf8 -O airport airport + +PYTHONPATH=/var/airport ; export PYTHONPATH +cd /var/airport +. bin/activate +cd djangoproject +./manage.py syncdb --settings=etc.settings --noinput + +mv /etc/local.d/firstboot.start /etc/local.d/firstboot.start.disabled diff --git a/airport/issue b/airport/issue new file mode 100644 index 0000000..74868ae --- /dev/null +++ b/airport/issue @@ -0,0 +1,15 @@ + + | + | + | + _|_ + /___\\ + /_____\\ + /oo oo\\ + \\___________________________\\ /___________________________/ + `-----------|------|--------\\_____/--------|------|-----------' + ( ) ( ) O|OOo|oOO|O ( ) ( ) + ------------------------------------------------------------------------------ + Airport Console + ------------------------------------------------------------------------------ + diff --git a/airport/package.keywords b/airport/package.keywords new file mode 100644 index 0000000..e69de29 diff --git a/airport/package.use b/airport/package.use new file mode 100644 index 0000000..8324875 --- /dev/null +++ b/airport/package.use @@ -0,0 +1,7 @@ +app-editors/nano ncurses +dev-lang/python ssl threads xml +net-misc/dhcp client +sys-devel/gcc cxx +sys-kernel/gentoo-sources symlink +sys-libs/ncurses minimal +sys-apps/portage python2 diff --git a/airport/settings.py b/airport/settings.py new file mode 100644 index 0000000..2b03cdf --- /dev/null +++ b/airport/settings.py @@ -0,0 +1,152 @@ +# Django settings for djangoproject project. +import os + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +ADMINS = ( + ('Your Name', 'your@email.com'), +) + +MANAGERS = ADMINS + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'airport', + 'USER': 'airport', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '', + } +} + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# On Unix systems, a value of None will cause Django to use the same +# timezone as the operating system. +# If running in a Windows environment this must be set to the same as your +# system time zone. +TIME_ZONE = 'America/New_York' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = False + +# If you set this to False, Django will not format dates, numbers and +# calendars according to the current locale +USE_L10N = True + +# Absolute filesystem path to the directory that will hold user-uploaded files. +# Example: "/home/media/media.lawrence.com/media/" +MEDIA_ROOT = '' + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash. +# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" +MEDIA_URL = '' + +# Absolute path to the directory static files should be collected to. +# Don't put anything in this directory yourself; store your static files +# in apps' "static/" subdirectories and in STATICFILES_DIRS. +# Example: "/home/media/media.lawrence.com/static/" +STATIC_ROOT = '' + +# URL prefix for static files. +# Example: "http://media.lawrence.com/static/" +STATIC_URL = '/static/' + +# URL prefix for admin static files -- CSS, JavaScript and images. +# Make sure to use a trailing slash. +# Examples: "http://foo.com/static/admin/", "/static/admin/". +ADMIN_MEDIA_PREFIX = '/static/admin/' + +# Additional locations of static files +STATICFILES_DIRS = ( + # Put strings here, like "/home/html/static" or "C:/www/django/static". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +# List of finder classes that know how to find static files in +# various locations. +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', +# 'django.contrib.staticfiles.finders.DefaultStorageFinder', +) + +# Make this unique, and don't share it with anybody. +SECRET_KEY = '5vv-a3_^4a5uk=88m-jow=62*nvo0)0nn)wh)^ea^l=-+o9zuv' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', +# 'django.template.loaders.eggs.Loader', +) + +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + 'airport.context_processors.externals', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', +) + +ROOT_URLCONF = 'djangoproject.urls' + +TEMPLATE_DIRS = ( + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + #'django.contrib.sites', + 'django.contrib.messages', + #'django.contrib.staticfiles', + 'django.contrib.humanize', + 'airport' +) + +# A sample logging configuration. The only tangible logging +# performed by this configuration is to send an email to +# the site admins on every HTTP 500 error. +# See http://docs.djangoproject.com/en/dev/topics/logging for +# more details on how to customize your logging configuration. +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'handlers': { + 'mail_admins': { + 'level': 'ERROR', + 'class': 'django.utils.log.AdminEmailHandler' + } + }, + 'loggers': { + 'django.request': { + 'handlers': ['mail_admins'], + 'level': 'ERROR', + 'propagate': True, + }, + } +} + +AUTH_PROFILE_MODULE = 'airport.UserProfile' diff --git a/airport/world b/airport/world new file mode 100644 index 0000000..136080e --- /dev/null +++ b/airport/world @@ -0,0 +1,3 @@ +dev-db/postgresql-server:9.1 +net-misc/dhcp +www-apache/mod_wsgi diff --git a/fstab b/fstab index 4d3632d..0091a14 100644 --- a/fstab +++ b/fstab @@ -1,3 +1,4 @@ # /dev/sda1 / ext4 noatime 1 1 +none /sys sysfs defaults 0 0 /.swap none swap sw 0 0 diff --git a/rsync-excludes-critical b/rsync-excludes-critical index 9752dec..bca3562 100644 --- a/rsync-excludes-critical +++ b/rsync-excludes-critical @@ -1,6 +1,10 @@ +usr/include/* usr/lib/python*/test +usr/lib64/python*/test usr/share/gtk-doc var/db/pkg usr/lib/perl* +usr/lib64/perl* +usr/share/doc/* *.pyc *.pyo