Kaynağa Gözat

Can configure wifi from image builder

Bob Mottram 9 yıl önce
ebeveyn
işleme
ddc7f1a7bb
No account linked to committer's email
3 değiştirilmiş dosya ile 152 ekleme ve 85 silme
  1. 119
    85
      src/freedombone-image
  2. 23
    0
      src/freedombone-image-customise
  3. 10
    0
      src/freedombone-image-make

+ 119
- 85
src/freedombone-image Dosyayı Görüntüle

100
 # Whether to only install debian but nothing else
100
 # Whether to only install debian but nothing else
101
 DEBIAN_INSTALL_ONLY='no'
101
 DEBIAN_INSTALL_ONLY='no'
102
 
102
 
103
+# wifi settings
104
+WIFI_INTERFACE='wlan0'
105
+WIFI_SSID=
106
+WIFI_TYPE='wpa-psk'
107
+WIFI_PASSPHRASE=
108
+WIFI_HOTSPOT='no'
109
+
103
 mesh_router_setup_script() {
110
 mesh_router_setup_script() {
104
     # create a setup script for a mesh router
111
     # create a setup script for a mesh router
105
     mesh_script_filename=$1
112
     mesh_script_filename=$1
220
             shift
227
             shift
221
             DEBIAN_INSTALL_ONLY="$1"
228
             DEBIAN_INSTALL_ONLY="$1"
222
             ;;
229
             ;;
223
-        *)
224
-            # unknown option
225
-            ;;
226
-    esac
227
-    shift
230
+        --interface|--if)
231
+			shift
232
+			WIFI_INTERFACE="$1"
233
+			;;
234
+        --ssid|--essid)
235
+			shift
236
+			WIFI_SSID="$1"
237
+			;;
238
+        --wifitype)
239
+			shift
240
+			WIFI_TYPE="$1"
241
+			;;
242
+        --wifipass|--passphrase)
243
+			shift
244
+			WIFI_PASSPHRASE="$1"
245
+			;;
246
+        --hotspot)
247
+			shift
248
+			if [[ $"$1" == $'yes' || $"$1" == $'y' ]]; then
249
+				WIFI_HOTSPOT='yes'
250
+			fi			
251
+			;;
252
+		*)
253
+			# unknown option
254
+			;;
255
+	esac
256
+	shift
228
 done
257
 done
229
 
258
 
230
 if [[ $INTERACTIVE == "yes" || $INTERACTIVE == "y" || $INTERACTIVE == "Yes" ]]; then
259
 if [[ $INTERACTIVE == "yes" || $INTERACTIVE == "y" || $INTERACTIVE == "Yes" ]]; then
231
-    ${PROJECT_NAME}-config --minimal "$MINIMAL_INSTALL"
232
-    if [ -f freedombone.cfg ]; then
233
-        CONFIG_FILENAME=freedombone.cfg
234
-        DEFAULT_DOMAIN_NAME=$(cat $CONFIG_FILENAME | grep 'DEFAULT_DOMAIN_NAME' | awk -F '=' '{print $2}')
235
-    fi
260
+	${PROJECT_NAME}-config --minimal "$MINIMAL_INSTALL"
261
+	if [ -f freedombone.cfg ]; then
262
+		CONFIG_FILENAME=freedombone.cfg
263
+		DEFAULT_DOMAIN_NAME=$(cat $CONFIG_FILENAME | grep 'DEFAULT_DOMAIN_NAME' | awk -F '=' '{print $2}')
264
+	fi
236
 fi
265
 fi
237
 
266
 
238
 if [[ $GENERIC_IMAGE == "yes" ]]; then
267
 if [[ $GENERIC_IMAGE == "yes" ]]; then
239
-    USERNAME=$GENERIC_IMAGE_USERNAME
240
-    PASSWORD=$GENERIC_IMAGE_PASSWORD
268
+	USERNAME=$GENERIC_IMAGE_USERNAME
269
+	PASSWORD=$GENERIC_IMAGE_PASSWORD
241
 fi
