ソースを参照

Can use wifi networks config file from the image builder

Bob Mottram 9 年 前
コミット
2b14e18748
共有4 個のファイルを変更した604 個の追加589 個の削除を含む
  1. 7
    1
      src/freedombone-image
  2. 330
    323
      src/freedombone-image-customise
  3. 2
    0
      src/freedombone-image-make
  4. 265
    265
      src/freedombone-wifi

+ 7
- 1
src/freedombone-image ファイルの表示

@@ -106,6 +106,7 @@ WIFI_SSID=
106 106
 WIFI_TYPE='wpa-psk'
107 107
 WIFI_PASSPHRASE=
108 108
 WIFI_HOTSPOT='no'
109
+WIFI_NETWORKS_FILE=${PROJECT_NAME}-wifi.cfg
109 110
 
110 111
 mesh_router_setup_script() {
111 112
     # create a setup script for a mesh router
@@ -249,6 +250,10 @@ do
249 250
 				WIFI_HOTSPOT='yes'
250 251
 			fi			
251 252
 			;;
253
+        --wifinetworks)
254
+			shift
255
+			WIFI_NETWORKS_FILE="$1"
256
+			;;
252 257
 		*)
253 258
 			# unknown option
254 259
 			;;
@@ -356,7 +361,8 @@ make $IMAGE_TYPE \
356 361
 	 WIFI_SSID="$WIFI_SSID" \
357 362
 	 WIFI_TYPE="$WIFI_TYPE" \
358 363
 	 WIFI_PASSPHRASE="$WIFI_PASSPHRASE" \
359
-	 WIFI_HOTSPOT="$WIFI_HOTSPOT"
364
+	 WIFI_HOTSPOT="$WIFI_HOTSPOT" \
365
+	 WIFI_NETWORKS_FILE="$WIFI_NETWORKS_FILE"
360 366
 	 
361 367
 if [ ! "$?" = "0" ]; then
362 368
 	echo $'Build failed'

+ 330
- 323
src/freedombone-image-customise ファイルの表示

@@ -84,57 +84,58 @@ WIFI_SSID=
84 84
 WIFI_TYPE='wpa-psk'
85 85
 WIFI_PASSPHRASE=
86 86
 WIFI_HOTSPOT='no'
87
+WIFI_NETWORKS_FILE=${PROJECT_NAME}-wifi.cfg
87 88
 
88 89
 enable_eatmydata_override() {
89
-    chroot $rootdir apt-get install --no-install-recommends -y eatmydata
90
-    if [ -x $rootdir/usr/bin/eatmydata ] && \
91
-           [ ! -f $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata ]; then
92
-        echo $"info: Adding apt config to call dpkg via eatmydata"
93
-        printf "#!/bin/sh\nexec eatmydata dpkg \"\$@\"\n" \
94
-               > $rootdir/var/tmp/dpkg-eatmydata
95
-        chmod 755 $rootdir/var/tmp/dpkg-eatmydata
96
-        cat > $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata <<EOF
97
-Dir::Bin::dpkg "/var/tmp/dpkg-eatmydata";
98
-EOF
99
-    else
100
-        echo $"error: unable to find /usr/bin/eatmydata after installing the eatmydata package"
101
-    fi
90
+	chroot $rootdir apt-get install --no-install-recommends -y eatmydata
91
+	if [ -x $rootdir/usr/bin/eatmydata ] && \
92
+		   [ ! -f $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata ]; then
93
+		echo $"info: Adding apt config to call dpkg via eatmydata"
94
+		printf "#!/bin/sh\nexec eatmydata dpkg \"\$@\"\n" \
95
+			   > $rootdir/var/tmp/dpkg-eatmydata
96
+		chmod 755 $rootdir/var/tmp/dpkg-eatmydata
97
+		cat > $rootdir/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata <<EOF
98
+			Dir::Bin::dpkg "/var/tmp/dpkg-eatmydata";
99
+			EOF
100
+	else
101
+		echo $"error: unable to find /usr/bin/eatmydata after installing the eatmydata package"
102
+	fi
102 103
 }
103 104
 
104 105
 disable_eatmydata_override() {
105
-    for override in \
106
-        /etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata \
107
-            /var/tmp/dpkg-eatmydata ; do
108
-        echo $"info: Removing apt config to call dpkg via eatmydata"
109
-        if [ -f $rootdir$override ] ; then
110
-            rm -f $rootdir$override
111
-        else
112
-            echo $"warning: missing $rootdir$override"
113
-        fi
114
-    done
115
-    sync # Flush file buffers before continuing
106
+	for override in \
107
+		/etc/apt/apt.conf.d/95debian-edu-install-dpkg-eatmydata \
108
+			/var/tmp/dpkg-eatmydata ; do
109
+		echo $"info: Removing apt config to call dpkg via eatmydata"
110
+		if [ -f $rootdir$override ] ; then
111
+			rm -f $rootdir$override
112
+		else
113
+			echo $"warning: missing $rootdir$override"
114
+		fi
115
+	done
116
+	sync # Flush file buffers before continuing
116 117
 }
117 118
 
118 119
 set_apt_sources() {
119
-    NEW_MIRROR="$1"
120
-    COMPONENTS="main"
120
+	NEW_MIRROR="$1"
121
+	COMPONENTS="main"
121 122
 
122
-    cat <<EOF > etc/apt/sources.list
123
-deb $NEW_MIRROR $SUITE $COMPONENTS
124
-deb-src $NEW_MIRROR $SUITE $COMPONENTS
123
+	cat <<EOF > etc/apt/sources.list
124
+		deb $NEW_MIRROR $SUITE $COMPONENTS
125
+		deb-src $NEW_MIRROR $SUITE $COMPONENTS
125 126
 
126
-#deb http://security.debian.org/ $SUITE/updates main
127
-#deb-src http://security.debian.org/ $SUITE/updates main
128
-EOF
127
+		#deb http://security.debian.org/ $SUITE/updates main
128
+		#deb-src http://security.debian.org/ $SUITE/updates main
129
+		EOF
129 130
 }
130 131
 
131 132
 configure_networking() {
132
-    if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
133
-        return
134
-    fi
133
+	if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
134
+		return
135
+	fi
135 136
     
136
-    if [[ $GENERIC_IMAGE == "no" ]]; then
137
-        echo "# This file describes the network interfaces available on your system
137
+	if [[ $GENERIC_IMAGE == "no" ]]; then
138
+		echo "# This file describes the network interfaces available on your system
138 139
 # and how to activate them. For more information, see interfaces(5).
139 140
 
140 141
 # The loopback network interface
@@ -148,43 +149,43 @@ iface eth0 inet static
148 149
     netmask 255.255.255.0
149 150
     gateway $ROUTER_IP_ADDRESS
150 151
     dns-nameservers $NAMESERVER1 $NAMESERVER2
151
-        # Example to keep MAC address between reboots
152
-        #hwaddress ether B5:A2:BE:3F:1A:FE
153
-
154
-        # The secondary network interface
155
-        #auto eth1
156
-        #iface eth1 inet dhcp
157
-
158
-        # WiFi Example
159
-        #auto wlan0
160
-        #iface wlan0 inet dhcp
161
-        #    wpa-ssid \"essid\"
162
-        #    wpa-psk  \"password\"
163
-
164
-        # Ethernet/RNDIS gadget (g_ether)
165
-        # ... or on host side, usbnet and random hwaddr
166
-        # Note on some boards, usb0 is automaticly setup with an init script
167
-        #iface usb0 inet static
168
-        #    address 192.168.7.2
169
-        #    netmask 255.255.255.0
170
-        #    network 192.168.7.0
171
-        #    gateway 192.168.7.1" > $rootdir/etc/network/interfaces
172
-
173
-        hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
174
-        a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
175
-        b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
176
-        c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
177
-        d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
178
-        e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
179
-        sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \
180
-            $rootdir/etc/network/interfaces
181
-    fi
182
-
183
-    sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
184
-    sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
185
-
186
-    # change the motd to show further install instructions
187
-    echo $"
152
+		# Example to keep MAC address between reboots
153
+		#hwaddress ether B5:A2:BE:3F:1A:FE
154
+
155
+		# The secondary network interface
156
+		#auto eth1
157
+		#iface eth1 inet dhcp
158
+
159
+		# WiFi Example
160
+		#auto wlan0
161
+		#iface wlan0 inet dhcp
162
+		#    wpa-ssid \"essid\"
163
+		#    wpa-psk  \"password\"
164
+
165
+		# Ethernet/RNDIS gadget (g_ether)
166
+		# ... or on host side, usbnet and random hwaddr
167
+		# Note on some boards, usb0 is automaticly setup with an init script
168
+		#iface usb0 inet static
169
+		#    address 192.168.7.2
170
+		#    netmask 255.255.255.0
171
+		#    network 192.168.7.0
172
+		#    gateway 192.168.7.1" > $rootdir/etc/network/interfaces
173
+
174
+		hexarray=( 1 2 3 4 5 6 7 8 9 0 a b c d e f )
175
+		a=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
176
+		b=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
177
+		c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
178
+		d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
179
+		e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
180
+		sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \
181
+			$rootdir/etc/network/interfaces
182
+	fi
183
+
184
+	sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
185
+	sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
186
+
187
+	# change the motd to show further install instructions
188
+	echo $"
188 189
  .---.                  .              .
189 190
  |                      |              |
190 191
  |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
@@ -203,57 +204,57 @@ following commands, then enter your details.
203 204
 }
