Created basic playbook skeleton and setup scripts
This commit is contained in:
126
install.sh
Normal file
126
install.sh
Normal file
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env bash
|
||||
setup_encryption() {
|
||||
|
||||
sed -i 's/ENCRYPT/true/' group_vars/client.yml
|
||||
pass_reprompt="1"
|
||||
while [ pass_reprompt == 1 ]; do
|
||||
printf 'Please enter a passphrase to use for your backup\n Password: '
|
||||
read -s password1
|
||||
printf '\nVerify Password: '
|
||||
read -s password2
|
||||
if [ "$password1" -eq "$password2" ]; then
|
||||
pass_reprompt=0
|
||||
else
|
||||
printf 'Passwords do not match. Please try again\n'
|
||||
fi
|
||||
done
|
||||
|
||||
SECRET="---\\nbackup:\\n passphrase: '$password'\\n"
|
||||
printf '%s' "$SECRET" | tee group_vars/secret.yml
|
||||
|
||||
}
|
||||
|
||||
setup_ssh() {
|
||||
printf 'What is the IP or hostname of your remote backup?\n'
|
||||
cont=0
|
||||
while [ $cont != 1 ]; do
|
||||
read -p "IP/hostname: " address
|
||||
printf '\nIs %s correct? ' "$address"
|
||||
read -p "[y/N]: " ans
|
||||
case "$ans" in
|
||||
[yY].*) cont=1
|
||||
;;
|
||||
*) cont=0
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
cont=0
|
||||
printf 'What is the backup location?\n'
|
||||
while [ "$cont" != 1 ]; do
|
||||
read -p "Absolute path: " path
|
||||
printf '\nIs %s correct? ' "$path"
|
||||
read -p "[y/N]: " ans
|
||||
case "$ans" in
|
||||
[yY].*) cont=1
|
||||
;;
|
||||
*) cont=0
|
||||
esac
|
||||
done
|
||||
|
||||
printf 's/REPO/ssh://backup@%s:%s/\n' "$address" "$path" > /tmp/backupssh.sed
|
||||
|
||||
sed -i -s /tmp/backupssh.sed group_vars/client.yml
|
||||
rm /tmp/backupssh.sed
|
||||
|
||||
}
|
||||
|
||||
|
||||
setup_remote() {
|
||||
case "$1" in
|
||||
"ssh") setup_ssh
|
||||
;;
|
||||
"local") setup_local
|
||||
;;
|
||||
*)
|
||||
printf 'Error in setup_remote()\n'
|
||||
printf 'Case %s not understood\n' "$1"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
setup_environment() {
|
||||
printf 'Setting up environment...\n'
|
||||
printf 'What is your backup location?\n'
|
||||
printf '0: cancel\n'
|
||||
printf '1: ssh\n'
|
||||
printf '2: local\n'
|
||||
read -p "(0-2)" ans
|
||||
case "$ans" in
|
||||
"0") printf 'Cancelling...\n' && exit
|
||||
;;
|
||||
"1") setup_remote "ssh"
|
||||
;;
|
||||
"2") setup_remote "local"
|
||||
;;
|
||||
*) printf 'Answer not understood. Please rerun this script' && exit
|
||||
;;
|
||||
esac
|
||||
|
||||
read -p "Would you like to set up encryption? [y/N]" ans
|
||||
case "$ans" in
|
||||
[yY].*) setup_encryption
|
||||
;;
|
||||
*) sed -i 's/ENCRYPT/false/' group_vars/client.yml
|
||||
;;
|
||||
esac
|
||||
|
||||
printf 'Would you like to set up a "reserve" file?\n'
|
||||
printf 'This file will be an empty file 50GB in size\n'
|
||||
printf 'that you can delete to free up space should you run out.\n\n'
|
||||
printf 'This is highly recommended\n'
|
||||
|
||||
read -p "Setup Reserved Space [Y/n]: " reserved
|
||||
case "$reserved" in
|
||||
[nN].*) sed -i 's/ALLOCATE/true/' group_vars/client.yml
|
||||
;;
|
||||
*) sed -i 's/ALLOCATE/false/' group_vars/client.yml
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
|
||||
printf 'The setup will now install required packages\n'
|
||||
printf 'You will be prompted for your sudo password\n'
|
||||
|
||||
sudo dnf install -y ansible ansible-playbook
|
||||
|
||||
read -p "Would you like to set up the environment files?: [Y/n]: " ans
|
||||
|
||||
case $ans in
|
||||
[yY].*) setup_environment
|
||||
;;
|
||||
*) printf 'No environment set up. You will need to do this manually\n'
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user