2012-12-19 03:50:16 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Failsafe minimal text-mode firstboot
|
|
|
|
|
|
|
|
# Welcome
|
|
|
|
|
2015-03-21 21:03:15 +00:00
|
|
|
if [ "x$1" = "x--help" ]; then
|
|
|
|
echo "Failsafe minimal text-mode firstboot"
|
|
|
|
echo "For unattended mode use: $0 <username> <userpass> <vm-creation-option-number>"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2012-12-19 03:50:16 +00:00
|
|
|
echo "########################################################"
|
|
|
|
echo "### ###"
|
|
|
|
echo "### Welcome to `cat /etc/qubes-release` ###"
|
|
|
|
echo "### ###"
|
|
|
|
echo "########################################################"
|
|
|
|
echo
|
|
|
|
echo "This is failsafe text-mode firstboot. If you see this message, you have"
|
|
|
|
echo "some problem with Xorg (most probably video driver)"
|
|
|
|
echo
|
|
|
|
echo "Anyway some basic setup is needed to continue:"
|
|
|
|
|
|
|
|
# User creation
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "1. Setup user account"
|
2015-03-21 21:03:15 +00:00
|
|
|
user=$1
|
2012-12-19 03:50:16 +00:00
|
|
|
while [ -z "$user" ]; do
|
|
|
|
echo -n "Enter desired username: "
|
|
|
|
read user
|
|
|
|
if echo "$user" | grep -q "[^a-z0-9]"; then
|
|
|
|
echo "ERROR: Invalid characters in username, try again"
|
2015-03-21 21:03:15 +00:00
|
|
|
user=
|
2012-12-19 03:50:16 +00:00
|
|
|
elif id $user > /dev/null 2>&1; then
|
|
|
|
echo "ERROR: This user already exists, try again"
|
2015-03-21 21:03:15 +00:00
|
|
|
user=
|
2012-12-19 03:50:16 +00:00
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
useradd -G qubes -m "$user" || exit 1
|
2015-03-21 21:03:15 +00:00
|
|
|
if [ -n "$2" ]; then
|
|
|
|
echo -e "$2\n$2" | passwd --stdin "$user"
|
|
|
|
else
|
|
|
|
while ! passwd "$user"; do true; done
|
|
|
|
fi
|
2012-12-19 03:50:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Create default VMs
|
|
|
|
|
|
|
|
echo
|
|
|
|
echo "2. Create default VMs"
|
|
|
|
echo
|
|
|
|
echo "Choose one option:"
|
|
|
|
echo " 1. Create default service VMs, and pre-defined AppVMs (work, banking, personal, untrusted)"
|
|
|
|
echo " 2. Just create default service VMs"
|
2015-03-21 21:03:15 +00:00
|
|
|
echo " 3. Do not create any VMs right now, but configure template(s)"
|
|
|
|
echo " 4. Do not do anything (not recommended, for advanced users only)"
|
|
|
|
vms_option=$3
|
2012-12-19 03:50:16 +00:00
|
|
|
while true; do
|
2015-03-21 21:03:15 +00:00
|
|
|
if [ -z "$vms_option" ]; then
|
|
|
|
echo -n "Enter your choice (1/2/3): "
|
|
|
|
read vms_option
|
|
|
|
fi
|
2012-12-19 03:50:16 +00:00
|
|
|
if [ "$vms_option" == "1" ]; then
|
2015-03-21 21:03:15 +00:00
|
|
|
vms_template=yes
|
2012-12-19 03:50:16 +00:00
|
|
|
vms_service=yes
|
|
|
|
vms_app=yes
|
|
|
|
break
|
|
|
|
elif [ "$vms_option" == "2" ]; then
|
2015-03-21 21:03:15 +00:00
|
|
|
vms_template=yes
|
2012-12-19 03:50:16 +00:00
|
|
|
vms_service=yes
|
|
|
|
break
|
|
|
|
elif [ "$vms_option" == "3" ]; then
|
2015-03-21 21:03:15 +00:00
|
|
|
vms_template=yes
|
|
|
|
break
|
|
|
|
elif [ "$vms_option" == "4" ]; then
|
2012-12-19 03:50:16 +00:00
|
|
|
break
|
|
|
|
else
|
|
|
|
echo "ERROR: Invalid choice, try again"
|
2015-03-21 21:03:15 +00:00
|
|
|
vms_option=
|
2012-12-19 03:50:16 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2015-03-21 21:03:15 +00:00
|
|
|
if [ "$vms_template" == "yes" ]; then
|
|
|
|
for template in `ls /var/lib/qubes/vm-templates`; do
|
|
|
|
echo "-> Configuring template $template..."
|
|
|
|
qvm-start --no-guid $template
|
|
|
|
qvm-run --nogui --pass-io -u root $template 'cat > /etc/locale.conf' < /etc/locale.conf
|
|
|
|
su -c "qvm-sync-appmenus $template" - $user
|
|
|
|
qvm-shutdown --wait $template
|
|
|
|
done
|
|
|
|
fi
|
2012-12-19 03:50:16 +00:00
|
|
|
if [ "$vms_service" == "yes" ]; then
|
|
|
|
echo "-> Creating default netvm..."
|
|
|
|
su -c "/usr/bin/qvm-create --net --label red netvm" - $user
|
|
|
|
for dev in `/sbin/lspci -mm -n | sed -ne 's/^\([0-9][0-9]:[0-9][0-9].[0-9]\) "02.*/\1/p'`; do
|
|
|
|
su -c "/usr/bin/qvm-pci -a netvm $dev" - $user
|
|
|
|
done
|
|
|
|
echo "-> Creating default firewallvm..."
|
|
|
|
su -c "/usr/bin/qvm-create --proxy --label green firewallvm" - $user
|
|
|
|
su -c "/usr/bin/qvm-prefs --set firewallvm netvm netvm" - $user
|
|
|
|
su -c "/usr/bin/qubes-prefs --set default-netvm firewallvm" - $user
|
|
|
|
echo "-> Starting network..."
|
2015-03-21 21:03:15 +00:00
|
|
|
service qubes-netvm start
|
2012-12-19 03:50:16 +00:00
|
|
|
echo "-> Creating DispVM savefile (can take long time)..."
|
2015-03-21 21:03:15 +00:00
|
|
|
su -c "/usr/bin/qvm-create-default-dvm --default-template --default-script" - $user || :
|
2012-12-19 03:50:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$vms_app" == "yes" ]; then
|
|
|
|
echo "-> Creating default AppVMs..."
|
|
|
|
su -c "/usr/bin/qvm-create work --label green" - $user
|
|
|
|
su -c "/usr/bin/qvm-create banking --label green" - $user
|
|
|
|
su -c "/usr/bin/qvm-create personal --label yellow" - $user
|
|
|
|
su -c "/usr/bin/qvm-create untrusted --label red" - $user
|
|
|
|
fi
|
|
|
|
echo "-> Done."
|