204 205
 
205 206
 configure_ssh() {
206
-    sed -i "s/Port .*/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
207
-
208
-    if [[ "$SSH_PUBKEY" != "no" ]]; then
209
-        if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then
210
-            mkdir $rootdir/home/$MY_USERNAME/.ssh
211
-        fi
212
-        echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys
213
-        chroot $rootdir chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
214
-        sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
215
-        echo $"Using ssh public key:"
216
-        echo $SSH_PUBKEY
217
-        echo $'Password ssh authentication turned off'
218
-    fi
207
+	sed -i "s/Port .*/Port ${SSH_PORT}/g" $rootdir/etc/ssh/sshd_config
208
+
209
+	if [[ "$SSH_PUBKEY" != "no" ]]; then
210
+		if [ ! -d $rootdir/home/$MY_USERNAME/.ssh ]; then
211
+			mkdir $rootdir/home/$MY_USERNAME/.ssh
212
+		fi
213
+		echo "$SSH_PUBKEY" > $rootdir/home/$MY_USERNAME/.ssh/authorized_keys
214
+		chroot $rootdir chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
215
+		sed -i 's|PasswordAuthentication.*|PasswordAuthentication no|g' $rootdir/etc/ssh/sshd_config
216
+		echo $"Using ssh public key:"
217
+		echo $SSH_PUBKEY
218
+		echo $'Password ssh authentication turned off'
219
+	fi
219 220
 }
220 221
 
221 222
 admin_user_sudo() {
222
-    echo "$MY_USERNAME  ALL=(ALL) ALL" >> $rootdir/etc/sudoers
223
+	echo "$MY_USERNAME  ALL=(ALL) ALL" >> $rootdir/etc/sudoers
223 224
 }
224 225
 
