Parcourir la source

Improving initial login to generic image

Bob Mottram il y a 9 ans
Parent
révision
304eabc52f
1 fichiers modifiés avec 26 ajouts et 15 suppressions
  1. 26
    15
      src/freedombone-image-customise

+ 26
- 15
src/freedombone-image-customise Voir le fichier

97
 }
97
 }
98
 
98
 
99
 configure_networking() {
99
 configure_networking() {
100
-	if [[ $GENERIC_IMAGE == "no" ]]; then
100
+    if [[ $GENERIC_IMAGE == "no" ]]; then
101
         echo "# This file describes the network interfaces available on your system
101
         echo "# This file describes the network interfaces available on your system
102
 # and how to activate them. For more information, see interfaces(5).
102
 # and how to activate them. For more information, see interfaces(5).
103
 
103
 
140
         c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
140
         c=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
141
         d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
141
         d=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
142
         e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
142
         e=${hexarray[$RANDOM%16]}${hexarray[$RANDOM%16]}
143
-        sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \ 
143
+        sed -i "s|#hwaddress ether.*|hwaddress ether de:$a:$b:$c:$d:$e|g" \
144
             $rootdir/etc/network/interfaces
144
             $rootdir/etc/network/interfaces
145
-	fi
145
+    fi
146
 
146
 
147
     sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
147
     sed -i "s/nameserver.*/nameserver $NAMESERVER1/g" $rootdir/etc/resolv.conf
148
     sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
148
     sed -i "/nameserver $NAMESERVER1/a\nameserver $NAMESERVER2" $rootdir/etc/resolv.conf
195
     # The presence of this file indicates that the initial
195
     # The presence of this file indicates that the initial
196
     # setup has not yet been completed
196
     # setup has not yet been completed
197
     touch $rootdir/home/$MY_USERNAME/.initial_setup
197
     touch $rootdir/home/$MY_USERNAME/.initial_setup
198
+    chown $MY_USERNAME:$MY_USERNAME $rootdir/home/$MY_USERNAME/.initial_setup
198
     touch $rootdir/root/.initial_setup
199
     touch $rootdir/root/.initial_setup
199
-   
200
+
200
     cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
201
     cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
201
 # initial setup of the system
202
 # initial setup of the system
202
 if [ -f ~/.initial_setup ]; then
203
 if [ -f ~/.initial_setup ]; then
215
     echo ''
216
     echo ''
216
 EOF
217
 EOF
217
 
218
 
218
-echo '    NEW_USER_PASSWORD="$(openssl rand -base64 12 | cut -c1-10)"' >> $rootdir/home/$MY_USERNAME/.bashrc
219
-echo '    echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/home/$MY_USERNAME/.bashrc
220
-echo '    echo "    $NEW_USER_PASSWORD"' >> $rootdir/home/$MY_USERNAME/.bashrc
219
+    echo '    if [ -f ~/login.txt ]; then' >> $rootdir/home/$MY_USERNAME/.bashrc
220
+    echo '        NEW_USER_PASSWORD=$(cat ~/login.txt)' >> $rootdir/home/$MY_USERNAME/.bashrc
221
+    echo '    else' >> $rootdir/home/$MY_USERNAME/.bashrc
222
+    echo '        NEW_USER_PASSWORD="$(openssl rand -base64 12 | cut -c1-10)"' >> $rootdir/home/$MY_USERNAME/.bashrc
223
+    echo '    fi' >> $rootdir/home/$MY_USERNAME/.bashrc
224
+    echo '    echo -n "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/home/$MY_USERNAME/.bashrc
225
+    echo '    echo "    $NEW_USER_PASSWORD"' >> $rootdir/home/$MY_USERNAME/.bashrc
221
 
226
 
222
     cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
227
     cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
223
     echo ''
228
     echo ''
224
     echo 'Copy it into a password manager or write it down somewhere.'
229
     echo 'Copy it into a password manager or write it down somewhere.'
225
     echo ''
230
     echo ''
226
     read -n1 -r -p "Press any key to continue..." key
231
     read -n1 -r -p "Press any key to continue..." key
227
-    rm ~/.initial_setup
228
-    sudo su
232
+EOF
233
+    echo "    echo '$MY_PASSWORD' | sudo su" >> $rootdir/home/$MY_USERNAME/.bashrc
234
+    cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
229
 fi
235
 fi
230
 EOF
236
 EOF
231
 
237
 
232
     cat >> $rootdir/root/.bashrc <<EOF
238
     cat >> $rootdir/root/.bashrc <<EOF
233
 # initial setup of the system
239
 # initial setup of the system
234
 if [ -f ~/.initial_setup ]; then
240
 if [ -f ~/.initial_setup ]; then
241
+    freedombone menuconfig
242
+    if [ "$?" = "0" ]; then
235
 EOF
243
 EOF
236
-    echo -n "    echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
244
+    # change the password for the admin user
245
+    echo -n "        echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
237
     echo -n '$(cat /home/'  >> $rootdir/root/.bashrc
246
     echo -n '$(cat /home/'  >> $rootdir/root/.bashrc
238
     echo "${MY_USERNAME}/login.txt)\"|chpasswd" >> $rootdir/root/.bashrc
247
     echo "${MY_USERNAME}/login.txt)\"|chpasswd" >> $rootdir/root/.bashrc
248
+
249
+    # Remove the initial setup files
250
+    echo "        rm /root/.initial_setup" >> $rootdir/root/.bashrc
251
+    echo "        rm /home/${MY_USERNAME}/.initial_setup" >> $rootdir/root/.bashrc
252
+    echo "        shred -zu /home/${MY_USERNAME}/login.txt" >> $rootdir/root/.bashrc
239
     cat >> $rootdir/root/.bashrc <<EOF
253
     cat >> $rootdir/root/.bashrc <<EOF
240
-    freedombone menuconfig
241
-    rm ~/.initial_setup
242
-EOF
243
-    echo "    shred -zu /home/${MY_USERNAME}/login.txt" >> $rootdir/root/.bashrc
244
-    cat >> $rootdir/root/.bashrc <<EOF
254
+    fi
255
+    exit
245
 fi
256
 fi
246
 EOF
257
 EOF
247
 }
258
 }