123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- #!/bin/bash
- source _common.sh
- source /usr/share/yunohost/helpers
- ynh_clean_setup () {
- ynh_clean_check_starting
- }
- ynh_abort_if_errors
- domain=$YNH_APP_ARG_DOMAIN
- path_url=$YNH_APP_ARG_PATH
- 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..."
- final_path=/var/www/$app
- test ! -e "$final_path" || ynh_die --message="This path already contains a folder"
- ynh_webpath_register --app=$app --domain=$domain --path_url=$path_url
- if [ $firmware_nonfree = "no" ]; then
- firmware_nonfree=0
- elif [ $firmware_nonfree = "yes" ]; then
- firmware_nonfree=1
- fi
- if [[ -z $wifi_ssid || -z $wifi_passphrase ]]; then
- ynh_die --message="Your Wifi Hotspot needs a name and a password"
- fi
- wifi_passphrase_length="$(echo -n "${wifi_passphrase}" | wc -c)"
- 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=domain --value=$domain
- 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
- 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
- install -b -o root -g root -m 0440 ../conf/sudoers.conf /etc/sudoers.d/${app}_ynh
- ynh_replace_string --match_string="__HOTSPOT_SYSUSER__" --replace_string="${app}" --target_file="/etc/sudoers.d/${app}_ynh"
- ynh_script_progression --message="Installing custom script..."
- install -o root -g root -m 0755 ../conf/iw_multissid /usr/local/bin/
- install -o root -g root -m 0755 ../conf/iw_devices /usr/local/bin/
- install -o root -g root -m 0755 ../conf/iw_ssids /usr/local/bin/
- install -o root -g root -m 0755 ../conf/ipv6_expanded /usr/local/bin/
- install -o root -g root -m 0755 ../conf/ipv6_compressed /usr/local/bin/
- if [[ ! -v ip6_net ]]; then
- ip6_net=none
- ip6_addr=none
- if [[ -e /tmp/.ynh-vpnclient-started ]]; then
- vpnclient_ip6_net=$(ynh_app_setting_get vpnclient ip6_net 2>&1)
- vpnclient_ip6_addr=$(ynh_app_setting_get vpnclient ip6_addr 2>&1)
- if [[ $vpnclient_ip6_net =~ :: && $vpnclient_ip6_addr =~ :: ]]; then
- ip6_net=${vpnclient_ip6_net}
- ip6_addr=${vpnclient_ip6_addr}
- fi
- fi
- fi
- hot_reload_usb_wifi_cards
- wifi_device=$(bash ../conf/iw_devices | awk -F\| '{ print $1 }')
- ynh_app_setting_set --app=$app --key=multissid --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_addr --value="${ip6_addr}"
- 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=ip6_dns0 --value=2001:913::8
- ynh_app_setting_set --app=$app --key=ip6_dns1 --value=2001:910:800::12
- ynh_app_setting_set --app=$app --key=ip4_dns0 --value=80.67.188.188
- ynh_app_setting_set --app=$app --key=ip4_dns1 --value=80.67.169.12
- ynh_app_setting_set --app=$app --key=ip4_nat_prefix --value=10.0.242
- ynh_app_setting_set --app=$app --key=vpnclient --value=no
- if [[ -z $wifi_device ]]; then
- ynh_app_setting_set --app=$app --key=service_enabled --value=0
- wifi_device=none
- else
- ynh_app_setting_set --app=$app --key=service_enabled --value=1
- fi
- ynh_script_progression --message="Copying configuration..."
- mkdir -pm 0755 /etc/dnsmasq.dhcpd/
- chown root: /etc/dnsmasq.dhcpd/
- install -b -o root -g root -m 0644 ../conf/hostapd.conf.tpl? /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/
- ynh_replace_string --match_string="__PHPVERSION__" --replace_string="${YNH_PHP_VERSION}" --target_file="/usr/local/bin/$service_name"
- ynh_script_progression --message="Setting up source files..."
- ynh_app_setting_set --app=$app --key=final_path --value=$final_path
- mkdir -pm 0755 $final_path
- cp -a ../sources/* ${final_path}/
- chmod -R 0644 ${final_path}/*
- chmod 750 "$final_path"
- chmod -R o-rwx "$final_path"
- chown -R $app:$app "$final_path"
- ynh_script_progression --message="Configuring NGINX web server..."
- ynh_add_nginx_config
- ynh_script_progression --message="Configuring PHP-FPM..."
- ynh_add_fpm_config
- 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
- echo "DAEMON_CONF=/etc/hostapd/hostapd.conf" > /etc/default/hostapd
- ynh_add_config --template="config.php.tpl" --destination="$final_path/config.php"
- chown $app:$app "$final_path/config.php"
- systemctl disable hostapd --quiet
- systemctl stop hostapd
- systemctl unmask hostapd
- ynh_script_progression --message="Storing the config file checksum..."
- ynh_store_file_checksum --file="/etc/init.d/hostapd"
- ynh_script_progression --message="Configuring a systemd service..."
- ynh_add_systemd_config --service=$service_name
- if [[ $ip6_addr != none ]]; then
- if ip -6 address show dev tun0 2> /dev/null | grep -q "${ip6_addr}/"; then
- ip address delete "${ip6_addr}/128" dev tun0 &> /dev/null
- fi
- fi
- 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" --needs_exposed_ports 67 547
- ynh_script_progression --message="Starting a systemd service..."
- if [[ $wifi_device == none ]]; 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"
|