225 226
 create_generic_image() {
226
-    if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
227
-        return
228
-    fi  
229
-    if [[ $GENERIC_IMAGE == "no" ]]; then
230
-        return
231
-    fi
232
-    VARIANT="full"
233
-    if [ $CONFIG_FILENAME ]; then
234
-        if [[ "$CONFIG_FILENAME" == *"mesh.cfg"* ]]; then
235
-            VARIANT="mesh"
236
-        fi
237
-    fi
238
-
239
-    # Don't install any configuration. This will be a base system
240
-    if [[ $VARIANT != "mesh" ]]; then
241
-        CONFIG_FILENAME=
242
-    else
243
-        touch $rootdir/root/.initial_mesh_setup
244
-    fi
245
-
246
-    # The presence of this file indicates that the initial
247
-    # setup has not yet been completed
248
-    touch $rootdir/home/$MY_USERNAME/.initial_setup
249
-    chroot $rootdir chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.initial_setup
250
-    touch $rootdir/root/.initial_setup
251
-
252
-    cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
253
-# initial setup of the system
254
-if [ -f ~/.initial_setup ]; then
255
-    clear
256
-    echo "
227
+	if [[ $DEBIAN_INSTALL_ONLY != "no" ]]; then
228
+		return
229
+	fi  
230
+	if [[ $GENERIC_IMAGE == "no" ]]; then
231
+		return
232
+	fi
233
+	VARIANT="full"
234
+	if [ $CONFIG_FILENAME ]; then
235
+		if [[ "$CONFIG_FILENAME" == *"mesh.cfg"* ]]; then
236
+			VARIANT="mesh"
237
+		fi
238
+	fi
239
+
240
+	# Don't install any configuration. This will be a base system
241
+	if [[ $VARIANT != "mesh" ]]; then
242
+		CONFIG_FILENAME=
243
+	else
244
+		touch $rootdir/root/.initial_mesh_setup
245
+	fi
246
+
247
+	# The presence of this file indicates that the initial
248
+	# setup has not yet been completed
249
+	touch $rootdir/home/$MY_USERNAME/.initial_setup
250
+	chroot $rootdir chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.initial_setup
251
+	touch $rootdir/root/.initial_setup
252
+
253
+	cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
254
+		# initial setup of the system
255
+		if [ -f ~/.initial_setup ]; then
256
+			clear
257
+			echo "
257 258
  .---.                  .              .
258 259
  |                      |              |
259 260
  |--- .--. .-.  .-.  .-.|  .-. .--.--. |.-.  .-. .--.  .-.
@@ -264,183 +265,189 @@ if [ -f ~/.initial_setup ]; then
264 265
 
265 266
           Please enter your password a second time.
266 267
 "
267
-    sudo su
268
-fi
269
-EOF
270
-
271
-    echo '# initial setup of the system' >> $rootdir/root/.bashrc
272
-    echo 'if [ -f ~/.initial_setup ]; then' >> $rootdir/root/.bashrc
273
-    echo '    if [ -f ~/login.txt ]; then' >> $rootdir/root/.bashrc
274
-    echo '        NEW_USER_PASSWORD=$(printf `cat ~/login.txt`)' >> $rootdir/root/.bashrc
275
-    echo '    else' >> $rootdir/root/.bashrc
276
-    echo '        ENTROPY=$(cat /proc/sys/kernel/random/entropy_avail)' >> $rootdir/root/.bashrc
277
-    echo '        if [ $ENTROPY -lt 500 ]; then' >> $rootdir/root/.bashrc
278
-    ENTROPY_MESSAGE1=$'Initial setup process'
279
-    ENTROPY_MESSAGE2=$'Password Generation'
280
-    ENTROPY_MESSAGE3=$'WARNING: The entropy available on this system is too low to generate a password.\n\nThe installation process cannot continue.'
281
-    echo "            dialog --backtitle \"${ENTROPY_MESSAGE1}\" --title \"${ENTROPY_MESSAGE2}\" --msgbox \"${ENTROPY_MESSAGE3}\" 8 50" >> $rootdir/root/.bashrc
282
-    echo '            exit' >> $rootdir/root/.bashrc
283
-    echo '        fi' >> $rootdir/root/.bashrc
284
-    echo '        NEW_USER_PASSWORD="$(openssl rand -base64 12 | cut -c1-10)"' >> $rootdir/root/.bashrc
285
-    echo '    fi' >> $rootdir/root/.bashrc
286
-    echo '    echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/root/.bashrc
287
-
288
-    echo '    clear' >> $rootdir/root/.bashrc
289
-    echo '    echo ""' >> $rootdir/root/.bashrc
290
-    NEW_LOGIN_PASSWORD_MESSAGE1=$'Your new login password is:'
291
-    NEW_LOGIN_PASSWORD_MESSAGE2=$'Use it whenever you wish to ssh into this system.'
292
-    NEW_LOGIN_PASSWORD_MESSAGE3=$'IMPORTANT: Please take a moment to enter the above password into a\npassword manager or write it down somewhere.'
293
-    PRESS_KEY_MESSAGE=$'Press any key to continue...'
294
-    echo "    echo \"${NEW_LOGIN_PASSWORD_MESSAGE1}\"" >> $rootdir/root/.bashrc
295
-    echo '    echo ""' >> $rootdir/root/.bashrc
296
-    echo '    toilet "${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
297
-    echo '    echo ""' >> $rootdir/root/.bashrc
298
-    echo '    echo "                          ${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
299
-    echo '    echo ""' >> $rootdir/root/.bashrc
300
-    echo "    echo \"${NEW_LOGIN_PASSWORD_MESSAGE2}\"" >> $rootdir/root/.bashrc
301
-    echo '    echo ""' >> $rootdir/root/.bashrc
302
-    echo "    echo \"${NEW_LOGIN_PASSWORD_MESSAGE3}\"" >> $rootdir/root/.bashrc
303
-    echo '    echo ""' >> $rootdir/root/.bashrc
304
-    echo "    read -n1 -r -p \"${PRESS_KEY_MESSAGE}\" key" >> $rootdir/root/.bashrc
305
-
306
-    # change the password for the admin user
307
-    echo -n "    echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
308
-    echo '$(printf `cat ~/login.txt`)"|chpasswd' >> $rootdir/root/.bashrc
309
-
310
-    # update before continuing
311
-    echo "    cd /root/${PROJECT_NAME}" >> $rootdir/root/.bashrc
312
-    echo "    git stash" >> $rootdir/root/.bashrc
313
-    echo "    git pull" >> $rootdir/root/.bashrc
314
-    echo "    make install" >> $rootdir/root/.bashrc
315
-
316
-    if [[ $VARIANT != "mesh" ]]; then
317
-        if [[ $ONION_ONLY == "no" ]]; then
318
-            if [[ $MINIMAL_INSTALL == "no" ]]; then
319
-                echo "    ${PROJECT_NAME} menuconfig-full" >> $rootdir/root/.bashrc
320
-            else
321
-                echo "    ${PROJECT_NAME} menuconfig" >> $rootdir/root/.bashrc
322
-            fi
323
-        else
324
-            echo "    ${PROJECT_NAME} menuconfig-onion" >> $rootdir/root/.bashrc
325
-        fi
326
-    else
327
-        echo "    echo ''" >> $rootdir/root/.bashrc
328
-    fi
329
-    echo '    if [ "$?" = "0" ]; then' >> $rootdir/root/.bashrc
330
-    echo "        if [ -f ~/${PROJECT_NAME}-completed.txt ]; then" >> $rootdir/root/.bashrc
331
-    # Remove the initial setup files
332
-    echo '            rm /root/.initial_setup' >> $rootdir/root/.bashrc
333
-    echo "            rm /home/${MY_USERNAME}/.initial_setup" >> $rootdir/root/.bashrc
334
-    echo "            touch /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
335
-    echo '            shred -zu ~/login.txt' >> $rootdir/root/.bashrc
336
-    END_MESSAGE1=$'Congratulations!'
337
-    if [[ $VARIANT != "mesh" ]]; then
338
-        END_MESSAGE2=$'\nYour system has now installed\n\nThe onion ssh service is at $SSH_ONION_HOSTNAME\n\nPress any key to reboot and begin using it'
339
-        echo '            SSH_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_ssh/hostname)' >> $rootdir/root/.bashrc
340
-    else
341
-        END_MESSAGE2=$'\nYour system has now installed\n\nPress any key to reboot and begin using it'
342
-    fi
343
-    echo "            dialog --title '$END_MESSAGE1' --msgbox \"$END_MESSAGE2\" 9 50" >> $rootdir/root/.bashrc
344
-    echo '            reboot' >> $rootdir/root/.bashrc
345
-    echo '        fi' >> $rootdir/root/.bashrc
346
-    echo '    else' >> $rootdir/root/.bashrc
347
-    echo '        key=' >> $rootdir/root/.bashrc
348
-    echo '        while [[ $key != "x" ]]; do' >> $rootdir/root/.bashrc
349
-    INSTALL_FAIL_MESSAGE=$"Install failed. Press x to continue..."
350
-    echo "            read -n1 -r -p \"${INSTALL_FAIL_MESSAGE}\" key" >> $rootdir/root/.bashrc
351
-    echo '        done' >> $rootdir/root/.bashrc
352
-    echo '    fi' >> $rootdir/root/.bashrc
353
-    echo '    exit' >> $rootdir/root/.bashrc
354
-    echo 'else' >> $rootdir/root/.bashrc
355
-    echo '    # Remove default account after install' >> $rootdir/root/.bashrc
356
-    echo "    if [ -f /root/.remove_${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
357
-    echo "        if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
358
-    echo "           userdel -r ${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
359
-    echo "           if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
360
-    echo "               rm -rf /home/${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
361
-    echo "               rm /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
362
-    echo '           fi' >> $rootdir/root/.bashrc
363
-    echo '        fi' >> $rootdir/root/.bashrc
364
-    echo '    fi' >> $rootdir/root/.bashrc
365
-    echo 'fi' >> $rootdir/root/.bashrc
268
+			sudo su
269
+		fi
270
+		EOF
271
+
272
+	echo '# initial setup of the system' >> $rootdir/root/.bashrc
273
+	echo 'if [ -f ~/.initial_setup ]; then' >> $rootdir/root/.bashrc
274
+	echo '    if [ -f ~/login.txt ]; then' >> $rootdir/root/.bashrc
275
+	echo '        NEW_USER_PASSWORD=$(printf `cat ~/login.txt`)' >> $rootdir/root/.bashrc
276
+	echo '    else' >> $rootdir/root/.bashrc
277
+	echo '        ENTROPY=$(cat /proc/sys/kernel/random/entropy_avail)' >> $rootdir/root/.bashrc
278
+	echo '        if [ $ENTROPY -lt 500 ]; then' >> $rootdir/root/.bashrc
279
+	ENTROPY_MESSAGE1=$'Initial setup process'
280
+	ENTROPY_MESSAGE2=$'Password Generation'
281
+	ENTROPY_MESSAGE3=$'WARNING: The entropy available on this system is too low to generate a password.\n\nThe installation process cannot continue.'
282
+	echo "            dialog --backtitle \"${ENTROPY_MESSAGE1}\" --title \"${ENTROPY_MESSAGE2}\" --msgbox \"${ENTROPY_MESSAGE3}\" 8 50" >> $rootdir/root/.bashrc
283
+	echo '            exit' >> $rootdir/root/.bashrc
284
+	echo '        fi' >> $rootdir/root/.bashrc
285
+	echo '        NEW_USER_PASSWORD="$(openssl rand -base64 12 | cut -c1-10)"' >> $rootdir/root/.bashrc
286
+	echo '    fi' >> $rootdir/root/.bashrc
287
+	echo '    echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/root/.bashrc
288
+
289
+	echo '    clear' >> $rootdir/root/.bashrc
290
+	echo '    echo ""' >> $rootdir/root/.bashrc
291
+	NEW_LOGIN_PASSWORD_MESSAGE1=$'Your new login password is:'
292
+	NEW_LOGIN_PASSWORD_MESSAGE2=$'Use it whenever you wish to ssh into this system.'
293
+	NEW_LOGIN_PASSWORD_MESSAGE3=$'IMPORTANT: Please take a moment to enter the above password into a\npassword manager or write it down somewhere.'
294
+	PRESS_KEY_MESSAGE=$'Press any key to continue...'
295
+	echo "    echo \"${NEW_LOGIN_PASSWORD_MESSAGE1}\"" >> $rootdir/root/.bashrc
296
+	echo '    echo ""' >> $rootdir/root/.bashrc
297
+	echo '    toilet "${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
298
+	echo '    echo ""' >> $rootdir/root/.bashrc
299
+	echo '    echo "                          ${NEW_USER_PASSWORD}"' >> $rootdir/root/.bashrc
300
+	echo '    echo ""' >> $rootdir/root/.bashrc
301
+	echo "    echo \"${NEW_LOGIN_PASSWORD_MESSAGE2}\"" >> $rootdir/root/.bashrc
302
+	echo '    echo ""' >> $rootdir/root/.bashrc
303
+	echo "    echo \"${NEW_LOGIN_PASSWORD_MESSAGE3}\"" >> $rootdir/root/.bashrc
304
+	echo '    echo ""' >> $rootdir/root/.bashrc
305
+	echo "    read -n1 -r -p \"${PRESS_KEY_MESSAGE}\" key" >> $rootdir/root/.bashrc
306
+
307
+	# change the password for the admin user
308
+	echo -n "    echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
309
+	echo '$(printf `cat ~/login.txt`)"|chpasswd' >> $rootdir/root/.bashrc
310
+
311
+	# update before continuing
312
+	echo "    cd /root/${PROJECT_NAME}" >> $rootdir/root/.bashrc
313
+	echo "    git stash" >> $rootdir/root/.bashrc
314
+	echo "    git pull" >> $rootdir/root/.bashrc
315
+	echo "    make install" >> $rootdir/root/.bashrc
316
+
317
+	if [[ $VARIANT != "mesh" ]]; then
318
+		if [[ $ONION_ONLY == "no" ]]; then
319
+			if [[ $MINIMAL_INSTALL == "no" ]]; then
320
+				echo "    ${PROJECT_NAME} menuconfig-full" >> $rootdir/root/.bashrc
321
+			else
322
+				echo "    ${PROJECT_NAME} menuconfig" >> $rootdir/root/.bashrc
323
+			fi
324
+		else
325
+			echo "    ${PROJECT_NAME} menuconfig-onion" >> $rootdir/root/.bashrc
326
+		fi
327
+	else
328
+		echo "    echo ''" >> $rootdir/root/.bashrc
329
+	fi
330
+	echo '    if [ "$?" = "0" ]; then' >> $rootdir/root/.bashrc
331
+	echo "        if [ -f ~/${PROJECT_NAME}-completed.txt ]; then" >> $rootdir/root/.bashrc
332
+	# Remove the initial setup files
333
+	echo '            rm /root/.initial_setup' >> $rootdir/root/.bashrc
334
+	echo "            rm /home/${MY_USERNAME}/.initial_setup" >> $rootdir/root/.bashrc
335
+	echo "            touch /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
336
+	echo '            shred -zu ~/login.txt' >> $rootdir/root/.bashrc
337
+	END_MESSAGE1=$'Congratulations!'
338
+	if [[ $VARIANT != "mesh" ]]; then
339
+		END_MESSAGE2=$'\nYour system has now installed\n\nThe onion ssh service is at $SSH_ONION_HOSTNAME\n\nPress any key to reboot and begin using it'
340
+		echo '            SSH_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_ssh/hostname)' >> $rootdir/root/.bashrc
341
+	else
342
+		END_MESSAGE2=$'\nYour system has now installed\n\nPress any key to reboot and begin using it'
343
+	fi
344
+	echo "            dialog --title '$END_MESSAGE1' --msgbox \"$END_MESSAGE2\" 9 50" >> $rootdir/root/.bashrc
345
+	echo '            reboot' >> $rootdir/root/.bashrc
346
+	echo '        fi' >> $rootdir/root/.bashrc
347
+	echo '    else' >> $rootdir/root/.bashrc
348
+	echo '        key=' >> $rootdir/root/.bashrc
349
+	echo '        while [[ $key != "x" ]]; do' >> $rootdir/root/.bashrc
350
+	INSTALL_FAIL_MESSAGE=$"Install failed. Press x to continue..."
351
+	echo "            read -n1 -r -p \"${INSTALL_FAIL_MESSAGE}\" key" >> $rootdir/root/.bashrc
352
+	echo '        done' >> $rootdir/root/.bashrc
353
+	echo '    fi' >> $rootdir/root/.bashrc
354
+	echo '    exit' >> $rootdir/root/.bashrc
355
+	echo 'else' >> $rootdir/root/.bashrc
356
+	echo '    # Remove default account after install' >> $rootdir/root/.bashrc
357
+	echo "    if [ -f /root/.remove_${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
358
+	echo "        if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
359
+	echo "           userdel -r ${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
360
+	echo "           if [ -d /home/${GENERIC_IMAGE_USERNAME} ]; then" >> $rootdir/root/.bashrc
361
+	echo "               rm -rf /home/${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
362
+	echo "               rm /root/.remove_${GENERIC_IMAGE_USERNAME}" >> $rootdir/root/.bashrc
363
+	echo '           fi' >> $rootdir/root/.bashrc
364
+	echo '        fi' >> $rootdir/root/.bashrc
365
+	echo '    fi' >> $rootdir/root/.bashrc
366
+	echo 'fi' >> $rootdir/root/.bashrc
366 367
 }
