aboutsummaryrefslogblamecommitdiff
path: root/scripts/hostclass/unifi_controller
blob: 96558e10c7d0ca1179b2f7db2ee535859af3428e (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                                          



                                     

















                                                                                                                                       



                                                                                                                  








                                                                                                                                 
#!/bin/sh

unifi_user=unifi
unifi_home=/usr/local/share/java/unifi
unifi_https_cert="${unifi_home}/data/unifi.crt"
unifi_https_key="${unifi_home}/data/unifi.key"
unifi_keystore="${unifi_home}/data/keystore"

# Install required packages.
pkg install -y unifi8

# Create ZFS dataset for unifi data.
create_dataset -o "mountpoint=${unifi_home}/data" "${state_dataset}/unifi"
zfs set \
  com.sun:auto-snapshot:daily=true \
  com.sun:auto-snapshot:weekly=true \
  "${state_dataset}/unifi"

# Set ownership on unifi data dir.
install_directory -o "$unifi_user" -g "$unifi_user" -m 0700 "${unifi_home}/data"

# Copy TLS certificate for unifi.
install_certificate             -g "$unifi_user" unifi "$unifi_https_cert"
install_certificate_key -m 0640 -g "$unifi_user" unifi "$unifi_https_key"

# Enable unifi.
sysrc -v unifi_enable=YES

# Stop the unifi service.
service unifi status && service unifi stop

# Add HTTPS certificate to unifi keystore.
[ -f "${unifi_home}/data/keystore" ] || install -Cv -o "$unifi_user" -g "$unifi_user" -m 0600 /dev/null "${unifi_home}/data/keystore"
su -m "$unifi_user" -c "java -jar ${unifi_home}/lib/ace.jar import_key_cert ${unifi_https_key} ${unifi_https_cert} ${site_cacert_path}"

# Add root CA to java keystore.
keytool -list -cacerts -storepass changeit -alias "$site" \
  || keytool -import -trustcacerts -cacerts -storepass changeit -noprompt -alias "$site" -file "$site_cacert_path"

# Disable analytics.
install_directory -m 0640 -o "$unifi_user" -g "$unifi_user" \
  "${unifi_home}/data/sites" \
  "${unifi_home}/data/sites/default"
grep -xFq 'config.system_cfg.1=system.analytics.anonymous=disabled' "${unifi_home}/data/sites/default/config.properties" \
  || echo 'config.system_cfg.1=system.analytics.anonymous=disabled' | tee -a "${unifi_home}/data/sites/default/config.properties"

# Start unifi.
service unifi start