Add ability to spawn basic configurations for testing.
This commit is contained in:
58
setup.sh
58
setup.sh
@@ -15,7 +15,7 @@ BRANCH="main"
|
|||||||
function usage {
|
function usage {
|
||||||
cat <<- EOF
|
cat <<- EOF
|
||||||
|
|
||||||
$PROG [-l] [-b branch_name] [-h]
|
$PROG [-l] [-b branch_name] [-g] [-w] [-s] [-h]
|
||||||
Program to initialize synchronization with Hyperling's Ansible configuration.
|
Program to initialize synchronization with Hyperling's Ansible configuration.
|
||||||
$URL
|
$URL
|
||||||
|
|
||||||
@@ -24,6 +24,9 @@ function usage {
|
|||||||
This is helpful for development or just saving bandwidth.
|
This is helpful for development or just saving bandwidth.
|
||||||
It also provides prettier colors than the plaintext from ansible-pull. ;)
|
It also provides prettier colors than the plaintext from ansible-pull. ;)
|
||||||
-b branch_name : Download and run a specific branch. Default is $BRANCH.
|
-b branch_name : Download and run a specific branch. Default is $BRANCH.
|
||||||
|
-g : Enable the General config with test contents.
|
||||||
|
-w : Enable the Workstation config with test contents.
|
||||||
|
-s : Enable the Server config with test contents.
|
||||||
-h : Display this help text
|
-h : Display this help text
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
@@ -32,10 +35,13 @@ function usage {
|
|||||||
|
|
||||||
## Parameter Parsing ##
|
## Parameter Parsing ##
|
||||||
|
|
||||||
while getopts ":lb:h" arg; do
|
while getopts ":lb:gwsh" arg; do
|
||||||
case $arg in
|
case $arg in
|
||||||
l) local="Y" && echo "Running $LOCAL as the playbook." ;;
|
l) local="Y" && echo "Running $LOCAL as the playbook." ;;
|
||||||
b) branch="$OPTARG" && echo "Using branch $branch instead of $BRANCH." ;;
|
b) branch="$OPTARG" && echo "Using branch $branch instead of $BRANCH." ;;
|
||||||
|
l) create_general="Y" && echo "Creating basic '$general_config'." ;;
|
||||||
|
l) create_workstation="Y" && echo "Creating basic '$workstation_config'." ;;
|
||||||
|
l) create_server="Y" && echo "Creating basic '$server_config'." ;;
|
||||||
h) usage ;;
|
h) usage ;;
|
||||||
*) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;;
|
*) echo "ERROR: Parameter $OPTARG was not recognized." && usage 1 ;;
|
||||||
esac
|
esac
|
||||||
@@ -52,6 +58,19 @@ if [[ -z "$local" && "$branch" == "" ]]; then
|
|||||||
branch="$BRANCH"
|
branch="$BRANCH"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -n "$create_general" && -f "$general_config" ]]; then
|
||||||
|
echo "WARNING: General configuration already exists, will not overwrite."
|
||||||
|
ls -lh "$general"
|
||||||
|
fi
|
||||||
|
if [[ -n "$create_workstation" && -f "$workstation_config" ]]; then
|
||||||
|
echo "WARNING: Workstation configuration already exists, will not overwrite."
|
||||||
|
ls -lh "$workstation_config"
|
||||||
|
fi
|
||||||
|
if [[ -n "$create_server" && -f "$server_config" ]]; then
|
||||||
|
echo "WARNING: Server configuration already exists, will not overwrite."
|
||||||
|
ls -lh "$server_config"
|
||||||
|
fi
|
||||||
|
|
||||||
## Main ##
|
## Main ##
|
||||||
|
|
||||||
os="$(cat /etc/os-release)"
|
os="$(cat /etc/os-release)"
|
||||||
@@ -105,6 +124,41 @@ echo "Installed!"
|
|||||||
#ansible-galaxy collection install community.general
|
#ansible-galaxy collection install community.general
|
||||||
#echo "Added!"
|
#echo "Added!"
|
||||||
|
|
||||||
|
# Create basic layouts if configs do not exist and are requested.
|
||||||
|
if [[ -n "$create_general" && ! -f "$general_config" ]]; then
|
||||||
|
function print_general_contents {
|
||||||
|
cat <<- EOF
|
||||||
|
enable=true
|
||||||
|
user=test
|
||||||
|
user_desc=Test
|
||||||
|
branch=$branch
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
print_general_contents > "$general_config"
|
||||||
|
fi
|
||||||
|
if [[ -n "$create_workstation" && ! -f "$workstation_config" ]]; then
|
||||||
|
function print_workstation_contents {
|
||||||
|
cat <<- EOF
|
||||||
|
enable=true
|
||||||
|
user=test
|
||||||
|
user_desc=Test
|
||||||
|
branch=$branch
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
print_workstation_contents > "$workstation_config"
|
||||||
|
fi
|
||||||
|
if [[ -n "$create_server" && ! -f "$server_config" ]]; then
|
||||||
|
function print_server_contents {
|
||||||
|
cat <<- EOF
|
||||||
|
enable=true
|
||||||
|
user=test
|
||||||
|
user_desc=Test
|
||||||
|
branch=$branch
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
print_server_contents > "$server_config"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Provisioning Ansible..."
|
echo "Provisioning Ansible..."
|
||||||
if [[ $local == "Y" ]]; then
|
if [[ $local == "Y" ]]; then
|
||||||
sudo ansible-playbook $LOCAL
|
sudo ansible-playbook $LOCAL
|
||||||
|
|||||||
Reference in New Issue
Block a user