367 368
 
368 369
 continue_installation() {
369
-    # If a configuration file exists then run with it
370
-    # otherwise the interactive installer can be used
371
-    # This is equivalent to installing freedombox-setup on freedombox
372
-    if [ $CONFIG_FILENAME ]; then
373
-        if [ ${#CONFIG_FILENAME} -gt 2 ]; then
374
-            cp $CONFIG_FILENAME $rootdir/root/$PROJECT_NAME.cfg
375
-            cat $rootdir/root/$PROJECT_NAME.cfg
376
-            chroot "$rootdir" su -c "$PROJECT_NAME -c /root/$PROJECT_NAME.cfg" - root
377
-        fi
378
-    fi
370
+	# If a configuration file exists then run with it
371
+	# otherwise the interactive installer can be used
372
+	# This is equivalent to installing freedombox-setup on freedombox
373
+	if [ $CONFIG_FILENAME ]; then
374
+		if [ ${#CONFIG_FILENAME} -gt 2 ]; then
375
+			cp $CONFIG_FILENAME $rootdir/root/$PROJECT_NAME.cfg
376
+			cat $rootdir/root/$PROJECT_NAME.cfg
377
+			chroot "$rootdir" su -c "$PROJECT_NAME -c /root/$PROJECT_NAME.cfg" - root
378
+		fi
379
+	fi
379 380
 }
380 381
 
381 382
 atheros_wifi() {
382
-    firmware_filename="open-ath9k-htc-firmware_1.3-1_all.deb"
383
-    firmware_hash='5fea58ffefdf0ef15b504db7fbe3bc078c03e0d927bba64085e4b6f2546102f5'
384
-
385
-    firmware_url="http://us.archive.trisquel.info/trisquel/pool/main/o/open-ath9k-htc-firmware/$firmware_filename"
386
-    firmware_tempfile="/tmp/$firmware_filename"
387
-    wget "$firmware_url" -O "$rootdir$firmware_tempfile"
388
-    downloaded_firmware_hash=$(sha256sum "$rootdir$firmware_tempfile" | awk -F ' ' '{print $1}')
389
-    if [[ "$downloaded_firmware_hash" == "$firmware_hash" ]]; then
390
-        chroot "$rootdir" dpkg -i "$firmware_tempfile"
391
-    else
392
-        echo 'WARNING: Atheros Wifi firmware hash does not match. The driver has not been installed.'
393
-    fi
383
+	firmware_filename="open-ath9k-htc-firmware_1.3-1_all.deb"
384
+	firmware_hash='5fea58ffefdf0ef15b504db7fbe3bc078c03e0d927bba64085e4b6f2546102f5'
385
+
386
+	firmware_url="http://us.archive.trisquel.info/trisquel/pool/main/o/open-ath9k-htc-firmware/$firmware_filename"
387
+	firmware_tempfile="/tmp/$firmware_filename"
388
+	wget "$firmware_url" -O "$rootdir$firmware_tempfile"
389
+	downloaded_firmware_hash=$(sha256sum "$rootdir$firmware_tempfile" | awk -F ' ' '{print $1}')
390
+	if [[ "$downloaded_firmware_hash" == "$firmware_hash" ]]; then
391
+		chroot "$rootdir" dpkg -i "$firmware_tempfile"
392
+	else
393
+		echo 'WARNING: Atheros Wifi firmware hash does not match. The driver has not been installed.'
394
+	fi
394 395
 }
395 396
 
396 397
 
397 398
 initialise_mesh() {
398
-    if [[ $VARIANT != "mesh" || $DEBIAN_INSTALL_ONLY != "no" ]]; then
399
-        return
400
-    fi
401
-    freedombone-mesh-install -f firewall -r "${rootdir}"
402
-    freedombone-mesh-install -f avahi -r "${rootdir}"
403
-    freedombone-mesh-install -f batman -r "${rootdir}"
404
-    freedombone-mesh-install -f tox_node -r "${rootdir}"
405
-    freedombone-mesh-install -f tox_client -r "${rootdir}"
406
-    freedombone-mesh-install -f zeronet -r "${rootdir}"
407
-
408
-    MESH_SERVICE='mesh-setup.service'
409
-    MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
410
-
411
-    echo '[Unit]' > $MESH_SETUP_DAEMON
412
-    echo 'Description=Initial mesh router configuration' >> $MESH_SETUP_DAEMON
413
-    echo 'After=syslog.target' >> $MESH_SETUP_DAEMON
414
-    echo 'After=network.target' >> $MESH_SETUP_DAEMON
415
-    echo '[Service]' >> $MESH_SETUP_DAEMON
416
-    echo 'Type=simple' >> $MESH_SETUP_DAEMON
417
-    echo 'User=root' >> $MESH_SETUP_DAEMON
418
-    echo 'Group=root' >> $MESH_SETUP_DAEMON
419
-    echo 'WorkingDirectory=/root' >> $MESH_SETUP_DAEMON
420
-    echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-image-mesh > /var/log/mesh-setup.log" >> $MESH_SETUP_DAEMON
421
-    echo '' >> $MESH_SETUP_DAEMON
422
-    echo 'TimeoutSec=99999' >> $MESH_SETUP_DAEMON
423
-    echo '' >> $MESH_SETUP_DAEMON
424
-    echo '[Install]' >> $MESH_SETUP_DAEMON
425
-    echo 'WantedBy=multi-user.target' >> $MESH_SETUP_DAEMON
426
-    chroot "$rootdir" systemctl enable $MESH_SERVICE
399
+	if [[ $VARIANT != "mesh" || $DEBIAN_INSTALL_ONLY != "no" ]]; then
400
+		return
401
+	fi
402
+	freedombone-mesh-install -f firewall -r "${rootdir}"
403
+	freedombone-mesh-install -f avahi -r "${rootdir}"
404
+	freedombone-mesh-install -f batman -r "${rootdir}"
405
+	freedombone-mesh-install -f tox_node -r "${rootdir}"
406
+	freedombone-mesh-install -f tox_client -r "${rootdir}"
407
+	freedombone-mesh-install -f zeronet -r "${rootdir}"
408
+
409
+	MESH_SERVICE='mesh-setup.service'
410
+	MESH_SETUP_DAEMON=$rootdir/etc/systemd/system/$MESH_SERVICE
411
+
412
+	echo '[Unit]' > $MESH_SETUP_DAEMON
413
+	echo 'Description=Initial mesh router configuration' >> $MESH_SETUP_DAEMON
414
+	echo 'After=syslog.target' >> $MESH_SETUP_DAEMON
415
+	echo 'After=network.target' >> $MESH_SETUP_DAEMON
416
+	echo '[Service]' >> $MESH_SETUP_DAEMON
417
+	echo 'Type=simple' >> $MESH_SETUP_DAEMON
418
+	echo 'User=root' >> $MESH_SETUP_DAEMON
419
+	echo 'Group=root' >> $MESH_SETUP_DAEMON
420
+	echo 'WorkingDirectory=/root' >> $MESH_SETUP_DAEMON
421
+	echo "ExecStart=/usr/local/bin/${PROJECT_NAME}-image-mesh > /var/log/mesh-setup.log" >> $MESH_SETUP_DAEMON
422
+	echo '' >> $MESH_SETUP_DAEMON
423
+	echo 'TimeoutSec=99999' >> $MESH_SETUP_DAEMON
424
+	echo '' >> $MESH_SETUP_DAEMON
425
+	echo '[Install]' >> $MESH_SETUP_DAEMON
426
+	echo 'WantedBy=multi-user.target' >> $MESH_SETUP_DAEMON
427
+	chroot "$rootdir" systemctl enable $MESH_SERVICE
427 428
 }
428 429
 
429 430
 configure_wifi() {
430
-    if [[ $VARIANT == "mesh" ]]; then
431
-        return
432
-    fi
433
-    if [[ $WIFI_TYPE != 'none' ]]; then
434
-        if [ ! $WIFI_PASSPHRASE ]; then
435
-            return
436
-        fi
437
-        if [ ${#WIFI_PASSPHRASE} -lt 2 ]; then
438
-            return
439
-        fi  
440
-        chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $HOTSPOT
441
-    else
442
-        chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE --hotspot $HOTSPOT
443
-    fi
431
+	if [[ $VARIANT == "mesh" ]]; then
432
+		return
433
+	fi
434
+
435
+	if [ -f $WIFI_NETWORKS_FILE ]; then
436
+		chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE --networks $WIFI_NETWORKS_FILE
437
+		return
438
+	fi
439
+	
440
+	if [[ $WIFI_TYPE != 'none' ]]; then
441
+		if [ ! $WIFI_PASSPHRASE ]; then
442
+			return
443
+		fi
444
+		if [ ${#WIFI_PASSPHRASE} -lt 2 ]; then
445
+			return
446
+		fi  
447
+		chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE -p $WIFI_PASSPHRASE --hotspot $HOTSPOT
448
+	else
449
+		chroot "$rootdir" ${PROJECT_NAME}-wifi -i $WIFI_INTERFACE -s $WIFI_SSID -t $WIFI_TYPE --hotspot $HOTSPOT
450
+	fi
444 451
 }
445 452
 
446 453
 # Set to true/false to control if eatmydata is used during build
@@ -468,16 +475,16 @@ echo $username:$password | chroot $rootdir /usr/sbin/chpasswd
468 475
 chroot "$rootdir" adduser $username sudo
469 476
 
470 477
 case "$MACHINE" in
471
-    virtualbox)
472
-        # hide irrelevant console keyboard messages.
473
-        echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
474
-             >> /etc/init.d/rc.local
475
-        ;;
476
-    qemu)
477
-        # hide irrelevant console keyboard messages.
478
-        echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
479
-             >> /etc/init.d/rc.local
480
-        ;;
478
+	virtualbox)
479
+		# hide irrelevant console keyboard messages.
480
+		echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
481
+			 >> /etc/init.d/rc.local
482
+		;;
483
+	qemu)
484
+		# hide irrelevant console keyboard messages.
485
+		echo "echo \"4 4 1 7\" > /proc/sys/kernel/printk" \
486
+			 >> /etc/init.d/rc.local
487
+		;;
481 488
 esac
482 489
 
483 490
 set_apt_sources $BUILD_MIRROR
@@ -487,19 +494,19 @@ chroot "$rootdir" apt-get clean
487 494
 chroot "$rootdir" apt-get update
488 495
 
489 496
 cat > $rootdir/usr/sbin/policy-rc.d <<EOF
490
-#!/bin/sh
491
-exit 101
492
-EOF
497
+	#!/bin/sh
498
+	exit 101
499
+	EOF
493 500
 chmod a+rx $rootdir/usr/sbin/policy-rc.d
494 501
 
495 502
 if $use_eatmydata ; then
496
-    enable_eatmydata_override
503
+	enable_eatmydata_override
497 504
 fi
498 505
 
499 506
 if [ -n "$CUSTOM_SETUP" ]; then
500
-    cp "$CUSTOM_SETUP" "$rootdir"/tmp
501
-    chroot "$rootdir" apt-get install -y gdebi-core
502
-    chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
507
+	cp "$CUSTOM_SETUP" "$rootdir"/tmp
508
+	chroot "$rootdir" apt-get install -y gdebi-core
509
+	chroot "$rootdir" gdebi -n /tmp/"$(basename $CUSTOM_SETUP)"
503 510
 fi
504 511
 
505 512
 chroot "$rootdir" apt-get install -y sudo git dialog toilet build-essential openssh-server
@@ -511,45 +518,45 @@ chroot "$rootdir" apt-get install -y locales locales-all debconf wireless-tools
511 518
 sed -i "s|#host-name=.*|host-name=${PROJECT_NAME}|g" $rootdir/etc/avahi/avahi-daemon.conf
512 519
 
513 520
 chroot "$rootdir" /bin/bash -x <<EOF
514
-git clone $PROJECT_REPO /root/$PROJECT_NAME
515
-cd /root/$PROJECT_NAME
516
-make install
517
-EOF
521
+	git clone $PROJECT_REPO /root/$PROJECT_NAME
522
+	cd /root/$PROJECT_NAME
523
+	make install
524
+	EOF
518 525
 
519 526
 chroot "$rootdir" ${PROJECT_NAME}-image-hardware-setup 2>&1 | \
520
-    tee $rootdir/var/log/${PROJECT_NAME}-image-hardware-setup.log
527
+	tee $rootdir/var/log/${PROJECT_NAME}-image-hardware-setup.log
521 528
 
522 529
 rm $rootdir/usr/sbin/policy-rc.d
523 530
 
524 531
 # Set up HRNG for systems known to have one
525 532
 # Otherwise install haveged
526 533
 if [[ "$MACHINE" != "beaglebone" ]]; then
527
-    chroot $rootdir apt-get -y install haveged
534
+	chroot $rootdir apt-get -y install haveged
528 535
 else
529
-    chroot $rootdir apt-get -y install rng-tools
530
-    sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
536
+	chroot $rootdir apt-get -y install rng-tools
537
+	sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' $rootdir/etc/default/rng-tools
531 538
 fi
532 539
 
533 540
 # copy u-boot to beginning of image
534 541
 case "$MACHINE" in
535
-    beaglebone)
536
-        dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
537
-           count=1 seek=1 conv=notrunc bs=128k
538
-        dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
539
-           count=2 seek=1 conv=notrunc bs=384k
540
-        ;;
541
-    cubieboard2)
542
-        dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
543
-           seek=8 conv=notrunc bs=1k
544
-        ;;
545
-    a20-olinuxino-lime)
546
-        dd if=$rootdir/usr/lib/u-boot/A20-OLinuXino-Lime/u-boot-sunxi-with-spl.bin \
547
-           of="$image" seek=8 conv=notrunc bs=1k
548
-        ;;
542
+	beaglebone)
543
+		dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/MLO of="$image" \
544
+		   count=1 seek=1 conv=notrunc bs=128k
545
+		dd if=$rootdir/usr/lib/u-boot/am335x_boneblack/u-boot.img of="$image" \
546
+		   count=2 seek=1 conv=notrunc bs=384k
547
+		;;
548
+	cubieboard2)
549
+		dd if=$rootdir/usr/lib/u-boot/Cubieboard2/u-boot-sunxi-with-spl.bin of="$image" \
550
+		   seek=8 conv=notrunc bs=1k
551
+		;;
552
+	a20-olinuxino-lime)
553
+		dd if=$rootdir/usr/lib/u-boot/A20-OLinuXino-Lime/u-boot-sunxi-with-spl.bin \
554
+		   of="$image" seek=8 conv=notrunc bs=1k
555
+		;;
549 556
 esac
