Skip to content
This repository has been archived by the owner on Dec 4, 2020. It is now read-only.

Commit

Permalink
Add field to set the systems hostname at first boot wizard
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Moore committed Aug 14, 2013
1 parent 454e8cd commit d277133
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 2 deletions.
35 changes: 35 additions & 0 deletions src-qt4/pc-firstbootgui/firstboot.cpp
Expand Up @@ -8,6 +8,7 @@

#include <sys/types.h>
#include <pwd.h>
#include <unistd.h>

#include "backend.h"
#include "ui_firstboot.h"
Expand All @@ -26,6 +27,8 @@ Installer::Installer(QWidget *parent) : QMainWindow(parent)
connect(pushTouchKeyboard, SIGNAL(clicked()), this, SLOT(slotPushVirtKeyboard()));
connect(pushChangeKeyLayout, SIGNAL(clicked()), this, SLOT(slotPushKeyLayout()));

connect(lineHostname,SIGNAL(textChanged(const QString)),this,SLOT(slotCheckHost()));

connect(lineRootPW, SIGNAL(textChanged ( const QString &)), this, SLOT(slotCheckRootPW()));
connect(lineRootPW2, SIGNAL(textChanged ( const QString &)), this, SLOT(slotCheckRootPW()));

Expand All @@ -51,6 +54,9 @@ Installer::Installer(QWidget *parent) : QMainWindow(parent)
if (index != -1)
comboBoxTimezone->setCurrentIndex(index);

// Load the hostname
lineHostname->setText(pcbsd::Utils::getConfFileValue("/etc/rc.conf", "hostname=", 1));

// Start on the first screen
installStackWidget->setCurrentIndex(0);
backButton->setVisible(false);
Expand Down Expand Up @@ -130,6 +136,24 @@ void Installer::slotCheckRootPW()
nextButton->setEnabled(true);
}

void Installer::slotCheckHost()
{
QRegExp hostnameRegExp("^(([a-z0-9][a-z0-9-].*[a-z0-9])|([a-z0-9]+))$");
nextButton->setEnabled(false);
lineHostname->setText(lineHostname->text().toLower());
if (lineHostname->text().isEmpty())
{
lineHostname->setToolTip(tr("Please enter a hostname"));
return;
}
else if (hostnameRegExp.indexIn(lineHostname->text()) == -1)
{
lineHostname->setToolTip(tr("Hostname may only contain letters and numbers"));
return;
}
nextButton->setEnabled(true);
}

void Installer::slotCheckUser()
{
nextButton->setEnabled(false);
Expand Down Expand Up @@ -433,6 +457,17 @@ void Installer::saveSettings()
if ( checkEnc->isChecked() )
system("enable_user_pefs " + lineUsername->text().toLatin1() + " " + linePW->text().toLatin1());

// Do we need to change the system hostname?
if ( lineHostname->text() != pcbsd::Utils::getConfFileValue("/etc/rc.conf", "hostname=", 1) )
{
pcbsd::Utils::setConfFileValue("/etc/rc.conf", "hostname=", "hostname=\"" + lineHostname->text() + "\"", -1);
pcbsd::Utils::setConfFileValue("/etc/hosts", "::1", "::1\t\t\tlocalhost localhost.localdomain " + lineHostname->text() + ".localhost " + lineHostname->text(), -1);
pcbsd::Utils::setConfFileValue("/etc/hosts", "127.0.0.1", "127.0.0.1\t\tlocalhost localhost.localdomain " + lineHostname->text() + ".localhost " + lineHostname->text(), -1);

// Now set the hostname on the system
sethostname(lineHostname->text().toLatin1(), lineHostname->text().length());
}

}

void Installer::slotKeyLayoutUpdated(QString mod, QString lay, QString var)
Expand Down
3 changes: 3 additions & 0 deletions src-qt4/pc-firstbootgui/firstboot.h
Expand Up @@ -46,6 +46,9 @@ private slots:
void slotCheckUser();
void slotSuggestUsername();

// Let us check the hostname
void slotCheckHost();

// Start a scan of the network
void slotScanNetwork();

Expand Down
90 changes: 88 additions & 2 deletions src-qt4/pc-firstbootgui/firstboot.ui
Expand Up @@ -30,7 +30,7 @@
<string notr="true">background-image: url(:/modules/images/backgroundimage.jpg);</string>
</property>
<property name="currentIndex">
<number>3</number>
<number>1</number>
</property>
<widget class="QWidget" name="Page_Welcome">
<layout class="QGridLayout" name="gridLayout_2">
Expand Down Expand Up @@ -173,7 +173,7 @@ background: transparent;</string>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>50</height>
<height>30</height>
</size>
</property>
</spacer>
Expand Down Expand Up @@ -306,6 +306,22 @@ background: transparent;</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_17">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="verticalSpacer_11">
<property name="orientation">
Expand All @@ -319,6 +335,76 @@ background: transparent;</string>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_23">
<property name="minimumSize">
<size>
<width>0</width>
<height>55</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>55</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">border: transparent;
background: transparent;</string>
</property>
<property name="text">
<string/>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
<property name="pixmap">
<pixmap resource="pc-firstboot.qrc">:/modules/images/network.png</pixmap>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="styleSheet">
<string notr="true">background: transparent;</string>
</property>
<property name="title">
<string>System Hostname</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
<layout class="QGridLayout" name="gridLayout_10">
<item row="1" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Enter a valid hostname, or leave default.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="lineHostname">
<property name="styleSheet">
<string notr="true">background-color: rgb(255, 255, 255);</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item row="3" column="1">
Expand Down

0 comments on commit d277133

Please sign in to comment.