123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- #!/bin/bash
- source _common.sh
- source /usr/share/yunohost/helpers
- ynh_clean_setup () {
- ynh_clean_check_starting
- }
- ynh_abort_if_errors
- wifi_ssid=$YNH_APP_ARG_WIFI_SSID
- wifi_passphrase=$YNH_APP_ARG_WIFI_PASSPHRASE
- firmware_nonfree=$YNH_APP_ARG_FIRMWARE_NONFREE
- app=$YNH_APP_INSTANCE_NAME
- service_name='ynh-hotspot'
- ynh_script_progression --message="Validating installation parameters..."
- if [[ -z $wifi_ssid ]] || [[ -z $wifi_passphrase ]]; then
- ynh_die --message="Your Wifi Hotspot needs a name and a password"
- fi
- wifi_passphrase_length="$(wc -c <<< "${wifi_passphrase}")"
- if [[ $wifi_passphrase_length -lt 8 ]] || [[ $wifi_passphrase_length -gt 63 ]]; then
- ynh_die --message="Your password must from 8 to 63 characters (WPA2 passphrase)"
- fi
- if [[ $wifi_passphrase =~ [^[:print:]] ]]; then
- ynh_die --message="Only printable ASCII characters are permitted in your password (WPA2 passphrase)"
- fi
- ynh_script_progression --message="Storing installation settings..."
- ynh_app_setting_set --app=$app --key=wifi_ssid --value="$wifi_ssid"
- ynh_app_setting_set --app=$app --key=wifi_passphrase --value="$wifi_passphrase"
- ynh_app_setting_set --app=$app --key=firmware_nonfree --value="$firmware_nonfree"
- ynh_app_setting_set --app=$app --key=service_name --value=$service_name
- ynh_script_progression --message="Configuring firewall..."
- ynh_exec_warn_less yunohost firewall allow --no-upnp --ipv6 UDP 547
- ynh_exec_warn_less yunohost firewall allow --no-upnp UDP 67
- if test -e /usr/sbin/rfkill && rfkill | grep wlan | grep -q -w 'blocked'
- then
- ynh_print_info "Unblocking wlan interface..."
- /usr/sbin/rfkill unblock wlan
- fi
- ynh_script_progression --message="Installing firmware..."
- export DEBIAN_FRONTEND=noninteractive
- if [[ $firmware_nonfree -eq 1 ]]; then
- check_armbian_nonfree_conflict
- ynh_install_extra_app_dependencies --repo="deb http://deb.debian.org/debian $(ynh_get_debian_release) non-free" --package="$nonfree_firmware_packages"
- else
- pkg_dependencies="$pkg_dependencies $free_firmware_packages"
- fi
- ynh_script_progression --message="Installing dependencies..."
- ynh_install_app_dependencies $pkg_dependencies
- ynh_script_progression --message="Configuring system user..."
- ynh_system_user_create --username=$app
- ynh_script_progression --message="Configuring hotspot..."
- if [[ ! -v ip6_net ]]; then
- ip6_net=""
- if [[ -e /tmp/.ynh-vpnclient-started ]]; then
- vpnclient_ip6_net=$(ynh_app_setting_get vpnclient ip6_net 2>&1)
- if [[ $vpnclient_ip6_net =~ :: ]]; then
- ip6_net=${vpnclient_ip6_net}
- fi
- fi
- fi
- hot_reload_usb_wifi_cards
- wifi_device=$(iw_devices | awk -F\| '{ print $1 }')
- ynh_app_setting_set --app=$app --key=multissid --value=1
- ynh_app_setting_set --app=$app --key=ssid_nb --value=1
- ynh_app_setting_set --app=$app --key=wifi_ssid --value="${wifi_ssid}"
- ynh_app_setting_set --app=$app --key=wifi_secure --value=1
- ynh_app_setting_set --app=$app --key=wifi_passphrase --value="${wifi_passphrase}"
- ynh_app_setting_set --app=$app --key=wifi_device --value="${wifi_device}"
- ynh_app_setting_set --app=$app --key=wifi_channel --value=6
- ynh_app_setting_set --app=$app --key=ip6_firewall --value=1
- ynh_app_setting_set --app=$app --key=ip6_net --value="${ip6_net}"
- ynh_app_setting_set --app=$app --key=dns --value="10.0.242.1"
- ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242
- ynh_app_setting_set --app=$app --key=captive_portal --value=0
- ynh_app_setting_set --app=$app --key=captive_portal_url --value=""
- if [[ -z $wifi_device ]]; then
- ynh_app_setting_set --app=$app --key=service_enabled --value=0
- else
- ynh_app_setting_set --app=$app --key=service_enabled --value=1
- fi
- ynh_script_progression --message="Copying configuration files..."
- mkdir -pm 0755 /etc/dnsmasq.dhcpd/
- chown root: /etc/dnsmasq.dhcpd/
- mkdir -pm 0755 /etc/hotspot/
- touch /etc/hotspot/allowed.csv
- chown -R root: /etc/hotspot/
- install -b -o root -g root -m 0644 ../conf/hostapd.*.conf /etc/hostapd/
- install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv6.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv6.conf.tpl
- install -b -o root -g root -m 0644 ../conf/dnsmasq_dhcpdv4.conf.tpl /etc/dnsmasq.dhcpd/dhcpdv4.conf.tpl
- install -o root -g root -m 0755 ../conf/$service_name /usr/local/bin/
- install -o root -g root -m 0755 ../conf/captiveportal_fakedns /usr/local/bin/
- install -o root -g root -m 0755 ../conf/captiveportal_allow /usr/local/bin/
- ynh_script_progression --message="Configuring hostapd..."
- ynh_replace_string --match_string="^DAEMON_CONF=$" --replace_string="&/etc/hostapd/hostapd.conf" --target_file=/etc/init.d/hostapd
- ynh_store_file_checksum --file="/etc/init.d/hostapd"
- echo "DAEMON_CONF=/etc/hostapd/hostapd.conf" > /etc/default/hostapd
- systemctl disable hostapd --quiet 2>&1
- systemctl stop hostapd 2>&1
- systemctl unmask hostapd 2>&1
- ynh_script_progression --message="Configuring a systemd service..."
- ynh_add_systemd_config --service=$service_name
- ynh_add_systemd_config --service=captiveportal_fakedns --template=captiveportal_fakedns
- ynh_script_progression --message="Integrating service in YunoHost..."
- yunohost service add $service_name --description "Creates a Wi-Fi access point" --test_status "systemctl is-active hostapd"
- yunohost service add captiveportal_fakedns --description "Captive portal dns service" --test_status "systemctl is-active captiveportal_fakedns"
- ynh_script_progression --message="Starting a systemd service..."
- if [[ $wifi_device == "" ]]; then
- echo "WARNING: Wifi Hotspot is not started because no wifi device was found (please, check the web admin)" >&2
- else
- ynh_systemd_action --service_name=$service_name --action="start" --log_path=systemd
- fi
- ynh_script_progression --message="Installation of $app completed"
|