550 557
 
551 558
 if $use_eatmydata ; then
552
-    disable_eatmydata_override
559
+	disable_eatmydata_override
553 560
 fi
554 561
 
555 562
 set_apt_sources $MIRROR

+ 2
- 0
src/freedombone-image-make ファイルの表示

@@ -61,6 +61,7 @@ export WIFI_SSID
61 61
 export WIFI_TYPE
62 62
 export WIFI_PASSPHRASE
63 63
 export WIFI_HOTSPOT
64
+export WIFI_NETWORKS_FILE
64 65
 
65 66
 # Locate vmdebootstrap program fetched in Makefile
66 67
 basedir=`pwd`
@@ -181,6 +182,7 @@ sudo sed -i "s|WIFI_SSID=.*|WIFI_SSID=\"${WIFI_SSID}\"|g" $TEMP_CUSTOMISE
181 182
 sudo sed -i "s|WIFI_TYPE=.*|WIFI_TYPE=\"${WIFI_TYPE}\"|g" $TEMP_CUSTOMISE
182 183
 sudo sed -i "s|WIFI_PASSPHRASE=.*|WIFI_PASSPHRASE=\"${WIFI_PASSPHRASE}\"|g" $TEMP_CUSTOMISE
183 184
 sudo sed -i "s|WIFI_HOTSPOT=.*|WIFI_HOTSPOT=\"${WIFI_HOTSPOT}\"|g" $TEMP_CUSTOMISE
185
+sudo sed -i "s|WIFI_NETWORKS_FILE=.*|WIFI_NETWORKS_FILE=\"${WIFI_NETWORKS_FILE}\"|g" $TEMP_CUSTOMISE
184 186
 
185 187
 echo $"starting $VMDEBOOTSTRAP"
