forked from leonsio/YAHM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yahm-init
executable file
·183 lines (151 loc) · 5.05 KB
/
yahm-init
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
#
# @todo Nach jedem Skript Fehler abfangen
#
#
set -e
LSB_RELEASE="/usr/bin/lsb_release"
ERROR=1
# Check if we can use colours in our output
use_colour=0
[ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null && use_colour=1
# Some useful functions
progress() {
[ $use_colour -eq 1 ] && echo -ne "\033[01;32m"
echo -e "$@" >&2
[ $use_colour -eq 1 ] && echo -ne "\033[00m"
}
info() {
[ $use_colour -eq 1 ] && echo -ne "\033[01;34m"
echo -e "$@" >&2
[ $use_colour -eq 1 ] && echo -ne "\033[00m"
}
die () {
[ $use_colour -eq 1 ] && echo -ne "\033[01;31m"
echo -e "$@" >&2
[ $use_colour -eq 1 ] && echo -ne "\033[00m"
exit 1
}
if [ "$1" = "quickinstall" ]
then
exit_error()
{
if [ $ERROR -eq 1 ]
then
die "An error occurred while processing quickinstall mode. Pleasy try manually installation"
fi
}
trap exit_error EXIT SIGINT SIGTERM
fi
check_install_deb()
{
progress "Installing dependencies"
packages=$1
for P in $packages
do
dpkg -s "$P" >/dev/null 2>&1 && {
info $P is installed
} || {
install_package "$P"
}
done
}
install_package() {
package=$1
info "install ${package}"
apt-get -qq -y install $package 2>&1 > /dev/null
return $?
}
[ "x$(id -un)" == "xroot" ] || die "Sorry, this script must be run as root."
[ -x $LSB_RELEASE ] || install_package "lsb-release"
# Creating needed folders
mkdir -p /var/log/yahm
mkdir -p /var/lib/yahm
# check architecture
case `dpkg --print-architecture` in
armhf|arm64)
info "Found ARM based distribution"
;;
i386|amd64)
info "X86 CPU found, need to install QEMU"
check_install_deb "qemu-user-static binfmt-support"
;;
*)
die "Unsupported CPU architecture, we support only ARM and x86"
;;
esac
DIST_ID="$($LSB_RELEASE -is)"
CODENAME="$($LSB_RELEASE -cs)"
DIST=""
# Check the distribution is in the supported list
case "$DIST_ID:$CODENAME" in
Raspbian:jessie) DIST="debian";;
Debian:jessie) DIST="debian";;
Ubuntu:xenial) DIST="ubuntu";;
*) die "Sorry, this script does not support your distribution/release ($DIST_ID $CODENAME)." ;;
esac
if [ "$DIST_ID" = "Raspbian" ] ;
then
info "Disable new dhcpcd on Raspbian Jessie"
systemctl disable dhcpcd.service
systemctl stop dhcpcd.service
sed -i /etc/network/interfaces -e "s/iface eth0 inet manual/auto eth0\niface eth0 inet dhcp/"
fi
progress "Updating sources"
apt-get -q=2 update
check_install_deb "sendmail bash-completion wget dos2unix python git lxc liblzo2-dev bridge-utils python-lzo patch gzip openssl"
progress "Clean up YAHM directory (removing old versions)"
rm -rf /opt/YAHM
info "done"
# checkout all files
progress "Downloading actual version from git repository"
mkdir -p /opt
cd /opt
#####################################
#### REMOVE --branch IN MASTER !!!!!#
#####################################
git clone --recursive https://github.com/leonsio/YAHM.git 2>>/var/log/yahm/git.log >>/var/log/yahm/git.log
progress "Including YAHM into PATH"
chmod +x /opt/YAHM/bin/*
ln -sf /opt/YAHM/bin/* /usr/sbin/
progress "Installing bash command completion"
ln -sf /opt/YAHM/share/yahm_completion /etc/bash_completion.d/yahm_completion
info "Done"
if [ "$1" = "ui" ] && [ "$DIST" != "ubuntu" ]
then
info "\n\tEnter UI mode\n"
/opt/YAHM/bin/yahm-ui
info "\n\tuse 'yahm-ui' to launch the UI again\n"
fi
if [ "$1" = "quickinstall" ] && [ "$DIST" != "ubuntu" ]
then
info "\n\tEnter quick install mode\n"
progress "\tInstalling LXC container"
/opt/YAHM/bin/yahm-lxc install 2>>/var/log/yahm/lxc.log >>/var/log/yahm/lxc.log
info "\tYAHM LXC container was installed successfully\n"
progress "\tCreating Bridge for networking"
/opt/YAHM/bin/yahm-network -w create_bridge 2>>/var/log/yahm/network_create.log >>/var/log/yahm/network_create.log
info "\tBridge yahmbr0 with interface eth0 was created\n"
progress "\tAttaching network configuration to LXC container"
/opt/YAHM/bin/yahm-network attach_bridge 2>>/var/log/yahm/network_attach.log >>/var/log/yahm/network_attach.log
info "\tyahmbr0 was attached to YAHM LXC container\n"
progress "\tStarting LXC container"
lxc-start -n yahm -d 2>>/var/log/yahm/start.log >>/var/log/yahm/start.log
sleep 5
info "\tYAHM started\n"
progress "\tDisable Homematic-IP\n"
/opt/YAHM/bin/yahm-module -f -m homematic-ip disable 2>>/var/log/yahm/module.log >>/var/log/yahm/module.log
info "\tHomematic-IP was disabled successfully\n"
progress "\tRestarting LXC container"
lxc-stop -k -n yahm 2>>/var/log/yahm/stop.log >>/var/log/yahm/stop.log
sleep 5
lxc-start -n yahm -d 2>>/var/log/yahm/start.log >>/var/log/yahm/start.log
info "\tYAHM successfully restarted\n"
info "YAHM was successfully installed, use 'yahm-ctl join' to access YAHM console or 'yahm-ctl info' for IP information"
# Disable Error handling
ERROR=0
else
# Info
info "Please see 'yahm-lxc' for creating new container, 'yahm-network' for network configuration and 'yahm-modules' for additional modules"
ERROR=0
fi