Skip to content
Browse files

Add field to set the systems hostname at first boot wizard

  • Loading branch information...
1 parent 454e8cd commit d277133de6b1eedf523230f05d8d0a828b2b5f8a @kmoore134 kmoore134 committed Aug 14, 2013
Showing with 126 additions and 2 deletions.
  1. +35 −0 src-qt4/pc-firstbootgui/firstboot.cpp
  2. +3 −0 src-qt4/pc-firstbootgui/firstboot.h
  3. +88 −2 src-qt4/pc-firstbootgui/firstboot.ui
View
35 src-qt4/pc-firstbootgui/firstboot.cpp
@@ -8,6 +8,7 @@
#include <sys/types.h>
#include <pwd.h>
+#include <unistd.h>
#include "backend.h"
#include "ui_firstboot.h"
@@ -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()));
@@ -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);
@@ -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);
@@ -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)
View
3 src-qt4/pc-firstbootgui/firstboot.h
@@ -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();
View
90 src-qt4/pc-firstbootgui/firstboot.ui
@@ -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">
@@ -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>
@@ -307,6 +307,22 @@ background: transparent;</string>
</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">
<enum>Qt::Vertical</enum>
@@ -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">

0 comments on commit d277133

Please sign in to comment.
Something went wrong with that request. Please try again.