-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse the command line arguments and forward them to respective subroutines. Just the `./setup` side of things have been implemented here. Work done for GH-12
- Loading branch information
Showing
7 changed files
with
197 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#!/bin/sh | ||
|
||
vc_printerr () { | ||
printf "$@" 1>&2 | ||
} | ||
|
||
vc_usage () { | ||
vc_printerr "usage: $0" | ||
vc_printerr " action\n" | ||
} | ||
|
||
vc_get_file_dir () { | ||
local src | ||
|
||
src="$1" | ||
while [ -h "${src}" ]; do src="$(readlink "${src}")"; done | ||
src=$(cd -P $(dirname "${src}") && pwd) | ||
|
||
printf "${src}" | ||
} | ||
|
||
vc_check_file_readable () { | ||
if [ ! -r "$1" ]; then | ||
vc_printerr "$0: Cannot read file: \"$1\".\n\n" | ||
vc_usage | ||
exit 2 | ||
fi | ||
printf "$1" | ||
} | ||
|
||
vc_parse_options () { | ||
. ./vars.sh | ||
} | ||
|
||
vc_parse_args () { | ||
local arg | ||
local args | ||
|
||
args=$(getopt -n "$0" "$@") | ||
if [ $? -ne 0 ]; then | ||
vc_usage | ||
exit 1 | ||
fi | ||
|
||
set -- ${args} | ||
for arg in "$@"; do | ||
case "${arg}" in | ||
--) | ||
shift | ||
break | ||
;; | ||
esac | ||
done | ||
|
||
case "$1" in | ||
initialize|cleanup) | ||
ACTION="$1"; shift | ||
;; | ||
*) | ||
vc_printerr "$0: Unrecognised action: \"$1\".\n\n" | ||
vc_usage | ||
exit 3 | ||
;; | ||
esac | ||
} | ||
|
||
|
||
ROOT_DIR=$(vc_get_file_dir $0) | ||
|
||
. "${ROOT_DIR}/src/initialize.sh" | ||
. "${ROOT_DIR}/src/cleanup.sh" | ||
|
||
vc_parse_options | ||
vc_parse_args "$@" | ||
|
||
case "${ACTION}" in | ||
initialize) | ||
vc_action_initialize | ||
;; | ||
cleanup) | ||
vc_action_cleanup | ||
;; | ||
esac |
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,17 @@ | ||
vc_action_cleanup () { | ||
VBoxManage modifyvm ${NAME} \ | ||
--boot1 disk --boot2 none --boot3 none --boot4 none \ | ||
|
||
VBoxManage storagectl ${NAME} \ | ||
--name SATA --remove | ||
|
||
VBoxManage storagectl ${NAME} \ | ||
--name SATA --add sata --portcount 1 --bootable on | ||
|
||
VBoxManage storageattach ${NAME} \ | ||
--storagectl SATA --port 0 --type hdd \ | ||
--medium "${HDD}" | ||
VBoxManage storageattach ${NAME} \ | ||
--storagectl SATA --port 1 --type hdd \ | ||
--medium "${HDD_SWAP}" | ||
} |
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,93 @@ | ||
vc_initialize_ruby_exec () { | ||
local embedded_dir | ||
local ruby_exec | ||
local src | ||
|
||
src=$(which vagrant) | ||
if [ $? -eq 0 ]; then | ||
embedded_dir="$(vc_get_file_dir "${src}")/../embedded" | ||
|
||
unset RUBYOPT | ||
ruby_exec="${embedded_dir}/bin/ruby" | ||
else | ||
ruby_exec=$(which ruby) | ||
if [ ! $? -eq 0 ]; then | ||
vc_printerr "$0: Cannot find Ruby (needed to serve kickstart file)" | ||
exit 4 | ||
fi | ||
fi | ||
|
||
printf "${ruby_exec}" | ||
} | ||
|
||
vc_initialize_setup_box () { | ||
VBoxManage createvm --name ${NAME} --ostype ${TYPE} --register | ||
|
||
VBoxManage modifyvm ${NAME} \ | ||
--vram 12 \ | ||
--accelerate3d off \ | ||
--memory 613 \ | ||
--usb off \ | ||
--audio none \ | ||
--boot1 disk --boot2 dvd --boot3 none --boot4 none \ | ||
--nictype1 virtio --nic1 nat --natnet1 "${NATNET}" \ | ||
--nictype2 virtio \ | ||
--nictype3 virtio \ | ||
--nictype4 virtio \ | ||
--acpi on --ioapic off \ | ||
--chipset piix3 \ | ||
--rtcuseutc on \ | ||
--hpet on \ | ||
--bioslogofadein off \ | ||
--bioslogofadeout off \ | ||
--bioslogodisplaytime 0 \ | ||
--biosbootmenu disabled | ||
|
||
VBoxManage createhd --filename "${HDD}" --size 8192 | ||
VBoxManage createhd --filename "${HDD_SWAP}" --size 1226 | ||
|
||
VBoxManage storagectl ${NAME} \ | ||
--name SATA --add sata --portcount 2 --bootable on | ||
|
||
VBoxManage storageattach ${NAME} \ | ||
--storagectl SATA --port 0 --type hdd --medium "${HDD}" | ||
VBoxManage storageattach ${NAME} \ | ||
--storagectl SATA --port 1 --type hdd --medium "${HDD_SWAP}" | ||
VBoxManage storageattach ${NAME} \ | ||
--storagectl SATA --port 2 --type dvddrive --medium "${INSTALLER}" | ||
VBoxManage storageattach ${NAME} \ | ||
--storagectl SATA --port 3 --type dvddrive --medium "${GUESTADDITIONS}" | ||
|
||
VBoxManage startvm ${NAME} --type gui | ||
} | ||
|
||
vc_initialize_start_httpd () { | ||
# This only really caters for the common case. If you have | ||
# problems, please discover your host's IP address and adjust | ||
# accordingly. | ||
IP=${NATNET%.*/*} | ||
|
||
printf "At the boot prompt, hit <TAB> and then type:\n\n" | ||
printf " ks=http://${IP}.3:" | ||
|
||
ruby=$(vc_initialize_ruby_exec) | ||
"${ruby}" "${ROOT_DIR}/src/httpd.rb" "${ROOT_DIR}/ks.cfg" | ||
} | ||
|
||
vc_initialize_cleanup_msg () { | ||
printf "\n\n" | ||
printf "The box has accepted the kickstart file. It will now go through\n" | ||
printf "a lengthy install. When it is finished it will shutdown and you\n" | ||
printf "can run:\n\n" | ||
printf " ./box cleanup && vagrant package --base ${NAME} --output boxes/${NAME}-`date +%Y%m%d`.box\n\n" | ||
printf "to create a Vagrant box.\n" | ||
} | ||
|
||
vc_action_initialize () { | ||
local ruby | ||
|
||
vc_initialize_setup_box | ||
vc_initialize_start_httpd | ||
|
||
vc_initialize_cleanup_msg | ||
} |