186 188
 # Run vmdebootstrap script to create image

+ 265
- 265
src/freedombone-wifi ファイルの表示

@@ -42,314 +42,314 @@ WIFI_SSID=
42 42
 WIFI_PASSPHRASE=
43 43
 WIFI_HOTSPOT='no'
44 44
 WIFI_CONFIG=/etc/wpa_supplicant/wpa_supplicant.conf
45
-WIFI_FILE=/root/${PROJECT_NAME}-wifi.cfg
45
+WIFI_NETWORKS_FILE=/root/${PROJECT_NAME}-wifi.cfg
46 46
 
47 47
 function wifi_get_psk {
48
-	ssid=$1
49
-	passphrase=$2
48
+    ssid=$1
49
+    passphrase=$2
50 50
 
51
-	psk=$(wpa_passphrase "$ssid" "$passphrase" | grep 'psk=' | sed -n 2p | awk -F '=' '{print $2}')
52
-	echo $psk
51
+    psk=$(wpa_passphrase "$ssid" "$passphrase" | grep 'psk=' | sed -n 2p | awk -F '=' '{print $2}')
52
+    echo $psk
53 53
 }
54 54
 
55 55
 function hotspot_off {
56
-	if [ ! -f /etc/hostapd/hostapd.conf ]; then
57
-		return
58
-	fi
59
-	systemctl stop hostapd
60
-
61
-	rm /etc/hostapd/hostapd.conf
62
-
63
-	if [ -f /etc/network/interfaces_original ]; then
64
-		cp /etc/network/interfaces_original /etc/network/interfaces
65
-	else
66
-		echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
67
-		echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
68
-		echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
69
-	fi
70
-
71
-	systemctl restart network-manager
56
+    if [ ! -f /etc/hostapd/hostapd.conf ]; then
57
+        return
58
+    fi
59
+    systemctl stop hostapd
60
+
61
+    rm /etc/hostapd/hostapd.conf
62
+
63
+    if [ -f /etc/network/interfaces_original ]; then
64
+        cp /etc/network/interfaces_original /etc/network/interfaces
65
+    else
66
+        echo '# interfaces(5) file used by ifup(8) and ifdown(8)' > /etc/network/interfaces
67
+        echo '# Include files from /etc/network/interfaces.d:' >> /etc/network/interfaces
68
+        echo 'source-directory /etc/network/interfaces.d' >> /etc/network/interfaces
69
+    fi
70
+
71
+    systemctl restart network-manager
72 72
 }
73 73
 