270
 fi
242
 
271
 
243
 # If this is a mesh variant then create an appropriate script
272
 # If this is a mesh variant then create an appropriate script
248
 #fi
277
 #fi
249
 
278
 
250
 if [ ! $PASSWORD ]; then
279
 if [ ! $PASSWORD ]; then
251
-    # generate a random password
252
-    PASSWORD="$(openssl rand -base64 10 | cut -c1-8)"
280
+	# generate a random password
281
+	PASSWORD="$(openssl rand -base64 10 | cut -c1-8)"
253
 fi
282
 fi
254
 
283
 
255
 # Move any existing images into a build subdirectory
284
 # Move any existing images into a build subdirectory
256
 image_types=( xz img sig vdi qcow2 )
285
 image_types=( xz img sig vdi qcow2 )
257
 for im in "${image_types[@]}"
286
 for im in "${image_types[@]}"
258
 do
287
 do
259
-    no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
260
-    if (( no_of_files > 0 )); then
261
-        if [ ! -d ${CURR_DIR}/build ]; then
262
-            mkdir ${CURR_DIR}/build
263
-        fi
264
-        mv -f ${CURR_DIR}/${PROJECT_NAME}*.${im} ${CURR_DIR}/build
265
-    fi
288
+	no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
289
+	if (( no_of_files > 0 )); then
290
+		if [ ! -d ${CURR_DIR}/build ]; then
291
+			mkdir ${CURR_DIR}/build
292
+		fi
293
+		mv -f ${CURR_DIR}/${PROJECT_NAME}*.${im} ${CURR_DIR}/build
294
+	fi
266
 done
295
 done
267
 
296
 
268
 # Delete anything which didn't move
297
 # Delete anything which didn't move
269
 for im in "${image_types[@]}"
298
 for im in "${image_types[@]}"
270
 do
299
 do
271
-    no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
272
-    if (( no_of_files > 0 )); then
273
-        rm -f ${CURR_DIR}/${PROJECT_NAME}*.${im}
274
-    fi
300
+	no_of_files=$(ls -afq ${CURR_DIR}/${PROJECT_NAME}*.${im} | wc -l)
301
+	if (( no_of_files > 0 )); then
302
+		rm -f ${CURR_DIR}/${PROJECT_NAME}*.${im}
303
+	fi
275
 done
304
 done
276
 
305
 
277
 # Remove any existing login credentials file
306
 # Remove any existing login credentials file
278
 if [ -f ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt ]; then
307
 if [ -f ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt ]; then
279
-    rm ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt
308
+	rm ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt
280
 fi
309
 fi
281
 
310
 
282
 if [ -d $TEMPBUILD_DIR ]; then
311
 if [ -d $TEMPBUILD_DIR ]; then
283
-    rm -rf $TEMPBUILD_DIR
312
+	rm -rf $TEMPBUILD_DIR
284
 fi
313
 fi
285
 mkdir -p $TEMPBUILD_DIR
314
 mkdir -p $TEMPBUILD_DIR
286
 if [ -f /usr/local/bin/$MAKEFILE ]; then
315
 if [ -f /usr/local/bin/$MAKEFILE ]; then
287
-    cp /usr/local/bin/$MAKEFILE $TEMPBUILD_DIR/Makefile
316
+	cp /usr/local/bin/$MAKEFILE $TEMPBUILD_DIR/Makefile
288
 else
317
 else
289
-    cp /usr/bin/$MAKEFILE $TEMPBUILD_DIR/Makefile
318
+	cp /usr/bin/$MAKEFILE $TEMPBUILD_DIR/Makefile
290
 fi
319
 fi
291
 
320
 
