Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
chghostname / usr / bin / chghostname
Size: Mime:
#!/bin/bash
#------------------------------------------#
#     Change/edit hostname                 #
# Simple gui dialog to change the hostname #
#------------------------------------------#

ICON="/usr/share/chghostname/icons/hostname.svg"
MICON="/usr/share/chghostname/icons/hostname16.png"
EICON="/usr/share/chghostname/icons/error.svg"
ESICON="/usr/share/chghostname/icons/error16.svg"
OK="/usr/share/chghostname/icons/ok.svg"
CANCEL="/usr/share/chghostname/icons/cancel.svg"
pass_dialog="hostname"
clean_log() {
	

	if [ -n "$newhost" ]; then
		sed -i "s|$newhost|\*\*\*\*|"g $error_log
	fi
	
	if [ -n "$confirm_newhost" ]; then
		sed -i "s|$confirm_newhost|\*\*\*\*|"g $error_log
	fi
	newhost=""
	confirm_newhost=""
}

host_error() {
	
	clean_log
	use_existing=""
	yad --window-icon="$ESICON" --title=$"Hostname Error" --center --borders=10 \
	--image="$EICON" --width=400 --height=100 --fixed --button="Close!$CANCEL":0 \
	--text=$"\nHostnames do not match!  Restart the dialog again."
exit 0	
}
hostn=$(cat /etc/hostname)
#display existing hostname
OLDhost="Current hostname $hostn"

host_entry=$(yad --window-icon="$MICON" --form --title=$"Configure $host_dialog Hostname" \
--width=400 --height=125 --center --borders=10 --button="Ok!$OK":0 \
--text=$"<span color=\"#e07b39\">$host_dialog</span> $OLDhost         Use TAB to change fields." \
--field=$" Enter new <span color=\"#e07b39\">$host_dialog</span> hostname" \
--field=$" Confirm new <span color=\"#e07b39\">$host_dialog</span> hostname")  
newhost=$(echo $host_entry|awk -F "|" '{print $1}')
confirm_newhost=$(echo $host_entry|awk -F "|" '{print $2}')
use_existing=$(echo $host_entry|awk -F "|" '{print $3}')

	if [ -n "$newhost" ] && [ "$use_existing" = "TRUE" ]; then
	host_error
#	configure_host
	fi

	if [ -z "$newhost" ] || [ "$newhost" != "$confirm_newhost" ]; then
	host_error
#	configure_host
	fi

	pass_dialog=hostname
#	configure_host

			if [ -n "$newhost" ]; then
sed -i "s/$hostn/$newhost/g" /etc/hosts
sed -i "s/$hostn/$newhost/g" /etc/hostname
			fi
	
$(yad --window-icon="$MICON" --image="$ICON" --title=$"Change Hostname" \
--width=400 --height=100 --fixed --center --borders=10 --on-top --button="Reboot!$OK":1 --button="Close!$CANCEL":0 \
--text=$"\n<b>Hostname have been updated successfully</b>!\n\nYou must reboot to apply the changes.\n" )
if [ $? = "0"  ]; then
 exit 0	
else
reboot		
	fi