74 74
 function hotspot_on {
75
-	if [ ! -f /etc/default/hostapd ]; then
76
-		echo $'/etc/default/hostapd was not found'
77
-		exit 67241
78
-	fi
79
-	if [ ${#WIFI_PASSPHRASE} -lt 8 ]; then
80
-		echo $'Wifi hotspot passphrase is too short'
81
-		exit 25719
82
-	fi
83
-
84
-	sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
85
-
86
-	echo '### Wireless network name ###' > /etc/hostapd/hostapd.conf
87
-	echo "interface=$WIFI_INTERFACE" >> /etc/hostapd/hostapd.conf
88
-	echo '' >> /etc/hostapd/hostapd.conf
89
-	echo '### Set your bridge name ###' >> /etc/hostapd/hostapd.conf
90
-	echo 'bridge=br0' >> /etc/hostapd/hostapd.conf
91
-	echo '' >> /etc/hostapd/hostapd.conf
92
-	echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
93
-	echo "country_code=UK" >> /etc/hostapd/hostapd.conf
94
-	echo "ssid=$WIFI_SSID" >> /etc/hostapd/hostapd.conf
95
-	echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
96
-	echo 'channel=6' >> /etc/hostapd/hostapd.conf
97
-	echo 'wpa=2' >> /etc/hostapd/hostapd.conf
98
-	echo "wpa_passphrase=$WIFI_PASSPHRASE" >> /etc/hostapd/hostapd.conf
99
-	echo '' >> /etc/hostapd/hostapd.conf
100
-	echo '## Key management algorithms ##' >> /etc/hostapd/hostapd.conf
101
-	echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
102
-	echo '' >> /etc/hostapd/hostapd.conf
103
-	echo '## Set cipher suites (encryption algorithms) ##' >> /etc/hostapd/hostapd.conf
104
-	echo '## TKIP = Temporal Key Integrity Protocol' >> /etc/hostapd/hostapd.conf
105
-	echo '## CCMP = AES in Counter mode with CBC-MAC' >> /etc/hostapd/hostapd.conf
106
-	echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
107
-	echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
108
-	echo '' >> /etc/hostapd/hostapd.conf
109
-	echo '## Shared Key Authentication ##'
110
-	echo 'auth_algs=1'
111
-	echo '' >> /etc/hostapd/hostapd.conf
112
-	echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
113
-	echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
114
-
115
-	if [ ! -f /etc/network/interfaces_original ]; then
116
-		if ! grep -q "# wifi enabled" /etc/network/interfaces; then
117
-			cp /etc/network/interfaces /etc/network/interfaces_original
118
-		fi
119
-	fi
120
-
121
-	echo '# wifi enabled' > /etc/network/interfaces
122
-	echo 'auto lo br0' >> /etc/network/interfaces
123
-	echo 'iface lo inet loopback' >> /etc/network/interfaces
124
-	echo '' >> /etc/network/interfaces
125
-	echo "# wireless $WIFI_INTERFACE" >> /etc/network/interfaces
126
-	echo "allow-hotplug $WIFI_INTERFACE" >> /etc/network/interfaces
127
-	echo "iface $WIFI_INTERFACE inet manual" >> /etc/network/interfaces
128
-	echo '' >> /etc/network/interfaces
129
-	echo '# eth0 connected to the ISP router' >> /etc/network/interfaces
130
-	echo 'allow-hotplug eth0' >> /etc/network/interfaces
131
-	echo 'iface eth0 inet manual' >> /etc/network/interfaces
132
-	echo '' >> /etc/network/interfaces
133
-	echo '# Setup bridge' >> /etc/network/interfaces
134
-	echo 'iface br0 inet static' >> /etc/network/interfaces
135
-	echo "    bridge_ports $WIFI_INTERFACE eth0" >> /etc/network/interfaces
136
-
137
-	systemctl restart network-manager
138
-	systemctl restart hostapd
75
+    if [ ! -f /etc/default/hostapd ]; then
76
+        echo $'/etc/default/hostapd was not found'
77
+        exit 67241
78
+    fi
79
+    if [ ${#WIFI_PASSPHRASE} -lt 8 ]; then
80
+        echo $'Wifi hotspot passphrase is too short'
81
+        exit 25719
82
+    fi
83
+
84
+    sed -i 's|#DAEMON_CONF=.*|DAEMON_CONF="/etc/hostapd/hostapd.conf"|g' /etc/default/hostapd
85
+
86
+    echo '### Wireless network name ###' > /etc/hostapd/hostapd.conf
87
+    echo "interface=$WIFI_INTERFACE" >> /etc/hostapd/hostapd.conf
88
+    echo '' >> /etc/hostapd/hostapd.conf
89
+    echo '### Set your bridge name ###' >> /etc/hostapd/hostapd.conf
90
+    echo 'bridge=br0' >> /etc/hostapd/hostapd.conf
91
+    echo '' >> /etc/hostapd/hostapd.conf
92
+    echo 'driver=nl80211' >> /etc/hostapd/hostapd.conf
93
+    echo "country_code=UK" >> /etc/hostapd/hostapd.conf
94
+    echo "ssid=$WIFI_SSID" >> /etc/hostapd/hostapd.conf
95
+    echo 'hw_mode=g' >> /etc/hostapd/hostapd.conf
96
+    echo 'channel=6' >> /etc/hostapd/hostapd.conf
97
+    echo 'wpa=2' >> /etc/hostapd/hostapd.conf
98
+    echo "wpa_passphrase=$WIFI_PASSPHRASE" >> /etc/hostapd/hostapd.conf
99
+    echo '' >> /etc/hostapd/hostapd.conf
100
+    echo '## Key management algorithms ##' >> /etc/hostapd/hostapd.conf
101
+    echo 'wpa_key_mgmt=WPA-PSK' >> /etc/hostapd/hostapd.conf
102
+    echo '' >> /etc/hostapd/hostapd.conf
103
+    echo '## Set cipher suites (encryption algorithms) ##' >> /etc/hostapd/hostapd.conf
104
+    echo '## TKIP = Temporal Key Integrity Protocol' >> /etc/hostapd/hostapd.conf
105
+    echo '## CCMP = AES in Counter mode with CBC-MAC' >> /etc/hostapd/hostapd.conf
106
+    echo 'wpa_pairwise=TKIP' >> /etc/hostapd/hostapd.conf
107
+    echo 'rsn_pairwise=CCMP' >> /etc/hostapd/hostapd.conf
108
+    echo '' >> /etc/hostapd/hostapd.conf
109
+    echo '## Shared Key Authentication ##'
110
+    echo 'auth_algs=1'
111
+    echo '' >> /etc/hostapd/hostapd.conf
112
+    echo '## Accept all MAC address ###' >> /etc/hostapd/hostapd.conf
113
+    echo 'macaddr_acl=0' >> /etc/hostapd/hostapd.conf
114
+
115
+    if [ ! -f /etc/network/interfaces_original ]; then
116
+        if ! grep -q "# wifi enabled" /etc/network/interfaces; then
117
+            cp /etc/network/interfaces /etc/network/interfaces_original
118
+        fi
119
+    fi
120
+
121
+    echo '# wifi enabled' > /etc/network/interfaces
122
+    echo 'auto lo br0' >> /etc/network/interfaces
123
+    echo 'iface lo inet loopback' >> /etc/network/interfaces
124
+    echo '' >> /etc/network/interfaces
125
+    echo "# wireless $WIFI_INTERFACE" >> /etc/network/interfaces
126
+    echo "allow-hotplug $WIFI_INTERFACE" >> /etc/network/interfaces
127
+    echo "iface $WIFI_INTERFACE inet manual" >> /etc/network/interfaces
128
+    echo '' >> /etc/network/interfaces
129
+    echo '# eth0 connected to the ISP router' >> /etc/network/interfaces
130
+    echo 'allow-hotplug eth0' >> /etc/network/interfaces
131
+    echo 'iface eth0 inet manual' >> /etc/network/interfaces
132
+    echo '' >> /etc/network/interfaces
133
+    echo '# Setup bridge' >> /etc/network/interfaces
134
+    echo 'iface br0 inet static' >> /etc/network/interfaces
135
+    echo "    bridge_ports $WIFI_INTERFACE eth0" >> /etc/network/interfaces
136
+
137
+    systemctl restart network-manager
138
+    systemctl restart hostapd
139 139
 }
140 140
 
141 141
 function wifi_wpa2_psk {
142
-	ssid=$1
143
-	passphrase=$2
144
-
145
-	if [ ! -f /etc/network/interfaces_original ]; then
146
-		if ! grep -q "# wifi enabled" /etc/network/interfaces; then
147
-			cp /etc/network/interfaces /etc/network/interfaces_original
148
-		fi
149
-	fi
150
-
151
-	echo '# wifi enabled' > /etc/network/interfaces
152
-	echo 'auto lo' >> /etc/network/interfaces
153
-	echo 'iface lo inet loopback' >> /etc/network/interfaces
154
-	echo '' >> /etc/network/interfaces
155
-	echo 'allow-hotplug eth0' >> /etc/network/interfaces
156
-	echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
157
-	echo '' >> /etc/network/interfaces
158
-	echo 'allow-hotplug wlan0' >> /etc/network/interfaces
159
-	echo 'iface wlan0 inet manual' >> /etc/network/interfaces
160
-	echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
161
-	echo '' >> /etc/network/interfaces
162
-	echo 'iface default inet dhcp' >> /etc/network/interfaces
163
-
164
-	wpa_passphrase "$ssid" "$passphrase" > $WIFI_CONFIG
165
-
166
-	systemctl restart network-manager
142
+    ssid=$1
143
+    passphrase=$2
144
+
145
+    if [ ! -f /etc/network/interfaces_original ]; then
146
+        if ! grep -q "# wifi enabled" /etc/network/interfaces; then
147
+            cp /etc/network/interfaces /etc/network/interfaces_original
148
+        fi
149
+    fi
150
+
151
+    echo '# wifi enabled' > /etc/network/interfaces
152
+    echo 'auto lo' >> /etc/network/interfaces
153
+    echo 'iface lo inet loopback' >> /etc/network/interfaces
154
+    echo '' >> /etc/network/interfaces
155
+    echo 'allow-hotplug eth0' >> /etc/network/interfaces
156
+    echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
157
+    echo '' >> /etc/network/interfaces
158
+    echo 'allow-hotplug wlan0' >> /etc/network/interfaces
159
+    echo 'iface wlan0 inet manual' >> /etc/network/interfaces
160
+    echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
161
+    echo '' >> /etc/network/interfaces
162
+    echo 'iface default inet dhcp' >> /etc/network/interfaces
163
+
164
+    wpa_passphrase "$ssid" "$passphrase" > $WIFI_CONFIG
165
+
166
+    systemctl restart network-manager
167 167
 }
168 168
 
169 169
 function wifi_none {
170
-	ssid=$1
171
-
172
-	if [ ! -f /etc/network/interfaces_original ]; then
173
-		if ! grep -q "# wifi enabled" /etc/network/interfaces; then
174
-			cp /etc/network/interfaces /etc/network/interfaces_original
175
-		fi
176
-	fi
177
-
178
-	echo '# wifi enabled' > /etc/network/interfaces
179
-	echo 'auto lo' >> /etc/network/interfaces
180
-	echo 'iface lo inet loopback' >> /etc/network/interfaces
181
-	echo '' >> /etc/network/interfaces
182
-	echo 'allow-hotplug eth0' >> /etc/network/interfaces
183
-	echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
184
-	echo '' >> /etc/network/interfaces
185
-	echo 'allow-hotplug wlan0' >> /etc/network/interfaces
186
-	echo 'iface wlan0 inet manual' >> /etc/network/interfaces
187
-	echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
188
-	echo '' >> /etc/network/interfaces
189
-	echo 'iface default inet dhcp' >> /etc/network/interfaces
190
-
191
-	echo 'network={' > $WIFI_CONFIG
192
-	echo "  ssid=\"${ssid}\"" >> $WIFI_CONFIG
193
-	echo '  key_mgmt=NONE' >> $WIFI_CONFIG
194
-	echo '}' >> $WIFI_CONFIG
195
-
196
-	systemctl restart network-manager
170
+    ssid=$1
171
+
172
+    if [ ! -f /etc/network/interfaces_original ]; then
173
+        if ! grep -q "# wifi enabled" /etc/network/interfaces; then
174
+            cp /etc/network/interfaces /etc/network/interfaces_original
175
+        fi
176
+    fi
177
+
178
+    echo '# wifi enabled' > /etc/network/interfaces
179
+    echo 'auto lo' >> /etc/network/interfaces
180
+    echo 'iface lo inet loopback' >> /etc/network/interfaces
181
+    echo '' >> /etc/network/interfaces
182
+    echo 'allow-hotplug eth0' >> /etc/network/interfaces
183
+    echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
184
+    echo '' >> /etc/network/interfaces
185
+    echo 'allow-hotplug wlan0' >> /etc/network/interfaces
186
+    echo 'iface wlan0 inet manual' >> /etc/network/interfaces
187
+    echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
188
+    echo '' >> /etc/network/interfaces
189
+    echo 'iface default inet dhcp' >> /etc/network/interfaces
190
+
191
+    echo 'network={' > $WIFI_CONFIG
192
+    echo "  ssid=\"${ssid}\"" >> $WIFI_CONFIG
193
+    echo '  key_mgmt=NONE' >> $WIFI_CONFIG
194
+    echo '}' >> $WIFI_CONFIG
195
+
196
+    systemctl restart network-manager
197 197
 }
198 198
 
199 199
 function create_networks_from_file {
200
-	if [ ! -f $WIFI_FILE ]; then
201
-		return
202
-	fi
203
-
204
-	if [ ! -f /etc/network/interfaces_original ]; then
205
-		if ! grep -q "# wifi enabled" /etc/network/interfaces; then
206
-			cp /etc/network/interfaces /etc/network/interfaces_original
207
-		fi
208
-	fi
209
-
210
-	echo '# wifi enabled' > /etc/network/interfaces
211
-	echo 'auto lo' >> /etc/network/interfaces
212
-	echo 'iface lo inet loopback' >> /etc/network/interfaces
213
-	echo '' >> /etc/network/interfaces
214
-	echo 'allow-hotplug eth0' >> /etc/network/interfaces
215
-	echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
216
-	echo '' >> /etc/network/interfaces
217
-	echo 'allow-hotplug wlan0' >> /etc/network/interfaces
218
-	echo 'iface wlan0 inet manual' >> /etc/network/interfaces
219
-	echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
220
-	echo '' >> /etc/network/interfaces
221
-	echo 'iface default inet dhcp' >> /etc/network/interfaces
222
-
223
-	# remove wpa_supplicant.conf if it exists
224
-	if [ -f $WIFI_CONFIG ]; then
225
-		rm -f $WIFI_CONFIG
226
-	fi
227
-
228
-	ctr=0
229
-	while read -r line
230
-	do
231
-		if [ ${#line} -gt 1 ]; then
232
-			if [[ "$line" != '#'* ]]; then
233
-				if [ $ctr -eq 0 ]; then
234
-					WIFI_SSID="$line"
235
-				fi
236
-				if [ $ctr -eq 1 ]; then
237
-					WIFI_TYPE="$line"
238
-					if [[ $WIFI_TYPE == $'none' || $WIFI_TYPE == $'None' ]]; then
239
-						echo 'network={' >> $WIFI_CONFIG
240
-						echo "  ssid=\"${WIFI_SSID}\"" >> $WIFI_CONFIG
241
-						echo '  key_mgmt=NONE' >> $WIFI_CONFIG
242
-						echo '}' >> $WIFI_CONFIG
243
-						ctr=0
244
-						continue
245
-					fi
246
-				fi
247
-				if [ $ctr -eq 2 ]; then
248
-					WIFI_PASSPHRASE="$line"
249
-					wpa_passphrase "$WIFI_SSID" "$WIFI_PASSPHRASE" >> $WIFI_CONFIG
250
-					ctr=0
251
-					continue
252
-				fi
253
-
254
-				ctr=$((ctr + 1))
255
-			fi
256
-		fi
257
-	done < $WIFI_FILE
258
-
259
-	systemctl restart network-manager
200
+    if [ ! -f $WIFI_NETWORKS_FILE ]; then
201
+        exit 4
202
+    fi
203
+
204
+    if [ ! -f /etc/network/interfaces_original ]; then
205
+        if ! grep -q "# wifi enabled" /etc/network/interfaces; then
206
+            cp /etc/network/interfaces /etc/network/interfaces_original
207
+        fi
208
+    fi
209
+
210
+    echo '# wifi enabled' > /etc/network/interfaces
211
+    echo 'auto lo' >> /etc/network/interfaces
212
+    echo 'iface lo inet loopback' >> /etc/network/interfaces
213
+    echo '' >> /etc/network/interfaces
214
+    echo 'allow-hotplug eth0' >> /etc/network/interfaces
215
+    echo 'iface eth0 inet dhcp' >> /etc/network/interfaces
216
+    echo '' >> /etc/network/interfaces
217
+    echo 'allow-hotplug wlan0' >> /etc/network/interfaces
218
+    echo 'iface wlan0 inet manual' >> /etc/network/interfaces
219
+    echo "  wpa-roam $WIFI_CONFIG" >> /etc/network/interfaces
220
+    echo '' >> /etc/network/interfaces
221
+    echo 'iface default inet dhcp' >> /etc/network/interfaces
222
+
223
+    # remove wpa_supplicant.conf if it exists
224
+    if [ -f $WIFI_CONFIG ]; then
225
+        rm -f $WIFI_CONFIG
226
+    fi
227
+
228
+    ctr=0
229
+    while read -r line
230
+    do
231
+        if [ ${#line} -gt 1 ]; then
232
+            if [[ "$line" != '#'* ]]; then
233
+                if [ $ctr -eq 0 ]; then
234
+                    WIFI_SSID="$line"
235
+                fi
236
+                if [ $ctr -eq 1 ]; then
237
+                    WIFI_TYPE="$line"
238
+                    if [[ $WIFI_TYPE == $'none' || $WIFI_TYPE == $'None' ]]; then
239
+                        echo 'network={' >> $WIFI_CONFIG
240
+                        echo "  ssid=\"${WIFI_SSID}\"" >> $WIFI_CONFIG
241
+                        echo '  key_mgmt=NONE' >> $WIFI_CONFIG
242
+                        echo '}' >> $WIFI_CONFIG
243
+                        ctr=0
244
+                        continue
245
+                    fi
246
+                fi
247
+                if [ $ctr -eq 2 ]; then
248
+                    WIFI_PASSPHRASE="$line"
249
+                    wpa_passphrase "$WIFI_SSID" "$WIFI_PASSPHRASE" >> $WIFI_CONFIG
250
+                    ctr=0
251
+                    continue
252
+                fi
253
+
254
+                ctr=$((ctr + 1))
255
+            fi
256
+        fi
257
+    done < $WIFI_NETWORKS_FILE
258
+
259
+    systemctl restart network-manager
260 260
 }
261 261
 
262 262
 function show_help {
263
-	echo ''
264
-	echo $"${PROJECT_NAME}-wifi -i [interface] -t [type] -s [ssid] -p [passphrase]"
265
-	echo ''
266
-	echo $'Wifi configuration tool'
267
-	echo ''
268
-	echo $'     --help                        Show help'
269
-	echo $'  -i --interface [wlan0|wlan1...]  Device name'
270
-	echo $'  -t --type [wpa2-psk|none]        Security type'
271
-	echo $'  -s --ssid [id]                   Set SSID'
272
-	echo $'  -p --passphrase [text]           Set passphrase'
273
-	echo $'     --hotspot [yes|no]            Create a hotspot'
274
-	echo ''
275
-	exit 0
263
+    echo ''
264
+    echo $"${PROJECT_NAME}-wifi -i [interface] -t [type] -s [ssid] -p [passphrase]"
265
+    echo ''
266
+    echo $'Wifi configuration tool'
267
+    echo ''
268
+    echo $'     --help                        Show help'
269
+    echo $'  -i --interface [wlan0|wlan1...]  Device name'
270
+    echo $'  -t --type [wpa2-psk|none]        Security type'
271
+    echo $'  -s --ssid [id]                   Set SSID'
272
+    echo $'  -p --passphrase [text]           Set passphrase'
273
+    echo $'     --hotspot [yes|no]            Create a hotspot'
274
+    echo ''
275
+    exit 0
276 276
 }
277 277
 
278 278
 while [[ $# > 1 ]]
279 279
 do
280
-	key="$1"
281
-
282
-	case $key in
283
-		--help)
284
-			show_help
285
-			;;
286
-		-i|--if|--interface)
287
-			shift
288
-			WIFI_INTERFACE=${1}
289
-			;;
290
-		-t|--type)
291
-			shift
292
-			WIFI_TYPE=${1}
293
-			;;
294
-		-s|--ssid)
295
-			shift
296
-			WIFI_SSID=${1}
297
-			;;
298
-		-p|--pass|--passphrase)
299
-			shift
300
-			WIFI_PASSPHRASE=${1}
301
-			;;
302
-		--hostpot)
303
-			shift
304
-			WIFI_HOTSPOT=${1}
305
-			;;
306
-		--config)
307
-			shift
308
-			WIFI_FILE=${1}
309
-			;;
310
-		*)
311
-			# unknown option
312
-			;;
313
-	esac
314
-	shift
280
+    key="$1"
281
+
282
+    case $key in
283
+        --help)
284
+            show_help
285
+            ;;
286
+        -i|--if|--interface)
287
+            shift
288
+            WIFI_INTERFACE=${1}
289
+            ;;
290
+        -t|--type)
291
+            shift
292
+            WIFI_TYPE=${1}
293
+            ;;
294
+        -s|--ssid)
295
+            shift
296
+            WIFI_SSID=${1}
297
+            ;;
298
+        -p|--pass|--passphrase)
299
+            shift
300
+            WIFI_PASSPHRASE=${1}
301
+            ;;
302
+        --hostpot)
303
+            shift
304
+            WIFI_HOTSPOT=${1}
305
+            ;;
306
+        --networks)
307
+            shift
308
+            WIFI_NETWORKS_FILE=${1}
309
+            ;;
310
+        *)
311
+            # unknown option
312
+            ;;
313
+    esac
314
+    shift
315 315
 done