292
 cp -r /etc/${PROJECT_NAME}/* $TEMPBUILD_DIR
321
 cp -r /etc/${PROJECT_NAME}/* $TEMPBUILD_DIR
295
 cd $TEMPBUILD_DIR
324
 cd $TEMPBUILD_DIR
296
 
325
 
297
 if [[ $MINIMAL_INSTALL == "yes" ]]; then
326
 if [[ $MINIMAL_INSTALL == "yes" ]]; then
298
-    IMAGE_NAME='min'
327
+	IMAGE_NAME='min'
299
 fi
328
 fi
300
 
329
 
301
 if [[ $ONION_ONLY != "no" ]]; then
330
 if [[ $ONION_ONLY != "no" ]]; then
302
-    IMAGE_NAME='onion'
331
+	IMAGE_NAME='onion'
303
 fi
332
 fi
304
 
333
 
305
 cd $TEMPBUILD_DIR
334
 cd $TEMPBUILD_DIR
306
 make $IMAGE_TYPE \
335
 make $IMAGE_TYPE \
307
-     USERNAME="$USERNAME" \
308
-     PASSWORD="$PASSWORD" \
309
-     ROUTER_IP_ADDRESS="$ROUTER_IP_ADDRESS" \
310
-     BOX_IP_ADDRESS="$BOX_IP_ADDRESS" \
311
-     NAMESERVER1="$NAMESERVER1" \
312
-     NAMESERVER2="$NAMESERVER2" \
313
-     PROJECT_NAME="$PROJECT_NAME" \
314
-     CONFIG_FILENAME="$CONFIG_FILENAME" \
315
-     IMAGE_SIZE="$IMAGE_SIZE" \
316
-     SSH_PUBKEY="$SSH_PUBKEY" \
317
-     GENERIC_IMAGE="$GENERIC_IMAGE" \
318
-     MINIMAL_INSTALL="$MINIMAL_INSTALL" \
319
-     SSH_PORT="$SSH_PORT" \
320
-     ONION_ONLY="$ONION_ONLY" \
321
-     IMAGE_NAME="$IMAGE_NAME" \
322
-     PROJECT_REPO="$PROJECT_REPO" \
323
-     MIRROR="$MIRROR" \
324
-     BUILD_MIRROR="$MIRROR" \
325
-     DEBIAN_INSTALL_ONLY="$DEBIAN_INSTALL_ONLY"
326
-
336
+	 USERNAME="$USERNAME" \
337
+	 PASSWORD="$PASSWORD" \
338
+	 ROUTER_IP_ADDRESS="$ROUTER_IP_ADDRESS" \
339
+	 BOX_IP_ADDRESS="$BOX_IP_ADDRESS" \
340
+	 NAMESERVER1="$NAMESERVER1" \
341
+	 NAMESERVER2="$NAMESERVER2" \
342
+	 PROJECT_NAME="$PROJECT_NAME" \
343
+	 CONFIG_FILENAME="$CONFIG_FILENAME" \
344
+	 IMAGE_SIZE="$IMAGE_SIZE" \
345
+	 SSH_PUBKEY="$SSH_PUBKEY" \
346
+	 GENERIC_IMAGE="$GENERIC_IMAGE" \
347
+	 MINIMAL_INSTALL="$MINIMAL_INSTALL" \
348
+	 SSH_PORT="$SSH_PORT" \
349
+	 ONION_ONLY="$ONION_ONLY" \
350
+	 IMAGE_NAME="$IMAGE_NAME" \
351
+	 PROJECT_REPO="$PROJECT_REPO" \
352
+	 MIRROR="$MIRROR" \
353
+	 BUILD_MIRROR="$MIRROR" \
354
+	 DEBIAN_INSTALL_ONLY="$DEBIAN_INSTALL_ONLY" \
355
+	 WIFI_INTERFACE="$WIFI_INTERFACE" \
356
+	 WIFI_SSID="$WIFI_SSID" \
357
+	 WIFI_TYPE="$WIFI_TYPE" \
358
+	 WIFI_PASSPHRASE="$WIFI_PASSPHRASE" \
359
+	 WIFI_HOTSPOT="$WIFI_HOTSPOT"
360
+	 
327
 if [ ! "$?" = "0" ]; then
361
 if [ ! "$?" = "0" ]; then
328
-    echo $'Build failed'
329
-    rm -rf $TEMPBUILD_DIR
330
-    exit 1
362
+	echo $'Build failed'
363
+	rm -rf $TEMPBUILD_DIR
364
+	exit 1
331
 fi
365
 fi
332
 
366
 
333
 EXPECTED_EXTENSION='xz'
367
 EXPECTED_EXTENSION='xz'
334
 if [[ $IMAGE_TYPE == "qemu"* ]]; then
368
 if [[ $IMAGE_TYPE == "qemu"* ]]; then
335
-    EXPECTED_EXTENSION='qcow2'
369
+	EXPECTED_EXTENSION='qcow2'
336
 fi
370
 fi
337
 if [[ $IMAGE_TYPE == "virtualbox"* ]]; then
371
 if [[ $IMAGE_TYPE == "virtualbox"* ]]; then
338
-    EXPECTED_EXTENSION='vdi'
372
+	EXPECTED_EXTENSION='vdi'
339
 fi
373
 fi
340
 
374
 
341
 shopt -s nullglob
375
 shopt -s nullglob
342
 imgfiles=(build/${PROJECT_NAME}*.${EXPECTED_EXTENSION})
376
 imgfiles=(build/${PROJECT_NAME}*.${EXPECTED_EXTENSION})
343
 if [ ${#imgfiles[@]} -eq 0 ]; then
377
 if [ ${#imgfiles[@]} -eq 0 ]; then
344
-    echo $'Image was not created'
345
-    rm -rf $TEMPBUILD_DIR
346
-    exit 2
378
+	echo $'Image was not created'
379
+	rm -rf $TEMPBUILD_DIR
380
+	exit 2
347
 fi
381
 fi
348
 
382
 
349
 # Move images from temporary directory to the current directory
383
 # Move images from temporary directory to the current directory
350
 for im in "${image_types[@]}"
384
 for im in "${image_types[@]}"
351
 do
385
 do
352
-    no_of_files=$(ls -afq build/${PROJECT_NAME}*.${im} | wc -l)
353
-    if (( no_of_files > 0 )); then
354
-        mv build/${PROJECT_NAME}*.${im} ${CURR_DIR}/
355
-    fi
386
+	no_of_files=$(ls -afq build/${PROJECT_NAME}*.${im} | wc -l)
387
+	if (( no_of_files > 0 )); then
388
+		mv build/${PROJECT_NAME}*.${im} ${CURR_DIR}/
389
+	fi
356
 done
390
 done
357
 
391
 
358
 # Remove the temporary directory
392
 # Remove the temporary directory
367
 You will be able to log into it with:
401
 You will be able to log into it with:
368
 "
402
 "
369
 if [[ $IMAGE_TYPE != "virtualbox"* && $IMAGE_TYPE != "qemu"* ]]; then
403
 if [[ $IMAGE_TYPE != "virtualbox"* && $IMAGE_TYPE != "qemu"* ]]; then
370
-    echo $"    ssh $USERNAME@$DEFAULT_DOMAIN_NAME -p $SSH_PORT
404
+	echo $"    ssh $USERNAME@$DEFAULT_DOMAIN_NAME -p $SSH_PORT
371
 
405
 
372
-    Password: $PASSWORD
406
+Password: $PASSWORD
373
 "
407
 "
374
 else
408
 else
375
-    if [[ $IMAGE_TYPE != "qemu"* ]]; then
376
-        echo $"    Username: $USERNAME
377
-    Password: $PASSWORD
409
+	if [[ $IMAGE_TYPE != "qemu"* ]]; then
410
+		echo $"    Username: $USERNAME
411
+Password: $PASSWORD
378
 "
412
 "
379
-    else
380
-        if [[ $IMAGE_TYPE != "qemu-x86_64"* && $IMAGE_TYPE != "qemu-amd64"* ]]; then
381
-            echo "qemu-system-i386 -m ${VM_MEMORY} $(ls ${PROJECT_NAME}*.qcow2)"
382
-        else
383
-            echo "qemu-system-x86_64 -m ${VM_MEMORY} $(ls ${PROJECT_NAME}*.qcow2)"
384
-        fi
385
-        echo $"
386
-    Username: $USERNAME
387
-    Password: $PASSWORD
413
+	else
414
+		if [[ $IMAGE_TYPE != "qemu-x86_64"* && $IMAGE_TYPE != "qemu-amd64"* ]]; then
415
+			echo "qemu-system-i386 -m ${VM_MEMORY} $(ls ${PROJECT_NAME}*.qcow2)"
416
+		else
417
+			echo "qemu-system-x86_64 -m ${VM_MEMORY} $(ls ${PROJECT_NAME}*.qcow2)"
418
+		fi
419
+		echo $"
420
+Username: $USERNAME
421
+Password: $PASSWORD
388
 "
422
 "
389
-    fi
423
+	fi
390
 fi
424
 fi
391
 ls -lh ${PROJECT_NAME}*.img ${PROJECT_NAME}*.sig ${PROJECT_NAME}*.xz ${PROJECT_NAME}*.vdi ${PROJECT_NAME}*.qcow2
425
 ls -lh ${PROJECT_NAME}*.img ${PROJECT_NAME}*.sig ${PROJECT_NAME}*.xz ${PROJECT_NAME}*.vdi ${PROJECT_NAME}*.qcow2
392
 
426
 
393
 # Remove the mesh script after use
427
 # Remove the mesh script after use
394
 if [[ $VARIANT == "mesh"* ]]; then
428
 if [[ $VARIANT == "mesh"* ]]; then
395
-    rm -f $CONFIG_FILENAME
429
+	rm -f $CONFIG_FILENAME
396
 fi
430
 fi
397
 
431
 
398
 # record the default login credentials for later use
432
 # record the default login credentials for later use
401
 chmod 600 ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt
435
 chmod 600 ${CURR_DIR}/${PROJECT_NAME}_login_credentials.txt
402
 
436
 
403
 if [[ $IMAGE_TYPE != "virtualbox"* && $IMAGE_TYPE != "qemu"* ]]; then
437
 if [[ $IMAGE_TYPE != "virtualbox"* && $IMAGE_TYPE != "qemu"* ]]; then
404
-    echo ''
405
-    echo $'You can copy the image to a microSD card with:'
406
-    echo ''
407
-    echo "    unxz -k ${PROJECT_NAME}*.img.xz"
408
-    echo "    sudo dd bs=1M if=${PROJECT_NAME}*.img of=/dev/sdX conv=fdatasync"
409
-    echo ''
438
+	echo ''
439
+	echo $'You can copy the image to a microSD card with:'
440
+	echo ''
441
+	echo "    unxz -k ${PROJECT_NAME}*.img.xz"
442
+	echo "    sudo dd bs=1M if=${PROJECT_NAME}*.img of=/dev/sdX conv=fdatasync"
443
+	echo ''
410
 fi
444
 fi
411
 
445
 
412
 exit 0
446
 exit 0

+ 23
- 0
src/freedombone-image-customise Dosyayı Görüntüle

78
 # Whether to only install debian and nothing else
78
 # Whether to only install debian and nothing else
79
 DEBIAN_INSTALL_ONLY="no"
79
 DEBIAN_INSTALL_ONLY="no"
80
 
80
 
81
+# wifi settings
81
 WIFI_INTERFACE='wlan0'
82
 WIFI_INTERFACE='wlan0'
83
+WIFI_SSID=
84
+WIFI_TYPE='wpa-psk'
85
+WIFI_PASSPHRASE=
86
+WIFI_HOTSPOT='no'
82
 
87
 
83
 enable_eatmydata_override() {
88
 enable_eatmydata_override() {
84
     chroot $rootdir apt-get install --no-install-recommends -y eatmydata
89
     chroot $rootdir apt-get install --no-install-recommends -y eatmydata
421
     chroot "$rootdir" systemctl enable $MESH_SERVICE
426
     chroot "$rootdir" systemctl enable $MESH_SERVICE
422
 }
427
 }
423
 
428
 
429
+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
444
+}
445
+
424
 # Set to true/false to control if eatmydata is used during build
446
 # Set to true/false to control if eatmydata is used during build
425
 use_eatmydata=true
447
 use_eatmydata=true
426
 
448
 
540
 atheros_wifi
562
 atheros_wifi
541
 continue_installation
563
 continue_installation
542
 initialise_mesh
564
 initialise_mesh
565
+configure_wifi
543
 
566
 
544
 cd /
567
 cd /
545
 echo $"info: killing leftover processes in chroot"
568
 echo $"info: killing leftover processes in chroot"

+ 10
- 0
src/freedombone-image-make Dosyayı Görüntüle

56
 export ONION_ONLY
56
 export ONION_ONLY
57
 export PROJECT_REPO
57
 export PROJECT_REPO
58
 export DEBIAN_INSTALL_ONLY
58
 export DEBIAN_INSTALL_ONLY
59
+export WIFI_INTERFACE
60
+export WIFI_SSID
61
+export WIFI_TYPE
62
+export WIFI_PASSPHRASE
63
+export WIFI_HOTSPOT
59
 
64
 
60
 # Locate vmdebootstrap program fetched in Makefile
65
 # Locate vmdebootstrap program fetched in Makefile
61
 basedir=`pwd`
66
 basedir=`pwd`
171
 sudo sed -i "s|ONION_ONLY=.*|ONION_ONLY=\"${ONION_ONLY}\"|g" $TEMP_CUSTOMISE
176
 sudo sed -i "s|ONION_ONLY=.*|ONION_ONLY=\"${ONION_ONLY}\"|g" $TEMP_CUSTOMISE
172
 sudo sed -i "s|PROJECT_REPO=.*|PROJECT_REPO=\"${PROJECT_REPO}\"|g" $TEMP_CUSTOMISE
177
 sudo sed -i "s|PROJECT_REPO=.*|PROJECT_REPO=\"${PROJECT_REPO}\"|g" $TEMP_CUSTOMISE
173
 sudo sed -i "s|DEBIAN_INSTALL_ONLY=.*|DEBIAN_INSTALL_ONLY=\"${DEBIAN_INSTALL_ONLY}\"|g" $TEMP_CUSTOMISE
178
 sudo sed -i "s|DEBIAN_INSTALL_ONLY=.*|DEBIAN_INSTALL_ONLY=\"${DEBIAN_INSTALL_ONLY}\"|g" $TEMP_CUSTOMISE
179
+sudo sed -i "s|WIFI_INTERFACE=.*|WIFI_INTERFACE=\"${WIFI_INTERFACE}\"|g" $TEMP_CUSTOMISE
180
+sudo sed -i "s|WIFI_SSID=.*|WIFI_SSID=\"${WIFI_SSID}\"|g" $TEMP_CUSTOMISE
181
+sudo sed -i "s|WIFI_TYPE=.*|WIFI_TYPE=\"${WIFI_TYPE}\"|g" $TEMP_CUSTOMISE
182
+sudo sed -i "s|WIFI_PASSPHRASE=.*|WIFI_PASSPHRASE=\"${WIFI_PASSPHRASE}\"|g" $TEMP_CUSTOMISE
183
+sudo sed -i "s|WIFI_HOTSPOT=.*|WIFI_HOTSPOT=\"${WIFI_HOTSPOT}\"|g" $TEMP_CUSTOMISE
174
 
184
 
175
 echo $"starting $VMDEBOOTSTRAP"
185
 echo $"starting $VMDEBOOTSTRAP"
176
 # Run vmdebootstrap script to create image
186
 # Run vmdebootstrap script to create image