Developing a Script and GUI for Changing the System Host Name.

Moderator: Forum moderators

Post Reply
User avatar
rockedge
Site Admin
Posts: 5711
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1990 times
Been thanked: 2097 times
Contact:

Developing a Script and GUI for Changing the System Host Name.

Post by rockedge »

I keep changing the KLV /etc/hostname file manually to set a custom system host name....what if we had a tiny script with a gtkdialog or yad GUI to change the hostname file?

@fredx181 do you thing it is worth having such a utility? What would the gtkdialog or YAD code look like?

User avatar
fredx181
Posts: 2560
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 273 times
Been thanked: 992 times
Contact:

Re: Developing a Script and GUI for Changing the System Host Name.

Post by fredx181 »

Something like this ?

Code: Select all

#!/bin/bash

CH_HOSTNAME=$(yad --center --borders=8 --width=300 --title="Change hostname?" --entry --text="Current hostname is <b>$(cat /etc/hostname)</b> \nChange hostname ? \nType the new name below ")
[ $? -ne 0 ] && exit
if [ -z $CH_HOSTNAME ]; then
yad --center --borders=8 --text="No new name provided\nExiting..." --button="Close:0"
exit
fi
echo $CH_HOSTNAME > /etc/hostname
User avatar
Keef
Posts: 249
Joined: Tue Dec 03, 2019 8:05 pm
Has thanked: 3 times
Been thanked: 66 times

Re: Developing a Script and GUI for Changing the System Host Name.

Post by Keef »

Maybe like this from Fatdog - /usr/sbin/fatog-set-hostname.sh

Code: Select all

#!/bin/ash
# jamesbond 2012 - set hostname
# 131109 L18L internationalisation

# std localisation stanza
export TEXTDOMAIN=fatdog
. gettext.sh
# performance tweak - use "C" if there is no localisation
! [ -e $TEXTDOMAINDIR/${LANG%.*}/LC_MESSAGES/$TEXTDOMAIN.mo ] &&
! [ -e $TEXTDOMAINDIR/${LANG%_*}/LC_MESSAGES/$TEXTDOMAIN.mo ] && LANG=C

### configuration
APPTITLE="$(gettext 'Set Hostname')"
HOSTNAME="$(hostname)"

[ $(id -u) -ne 0 ] && exec gtksu "$APPTITLE" "$0" "$@"

if Xdialog --title "$(gettext 'Warning!')" --yesno "$(gettext 'Changing hostname will automatically restart X server.')
$(gettext 'Do you wish to continue?')" 0 0; then
	if NEW_HOSTNAME=$(Xdialog --title "$APPTITLE" --backtitle "$(eval_gettext 'The current hostname is $HOSTNAME.')" --stdout \
	--inputbox "$(gettext 'Please enter the new hostname.')" 0 0); then
		NEW_HOSTNAME=$(echo "$NEW_HOSTNAME" | tr -d ' \t\n.~!@#$%^&*()?<>/,;:"[]{}\|=') # remove evil characters
		Xdialog --title "$(gettext 'Success!')" --infobox "$(eval_gettext 'Hostname will be changed to $NEW_HOSTNAME.') 
$(gettext 'X server will be restarted now, but the new hostname will only take full effect after reboot.')"	0 0 10000
		echo $NEW_HOSTNAME > /etc/hostname
		sed -i'' -e "1 {s/^.*$/127.0.0.1 localhost $(cat /etc/hostname)/}" /etc/hosts 
		hostname -F /etc/hostname
		DONT_ASK=1 wmexit restart
	fi
fi
Xdialog --title "$(gettext 'Cancelled!')" --infobox "$(eval_gettext 'Nothing is changed, hostname stays as $HOSTNAME')" 0 0 10000
User avatar
rockedge
Site Admin
Posts: 5711
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1990 times
Been thanked: 2097 times
Contact:

Re: Developing a Script and GUI for Changing the System Host Name.

Post by rockedge »

@Keef Excellent! This script works well on KLV's and is exactly what I was looking for.

I am going to add this utility to the KLV's rootfs

HerrBert
Posts: 329
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 17 times
Been thanked: 110 times

Re: Developing a Script and GUI for Changing the System Host Name.

Post by HerrBert »

rockedge wrote: Sun Mar 10, 2024 4:21 pm

I keep changing the KLV /etc/hostname file manually to set a custom system host name....what if we had a tiny script with a gtkdialog or yad GUI to change the hostname file?
...

Isn't this a part of quicksetup in mainline puppies?

gtkdialog-Quick Setup.jpg
gtkdialog-Quick Setup.jpg (72.65 KiB) Viewed 161 times
User avatar
Chelsea80
Posts: 254
Joined: Tue Mar 09, 2021 12:44 am
Has thanked: 34 times
Been thanked: 56 times

Re: Developing a Script and GUI for Changing the System Host Name.

Post by Chelsea80 »

@HerrBert

Can confirm Hostname change is available in (see my signature) -
.

Hostname.jpg
Hostname.jpg (129.92 KiB) Viewed 153 times

.
Although I have never used it so I can't comment on its use -

Chelsea80

Chelsea80

BionicPup32+28 19.03 - Linux 4.9.163 - lxpup - 32-pae [i686] - (UPup Bionic Beaver)
Frugal Install - Internal HDD - Gateway MX8716b - HDD 120GB - RAM 2GB

Friendly-Bionic32 v1.1
USB Stick 2GB

User avatar
rockedge
Site Admin
Posts: 5711
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1990 times
Been thanked: 2097 times
Contact:

Re: Developing a Script and GUI for Changing the System Host Name.

Post by rockedge »

@HerrBert I borrowed the FatDog version for Kennel Linux. In KLV-Airedale up until now the host name had to be set manually to change it from the default void-live. This is just a convenience for the user to switch to a custom host name. I have many machines on two connected LAN's, so to prevent duplicate host names and make it easier to share resources across all the machines, each machine running Puppy Linux and now KLV-Airedale can quickly assign unique host names to differentiate each machine individually. Network sharing with SAMBA is very easy when the hostname are set to a unique name for each individual machine.

User avatar
rockedge
Site Admin
Posts: 5711
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 1990 times
Been thanked: 2097 times
Contact:

Re: Developing a Script and GUI for Changing the System Host Name.

Post by rockedge »

@fredx181 Thanks! I like the script and it works well :ugeek: :thumbup2:

Post Reply

Return to “KL-Dev_Work”