Improving initial login to generic image

This commit is contained in:
Bob Mottram 2015-11-23 20:43:43 +00:00
parent e8f4133bc4
commit 304eabc52f
1 changed files with 26 additions and 15 deletions

View File

@ -195,6 +195,7 @@ create_generic_image() {
# The presence of this file indicates that the initial
# setup has not yet been completed
touch $rootdir/home/$MY_USERNAME/.initial_setup
chown $MY_USERNAME:$MY_USERNAME $rootdir/home/$MY_USERNAME/.initial_setup
touch $rootdir/root/.initial_setup
cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
@ -215,8 +216,12 @@ if [ -f ~/.initial_setup ]; then
echo ''
EOF
echo ' if [ -f ~/login.txt ]; then' >> $rootdir/home/$MY_USERNAME/.bashrc
echo ' NEW_USER_PASSWORD=$(cat ~/login.txt)' >> $rootdir/home/$MY_USERNAME/.bashrc
echo ' else' >> $rootdir/home/$MY_USERNAME/.bashrc
echo ' NEW_USER_PASSWORD="$(openssl rand -base64 12 | cut -c1-10)"' >> $rootdir/home/$MY_USERNAME/.bashrc
echo ' echo "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/home/$MY_USERNAME/.bashrc
echo ' fi' >> $rootdir/home/$MY_USERNAME/.bashrc
echo ' echo -n "${NEW_USER_PASSWORD}" > ~/login.txt' >> $rootdir/home/$MY_USERNAME/.bashrc
echo ' echo " $NEW_USER_PASSWORD"' >> $rootdir/home/$MY_USERNAME/.bashrc
cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
@ -224,25 +229,31 @@ echo ' echo " $NEW_USER_PASSWORD"' >> $rootdir/home/$MY_USERNAME/.bashrc
echo 'Copy it into a password manager or write it down somewhere.'
echo ''
read -n1 -r -p "Press any key to continue..." key
rm ~/.initial_setup
sudo su
EOF
echo " echo '$MY_PASSWORD' | sudo su" >> $rootdir/home/$MY_USERNAME/.bashrc
cat >> $rootdir/home/$MY_USERNAME/.bashrc <<EOF
fi
EOF
cat >> $rootdir/root/.bashrc <<EOF
# initial setup of the system
if [ -f ~/.initial_setup ]; then
freedombone menuconfig
if [ "$?" = "0" ]; then
EOF
# change the password for the admin user
echo -n " echo \"${MY_USERNAME}:" >> $rootdir/root/.bashrc
echo -n '$(cat /home/' >> $rootdir/root/.bashrc
echo "${MY_USERNAME}/login.txt)\"|chpasswd" >> $rootdir/root/.bashrc
cat >> $rootdir/root/.bashrc <<EOF
freedombone menuconfig
rm ~/.initial_setup
EOF
# Remove the initial setup files
echo " rm /root/.initial_setup" >> $rootdir/root/.bashrc
echo " rm /home/${MY_USERNAME}/.initial_setup" >> $rootdir/root/.bashrc
echo " shred -zu /home/${MY_USERNAME}/login.txt" >> $rootdir/root/.bashrc
cat >> $rootdir/root/.bashrc <<EOF
fi
exit
fi
EOF
}