diff --git a/defaultlook.cpp b/defaultlook.cpp index c9bc9e2a..0ded8672 100644 --- a/defaultlook.cpp +++ b/defaultlook.cpp @@ -1501,6 +1501,12 @@ void defaultlook::setupEtc() debianKernelUpdateFlag = false; liqKernelUpdateFlag = false; + //hostname + ui->checkBoxComputerName->setChecked(false); + ui->lineEditHostname->setEnabled(false); + originalhostname = runCmd("hostname").output; + ui->lineEditHostname->setText(originalhostname); + //setup NOCSD GTK3 option if (!QFileInfo::exists(QStringLiteral("/usr/bin/gtk3-nocsd"))) { if (verbose) qDebug() << "gtk3-nocsd not found"; @@ -2550,6 +2556,16 @@ void defaultlook::on_ButtonApplyEtc_clicked() } } + //hostname setting + //if name doesn't validate, don't make any changes to any options, and don't reset gui. + if (ui->checkBoxComputerName->isChecked()){ + if (validatecomputername(ui->lineEditHostname->text())){ + changecomputername(ui->lineEditHostname->text()); + } else { + return; + } + } + //checkbox options if ( ! udisks_option.isEmpty() || ! sudo_override_option.isEmpty() || ! user_name_space_override_option.isEmpty() || ! intel_option.isEmpty() || ! lightdm_option.isEmpty() || ! amd_option.isEmpty() || ! radeon_option.isEmpty() || !bluetooth_option.isEmpty() || !recommends_option.isEmpty() || !debian_kernel_updates_option.isEmpty() || !liq_kernel_updates_option.isEmpty()){ runCmd("pkexec /usr/lib/mx-tweak/mx-tweak-lib.sh " + udisks_option + " " + sudo_override_option + " " + user_name_space_override_option + " " + intel_option + " " + amd_option + " " + radeon_option + " " + bluetooth_option + " " + recommends_option + " " + lightdm_option + " " + debian_kernel_updates_option + " " + liq_kernel_updates_option); @@ -2558,6 +2574,23 @@ void defaultlook::on_ButtonApplyEtc_clicked() setupEtc(); } +void defaultlook::changecomputername(QString hostname){ + runCmd("pkexec /usr/lib/mx-tweak/mx-tweak-lib.sh hostname " + hostname); +} + +bool defaultlook::validatecomputername(QString hostname){ + // see if name is reasonable + if (hostname.isEmpty()) { + QMessageBox::critical(this, this->windowTitle(), tr("Please enter a computer name.", "question to enter a name for the computer hostname")); + return false; + } else if (hostname.contains(QRegularExpression("[^0-9a-zA-Z-.]|^[.-]|[.-]$|\\.\\."))) { + QMessageBox::critical(this, this->windowTitle(), + tr("Sorry, your computer name contains invalid characters.\nYou'll have to select a different\nname before proceeding.", "unacceptable characters are found in hostname, pick a new name")); + return false; + } + return true; +} + void defaultlook::on_checkBoxSingleClick_clicked() { ui->ButtonApplyMiscDefualts->setEnabled(true); @@ -4204,3 +4237,15 @@ void defaultlook::on_checkBoxPlasmaDiscoverUpdater_clicked() ui->ButtonApplyPlasma->setEnabled(true); } + +void defaultlook::on_checkBoxComputerName_clicked() +{ + ui->ButtonApplyEtc->setEnabled(true); + if (ui->checkBoxComputerName->isChecked()){ + ui->lineEditHostname->setEnabled(true); + } else { + ui->lineEditHostname->setEnabled(false); + } +} + + diff --git a/defaultlook.h b/defaultlook.h index 0770edc7..09faf9d9 100644 --- a/defaultlook.h +++ b/defaultlook.h @@ -72,6 +72,7 @@ class defaultlook : public QDialog QHash theme_info; QString pluginidsystray; QString plugintasklist; + QString originalhostname; QStringList undotheme; bool verbose = false; bool panelflag{}; @@ -183,6 +184,8 @@ class defaultlook : public QDialog void setmissingxfconfvariables(const QString &activeprofile, const QString &resolution); void fluxboxchangeinitvariable(const QString &initline, const QString &value) const; void fluxboxchangedock() const; + void changecomputername(QString hostname); + bool validatecomputername(QString hostname); private slots: static void on_buttonCancel_clicked(); @@ -315,6 +318,8 @@ private slots: void on_checkBoxPlasmaDiscoverUpdater_clicked(); + void on_checkBoxComputerName_clicked(); + private: Ui::defaultlook *ui; }; diff --git a/defaultlook.ui b/defaultlook.ui index 2d9c696b..9e01a460 100644 --- a/defaultlook.ui +++ b/defaultlook.ui @@ -7,7 +7,7 @@ 0 0 1109 - 746 + 829 @@ -265,7 +265,7 @@ QTabWidget::North - 6 + 8 @@ -1936,62 +1936,49 @@ - - QLayout::SetNoConstraint - - - + + - Use tearfree radeon driver option + &User - - + + - NOTE: existing /etc/X11/xorg.conf.d/20-radeon.conf will be backed up to home folder + Use tearfree amdgpu option - + Password for administrative tasks: - - - - - 0 - 32 - - + + - Apply - - - - .. + Root - - + + - Generate fluxbox All Apps menu after package installation, removal, and updates + Use Client Side Decorations (CSD) on GTK3 applications that support them (requires session restart) - - + + - Reset Lightdm (login screen) to system default theme + NOTE: existing /etc/X11/xorg.conf.d/20-intel.conf will be backed up to home folder - + <html><head/><body><p>requires reboot</p></body></html> @@ -2001,116 +1988,123 @@ - - + + - Root + Apt installs additional "recommends" packages as dependencies - - + + - Use tearfree amdgpu option + Enable kernel sandbox - - + + - NOTE: existing /etc/X11/xorg.conf.d/20-amd.conf will be backed up to home folder + NOTE: existing /etc/X11/xorg.conf.d/20-radeon.conf will be backed up to home folder - - - - Qt::Vertical - - - - 20 - 77 - + + + + put a hold or remove a hold on updates of Liquorix kernels - - - - - Apt installs additional "recommends" packages as dependencies + Enable Automatic Liquorix Kernel Updates (MX ahs repository) - - + + - Enable mounting of internal drives by non-root users + Use intel driver instead of default "modesetting" driver (requires restart) - - + + + + put a hold or remove a hold on updates of Debian kernels + - NOTE: existing /etc/X11/xorg.conf.d/20-intel.conf will be backed up to home folder + Enable Automatic Debian Kernel Updates - - + + - &User + Generate fluxbox All Apps menu after package installation, removal, and updates - - + + - Use Client Side Decorations (CSD) on GTK3 applications that support them (requires session restart) + Use tearfree radeon driver option - - + + - Enable kernel sandbox + Reset Lightdm (login screen) to system default theme - - - - Qt::Horizontal + + + + NOTE: existing /etc/X11/xorg.conf.d/20-amd.conf will be backed up to home folder - - + + - Use intel driver instead of default "modesetting" driver (requires restart) + Enable mounting of internal drives by non-root users - - - - put a hold or remove a hold on updates of Liquorix kernels + + + + + 0 + 32 + - Enable Automatic Liquorix Kernel Updates (MX ahs repository) + Apply + + + + .. - - - - put a hold or remove a hold on updates of Debian kernels + + + + Qt::Horizontal + + + + - Enable Automatic Debian Kernel Updates + Change computer name (requires reboot) + + + diff --git a/lib/mx-tweak-lib.sh b/lib/mx-tweak-lib.sh index 9feba6b1..68562829 100755 --- a/lib/mx-tweak-lib.sh +++ b/lib/mx-tweak-lib.sh @@ -238,6 +238,29 @@ if [ -n "$(LC_ALL=C dpkg --status linux-image-liquorix-amd64 2>/dev/null| grep " fi } +change_hostname() +{ +local original="$(hostname)" new="$1" + +echo "$original" +echo "$new" + +if [ -e "/etc/hostname" ]; then + sed -i "s/$original/$new/" /etc/hostname +fi +if [ -e "/etc/hosts" ]; then + sed -i "s/$original/$new/" /etc/hosts +fi +if [ -e "/etc/mailname" ]; then + sed -i "s/$original/$new/" /etc/mailname +fi +if [ -e "/etc/dhcp/dhclient.conf" ]; then + sed -i "s/$original/$new/" /etc/dhcp/dhclient.conf +fi + +hostname "$new" +} + main() { $CMD1 @@ -249,7 +272,6 @@ $CMD6 $CMD7 $CMD8 $CMD9 - } CMD1=$1 @@ -262,6 +284,10 @@ CMD7=$7 CMD8=$8 CMD9=$9 -main +if [ "$CMD1" = "hostname" ]; then + change_hostname "$CMD2" +else + main +fi exit 0 diff --git a/translations/mx-tweak_en.ts b/translations/mx-tweak_en.ts index 6751308c..4fc1005a 100644 --- a/translations/mx-tweak_en.ts +++ b/translations/mx-tweak_en.ts @@ -298,7 +298,7 @@ - + Apply apply changes @@ -749,6 +749,11 @@ Workspace + + + Change computer name (requires reboot) + + Enable single-click @@ -800,111 +805,111 @@ - + Reset Lightdm (login screen) to system default theme - + put a hold or remove a hold on updates of Liquorix kernels toggle for apt hold action on update meta packages - + Enable Automatic Liquorix Kernel Updates (MX ahs repository) uses apt-mark to hold or unhold updates to kernel metapackages - + put a hold or remove a hold on updates of Debian kernels toggle for apt hold action on update meta packages - + Enable Automatic Debian Kernel Updates uses apt-mark to hold or unhold updates to kernel metapackages - + Password for administrative tasks: - + Enable mounting of internal drives by non-root users - + Root - + Enable kernel sandbox - + &User - + <html><head/><body><p>requires reboot</p></body></html> - + Enable Bluetooth Adapters on boot - + Apt installs additional "recommends" packages as dependencies - + Generate fluxbox All Apps menu after package installation, removal, and updates - + Use Client Side Decorations (CSD) on GTK3 applications that support them (requires session restart) - + Use intel driver instead of default "modesetting" driver (requires restart) - + NOTE: existing /etc/X11/xorg.conf.d/20-intel.conf will be backed up to home folder - + Use tearfree amdgpu option - + NOTE: existing /etc/X11/xorg.conf.d/20-amd.conf will be backed up to home folder - + Use tearfree radeon driver option - + NOTE: existing /etc/X11/xorg.conf.d/20-radeon.conf will be backed up to home folder @@ -984,17 +989,31 @@ - + settings - + Choose a theme set - + + Please enter a computer name. + question to enter a name for the computer hostname + + + + + Sorry, your computer name contains invalid characters. +You'll have to select a different +name before proceeding. + unacceptable characters are found in hostname, pick a new name + + + + Select application to run will show in file dialog when selection an application to run