forked from AzuraCast/AzuraCast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·70 lines (55 loc) · 2.01 KB
/
update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/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
;;
esac; shift; done
if [[ "$1" == '--' ]]; then shift; fi
PKG_OK=$(dpkg-query -W --showformat='${Status}\n' ansible|grep "install ok installed")
echo "Checking for Ansible: $PKG_OK"
if [[ "" == "$PKG_OK" ]]; then
sudo apt-get update
sudo apt-get install -q -y software-properties-common
sudo apt-add-repository ppa:ansible/ansible
sudo apt-get update
sudo apt-get install -q -y ansible python-mysqldb
else
sudo apt-get update
sudo apt-get install -q -y ansible python-mysqldb
fi
APP_ENV="${APP_ENV:-production}"
UPDATE_REVISION="${UPDATE_REVISION:-47}"
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
else
echo "You are running a release build. Any code updates should be applied manually."
fi
fi
ansible-playbook util/ansible/update.yml --inventory=util/ansible/hosts --extra-vars "app_env=$APP_ENV update_revision=$UPDATE_REVISION"