-
-
Notifications
You must be signed in to change notification settings - Fork 251
/
openhabian-setup.sh
executable file
·146 lines (129 loc) · 3.68 KB
/
openhabian-setup.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
# shellcheck disable=SC2034,2154
# openHABian - hassle-free openHAB installation and configuration tool
# for the Raspberry Pi and other Linux systems
#
# Documentation: https://www.openhab.org/docs/installation/openhabian.html
# Development: http://github.com/openhab/openhabian
# Discussion: https://community.openhab.org/t/13379
#
configFile="/etc/openhabian.conf"
if ! [[ -f $configFile ]]; then
cp /opt/openhabian/build-image/openhabian.conf "$configFile"
fi
# Find the absolute script location dir (e.g. BASEDIR=/opt/openhabian)
SOURCE="${BASH_SOURCE[0]}"
while [[ -h $SOURCE ]]; do
BASEDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="${BASEDIR:-/opt/openhabian}/$SOURCE"
done
BASEDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SCRIPTNAME="$(basename "$SOURCE")"
# Trap CTRL+C, CTRL+Z and quit singles
trap '' SIGINT SIGQUIT SIGTSTP
# Log with timestamp
timestamp() { printf "%(%F_%T_%Z)T\\n" "-1"; }
# Make sure only root can run our script
echo -n "$(timestamp) [openHABian] Checking for root privileges... "
if [[ $EUID -ne 0 ]]; then
echo
echo "This script must be run as root. Did you mean 'sudo openhabian-config'?" 1>&2
echo "More info: https://www.openhab.org/docs/installation/openhabian.html"
exit 1
else
echo "OK"
fi
# shellcheck disable=SC1090
source "$configFile"
# script will be called with 'unattended' argument by openHABian images else retrieve values from openhabian.conf
if [[ $1 == "unattended" ]]; then
APTTIMEOUT="${apttimeout:-60}"
UNATTENDED="1"
SILENT="1"
else
INTERACTIVE="1"
fi
# shellcheck disable=SC2154
if [[ $debugmode == "off" ]]; then
SILENT=1
unset DEBUGMAX
elif [[ $debugmode == "on" ]]; then
unset SILENT
unset DEBUGMAX
elif [[ $debugmode == "maximum" ]]; then
unset SILENT
DEBUGMAX=1
set -x
fi
export UNATTENDED SILENT DEBUGMAX INTERACTIVE
# Include all subscripts
# shellcheck source=/dev/null
for shfile in "${BASEDIR:-/opt/openhabian}"/functions/*.bash; do source "$shfile"; done
# avoid potential crash when deleting directory we started from
OLDWD="$(pwd)"
cd /opt || exit 1
CONFIGTXT=/boot/config.txt
if is_bookworm; then
CONFIGTXT=/boot/firmware/config.txt
fi
export CONFIGTXT
# update openhabian.conf to have latest set of parameters
update_openhabian_conf
# disable ipv6 if requested in openhabian.conf (eventually reboots)
config_ipv6
if [[ -n "$UNATTENDED" ]]; then
# apt/dpkg commands will not try interactive dialogs
export DEBIAN_FRONTEND="noninteractive"
wait_for_apt_to_finish_update
load_create_config
change_swapsize
timezone_setting
locale_setting
hostname_change
memory_split
enable_rpi_audio
basic_packages
needed_packages
bashrc_copy
vimrc_copy
install_tailscale "install"
misc_system_settings
add_admin_ssh_key
firemotd_setup
java_install "${java_opt:-17}"
openhab_setup "release"
import_openhab_config
openhab_shell_interfaces && setup_tailscale
vim_openhab_syntax
nano_openhab_syntax
multitail_openhab_scheme
srv_bind_mounts
samba_setup
clean_config_userpw
frontail_setup
custom_frontail_log "add" "$custom_log_files"
jsscripting_npm_install "openhab_rules_tools"
zram_setup
exim_setup
nut_setup
permissions_corrections
setup_mirror_SD "install"
install_cleanup
else
apt_update
whiptail_check
load_create_config
openhabian_console_check
openhabian_update_check
jsscripting_npm_check "openhab"
jsscripting_npm_check "openhab_rules_tools"
while show_main_menu; do
true
done
system_check_default_password
echo -e "$(timestamp) [openHABian] We hope you got what you came for! See you again soon ;)"
fi
# shellcheck disable=SC2164
cd "$OLDWD"
# vim: filetype=sh