316 316
 
317
-if [ -f $WIFI_FILE ]; then
318
-	create_networks_from_file
319
-	exit 0
317
+if [ -f $WIFI_NETWORKS_FILE ]; then
318
+    create_networks_from_file
319
+    exit 0
320 320
 fi
321 321
 
322 322
 if [ ! $WIFI_SSID ]; then
323
-	echo $'No SSID given'
324
-	exit 1
323
+    echo $'No SSID given'
324
+    exit 1
325 325
 fi
326 326
 
327 327
 if [[ $WIFI_HOTSPOT != 'no' ]]; then
328
-	hotspot_on
329
-	exit 0
328
+    hotspot_on
329
+    exit 0
330 330
 else
331
-	hotspot_off
331
+    hotspot_off
332 332
 fi
333 333
 
334 334
 if [[ $WIFI_TYPE != 'none' ]]; then
335
-	if [ ! $WIFI_PASSPHRASE ]; then
336
-		echo $'No wifi passphrase was given'
337
-		exit 2
338
-	fi
335
+    if [ ! $WIFI_PASSPHRASE ]; then
336
+        echo $'No wifi passphrase was given'
337
+        exit 2
338
+    fi
339 339
 fi
340 340
 
341 341
 if [[ $WIFI_TYPE == 'wpa2-psk' ]]; then
342
-	if [ ! -d /etc/wpa_supplicant ]; then
343
-		echo $'wpasupplicant package is not installed'
344
-		exit 3
345
-	fi
346
-	wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE"
347
-	exit 0
342
+    if [ ! -d /etc/wpa_supplicant ]; then
343
+        echo $'wpasupplicant package is not installed'
344
+        exit 3
345
+    fi
346
+    wifi_wpa2_psk "$WIFI_SSID" "$WIFI_PASSPHRASE"
347
+    exit 0
348 348
 fi
349 349
 
350 350
 if [[ $WIFI_TYPE == 'none' ]]; then
351
-	wifi_none "$WIFI_SSID"
352
-	exit 0
351
+    wifi_none "$WIFI_SSID"
352
+    exit 0
353 353
 fi
354 354
 
355 355
 exit 0