forked from bketelsen/workstation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·127 lines (106 loc) · 2.9 KB
/
deploy.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/bash
# Software Dependencies
neededSoftware=(software-properties-common ansible dialog git)
# These application vars are set here to avoid a chicken/egg scenario
# Where is the DPKG command?
DPKG=$(which dpkg)
# Where is the APT command?
APT=$(which apt)
# Check if software is installed and install with APT if needed.
function checkInstalled() {
$DPKG -s "$1" 2>/dev/null >/dev/null || sudo $APT -y install "$1"
}
function getPanelId() {
ID=$(dconf dump /com/solus-project/budgie-panel/panels/ | grep { | cut -d '[' -f2 | cut -d ']' -f1)
echo "$ID"
}
# Update APT Repos of older than 12 hours
if [ -z "$(find /var/cache/apt/pkgcache.bin -mmin -720)" ]; then
sudo apt update
fi
# Install Software if needed
for sw in "${neededSoftware[@]}"; do
checkInstalled "$sw"
done
### SCRIPT VARS
# These application vars are set after software deps are met
# Where is the ansible-playbook command?
ANSIBLE=$(which ansible-playbook)
# Where is the ansible-pull command?
APULL=$(which ansible-pull)
# Where is the git command?
GIT=$(which git)
# Local working root folder
MYLOCBASE="$HOME/tmp"
# Local repo path
MYREPO="$MYLOCBASE/bashfulrobot-ansible"
# Remote repo path
MYREPORMT="https://github.com/bashfulrobot/bashfulrobot-ansible.git"
# Configure git
$GIT config user.name bashfulrobot
$GIT config user.email [email protected]
$GIT config user.editor code-insiders
# Ansible Deploy from local GIT repo
function deployLocal() {
if [ ! -f "$MYYAML" ]; then
# Get the repo if needed
mkdir -p $MYLOCBASE
cd $MYLOCBASE
$GIT clone $MYREPORMT
cd $MYREPO
git remote set-url origin [email protected]:bashfulrobot/bashfulrobot-ansible
else
cd $MYREPO
# Get the latest version if exists.
$GIT pull
fi
# Run ansible-pull no matter what (local dev iteration)
$ANSIBLE --extra-vars "PANEL_ID=$(getPanelId)" $MYYAML --connection=local
}
# Setup Ansible CFG
if [ ! -f $HOME/.ansible.cfg ]; then
touch $HOME/.ansible.cfg
echo '[defaults]' >$HOME/.ansible.cfg
echo 'remote_tmp = /tmp/$USER/ansible' >>$HOME/.ansible.cfg
fi
# Build Menu
HEIGHT=15
WIDTH=40
CHOICE_HEIGHT=4
BACKTITLE="Deploying ansible scripts"
TITLE="Ansible Deploy"
MENU="Choose one of the following options:"
OPTIONS=(1 "Local Repo Deploy All"
2 "Local Repo Deploy ZSH"
3 "Remote Repo Deploy All"
4 "Local Repo Test Script")
CHOICE=$(dialog --clear \
--backtitle "$BACKTITLE" \
--title "$TITLE" \
--menu "$MENU" \
$HEIGHT $WIDTH $CHOICE_HEIGHT \
"${OPTIONS[@]}" \
2>&1 >/dev/tty)
clear
case $CHOICE in
1)
echo "Running $MYREPO/local.yml"
MYYAML="$MYREPO/local.yml"
deployLocal
;;
2)
echo "Running $MYREPO/local-test.yml"
MYYAML="$MYREPO/local-test.yml"
deployLocal
;;
3)
echo "Running ansible-pull from $MYREPORMT"
$APULL --extra-vars "PANEL_ID=$(getPanelId)" -U $MYREPORMT
;;
4)
echo "Running $MYREPO/local-test.yml"
MYYAML="$MYREPO/local-test.yml"
deployLocal
;;
esac
exit 0