Skip to content

Commit

Permalink
Various tweaks to Ansible installs.
Browse files Browse the repository at this point in the history
  • Loading branch information
BusterNeece committed Jun 9, 2020
1 parent abba7af commit ee88b48
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 86 deletions.
57 changes: 8 additions & 49 deletions install.sh
@@ -1,65 +1,24 @@
#!/usr/bin/env bash

# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.
ask() {
# https://djm.me/ask
local prompt default reply

while true; do

if [[ "${2:-}" = "Y" ]]; then
prompt="Y/n"
default=Y
elif [[ "${2:-}" = "N" ]]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi

# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "

read reply

# Default?
if [[ -z "$reply" ]]; then
reply=${default}
fi

# Check if the reply is valid
case "$reply" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac

done
}

while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
case $1 in
--dev)
APP_ENV="development"
shift
;;
esac; shift; done
esac
shift
done
if [[ "$1" == '--' ]]; then shift; fi

if ask "Use Docker installation method? (Recommended)" Y; then
bash docker.sh install
exit 0
fi

. /etc/lsb-release

if [[ $DISTRIB_ID != "Ubuntu" ]]; then
echo "Ansible installation is only supported on Ubuntu distributions."
exit 0
fi

PKG_OK=$(dpkg-query -W --showformat='${Status}\n' ansible|grep "install ok installed")
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' ansible | grep "install ok installed")
echo "Checking for Ansible: $PKG_OK"

if [[ "" == "$PKG_OK" ]]; then
Expand All @@ -71,12 +30,12 @@ if [[ "" == "$PKG_OK" ]]; then
else
sudo add-apt-repository -y ppa:ansible/ansible
sudo apt-get update

sudo apt-get install -q -y python2.7 python-pip python-mysqldb ansible
fi
fi

APP_ENV="${APP_ENV:-production}"

echo "Installing AzuraCast (Environment: $APP_ENV)"
ansible-playbook util/ansible/deploy.yml --inventory=util/ansible/hosts --extra-vars "app_env=$APP_ENV"
ansible-playbook util/ansible/deploy.yml --inventory=util/ansible/hosts --extra-vars "app_env=$APP_ENV"
40 changes: 6 additions & 34 deletions update.sh
@@ -1,17 +1,11 @@
#!/usr/bin/env bash

release_update=0

while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
case $1 in
--dev)
APP_ENV="development"
;;

-r | --release)
release_update=1
;;

--full)
UPDATE_REVISION=0
;;
Expand All @@ -20,6 +14,9 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
done
if [[ "$1" == '--' ]]; then shift; fi

APP_ENV="${APP_ENV:-production}"
UPDATE_REVISION="${UPDATE_REVISION:-55}"

PKG_OK=$(dpkg-query -W --showformat='${Status}\n' ansible | grep "install ok installed")
echo "Checking for Ansible: $PKG_OK"

Expand All @@ -34,39 +31,14 @@ else
sudo apt-get install -q -y ansible python-mysqldb
fi

APP_ENV="${APP_ENV:-production}"
UPDATE_REVISION="${UPDATE_REVISION:-55}"

echo "Updating AzuraCast (Environment: $APP_ENV, Update revision: $UPDATE_REVISION)"

if [[ ${APP_ENV} == "production" ]]; then
if [[ -d ".git" ]]; then
if [[ $release_update == 1 ]]; then
current_hash=$(git rev-parse HEAD)
current_tag=$(git describe --abbrev=0 --tags)

git fetch --tags
latest_tag=$(git describe --abbrev=0 --tags)

git reset --hard

if [[ $current_tag == $latest_tag ]]; then
echo "You are already on the latest version (${current_tag})!"
else
echo "Updating codebase from ${current_tag} to ${latest_tag}..."

git pull
git reset --hard $latest_tag
fi
else
echo "Updating to the latest rolling-release version..."
echo "Tip: use the '--release' flag to update to tagged releases only."

git reset --hard
git pull
fi
git reset --hard
git pull
else
echo "You are running a release build. Any code updates should be applied manually."
echo "You are running a downloaded release build. Any code updates should be applied manually."
fi
fi

Expand Down
6 changes: 4 additions & 2 deletions util/ansible/roles/azuracast-build/tasks/main.yml
Expand Up @@ -27,6 +27,8 @@
chdir: "{{ www_base }}/frontend"

- name: Set permissions of generated frontend content
file: path="{{ item }}" state=directory recurse=yes owner=azuracast group=www-data
shell: "{{ item }}"
with_items:
- "{{ www_base }}/web/static/dist"
- "chown -R azuracast:www-data {{ www_base }}"
- "find {{ www_base }} -type d -exec chmod 755 {} \;"
- "find {{ www_base }} -type f -exec chmod 644 {} \;"
2 changes: 1 addition & 1 deletion util/ansible/roles/dbip/tasks/main.yml
Expand Up @@ -5,7 +5,7 @@
dest: "{{ app_base }}/dbip/dbip-city-lite.mmdb.gz"

- name: Extract DBIP Database
shell: "gunzip dbip-city-lite.mmdb.gz"
shell: "gunzip -f dbip-city-lite.mmdb.gz"
args:
chdir: "{{ app_base }}/dbip"

Expand Down

0 comments on commit ee88b48

Please sign in to comment.