From 038edc961dbf6d265f5bce5dc2b4361a6740a917 Mon Sep 17 00:00:00 2001 From: DocRock3r Date: Wed, 23 Apr 2025 19:14:49 +0000 Subject: [PATCH 1/4] Add Scripts/change_hostname.sh Signed-off-by: DocRock3r --- Scripts/change_hostname.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Scripts/change_hostname.sh diff --git a/Scripts/change_hostname.sh b/Scripts/change_hostname.sh new file mode 100644 index 0000000..0c6be60 --- /dev/null +++ b/Scripts/change_hostname.sh @@ -0,0 +1,26 @@ +#! /bin/bash + +clear + +#get current hostname and set it as value of old_host +old_host=$(hostname) + +#make backups for hostname and hosts files +cp /etc/hostname /etc/hostname.bk +cd /etc/hosts /etc/hosts.bk + +#ask user for new host name and set it as value for new_host +printf "%s\n" "Hostname must be between 1-63 characters long" +printf "%s\n" "Valid characters are (lower case a-z), (0-9), and (-)" +printf "%s" "enter new hostname: " +read new_host + +#replace old_host with new_host in hostname and hosts files +#set hostname to new_host +sed -i 's/'$old_host'/'$new_host'/' /etc/hostname +sed -i 's/'$old_host'/'$new_host'/' /etc/hosts +hostname $new_host + +#confirm change and tell user to restart system +printf "%s\n" "Hostname changed from [$old_host] to [$new_host]" +printf "%s\n" "Reboot your system for the change to take effect" \ No newline at end of file -- 2.49.1 From 86faa63db1a42989a4389e0b30beb91a1e4315f9 Mon Sep 17 00:00:00 2001 From: DocRock3r Date: Wed, 23 Apr 2025 19:16:51 +0000 Subject: [PATCH 2/4] Update ReadMe.md Signed-off-by: DocRock3r --- ReadMe.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ReadMe.md b/ReadMe.md index 2728051..8d110b8 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -6,3 +6,4 @@ A collection of scripts intedned to simplify setting up and maintianing an Ubunt [Docker](Scripts/Docker.sh) - Install Docker [Portainer](Scripts/Portainer.sh) - Install Docker and Portainer Server [Update](Scripts/Update.sh) - Update and clean up unused packages +[Change Hostname](Scripts/change_hostname.sh) - Change the hostname for the system \ No newline at end of file -- 2.49.1 From ff8001d297b69d88e0df707772c348d3f090e8de Mon Sep 17 00:00:00 2001 From: DocRock3r Date: Wed, 23 Apr 2025 19:33:01 +0000 Subject: [PATCH 3/4] Update Scripts/change_hostname.sh --- Scripts/change_hostname.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/change_hostname.sh b/Scripts/change_hostname.sh index 0c6be60..1dc450d 100644 --- a/Scripts/change_hostname.sh +++ b/Scripts/change_hostname.sh @@ -7,7 +7,7 @@ old_host=$(hostname) #make backups for hostname and hosts files cp /etc/hostname /etc/hostname.bk -cd /etc/hosts /etc/hosts.bk +cp /etc/hosts /etc/hosts.bk #ask user for new host name and set it as value for new_host printf "%s\n" "Hostname must be between 1-63 characters long" -- 2.49.1 From f3dffb2a749e9753817b18534711cd66c312c8ba Mon Sep 17 00:00:00 2001 From: DocRock3r Date: Wed, 23 Apr 2025 19:42:52 +0000 Subject: [PATCH 4/4] Update Scripts/USE-AIO.sh Signed-off-by: DocRock3r --- Scripts/USE-AIO.sh | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/Scripts/USE-AIO.sh b/Scripts/USE-AIO.sh index 3dceddf..bc9cd43 100644 --- a/Scripts/USE-AIO.sh +++ b/Scripts/USE-AIO.sh @@ -4,10 +4,11 @@ clear echo "What do you want to do?" echo "1. Install Docker" echo "2. Install Docker + Portainer Server" -echo "3. Update system" -echo "4. Exit" +echo "3. Update System" +echo "4. Change Hostname" +echo "5. Exit" echo "" -echo -n "enter your selection: " +echo -n "enter your selection(1-4)(5 to exit): " while : do @@ -22,32 +23,37 @@ case $choice in sudo install -m 0755 -d /etc/apt/keyrings 1>/dev/null sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc 1>/dev/null sudo chmod a+r /etc/apt/keyrings/docker.asc 1>/dev/null + # Add the repository to Apt sources: echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update 1>/dev/null + # Install Docker sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y 1>/dev/null echo "Done";; -2) echo "Installing Docker..." +2) echo "Installing Docker..." # Add Docker's official GPG key: sudo apt-get update 1>/dev/null sudo apt-get install ca-certificates curl -y 1>/dev/null sudo install -m 0755 -d /etc/apt/keyrings 1>/dev/null sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc 1>/dev/null sudo chmod a+r /etc/apt/keyrings/docker.asc 1>/dev/null + # Add the repository to Apt sources: echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \ $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null sudo apt-get update 1>/dev/null + # Install Docker sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y 1>/dev/null echo "Done" + #install Portianer server echo "Installing Portainer..." sudo docker volume create portainer_data 1>/dev/null @@ -64,12 +70,40 @@ case $choice in sudo apt-get autoremove -y 1>/dev/null echo "Done" ;; -4) echo "Exiting..." +4) echo "" + + #get current hostname and set it as value of old_host + old_host=$(hostname) + + #make backups for hostname and hosts files + cp /etc/hostname /etc/hostname.bk + cp /etc/hosts /etc/hosts.bk + + #ask user for new host name and set it as value for new_host + printf "%s\n" "Hostname must be between 1-63 characters long" + printf "%s\n" "Valid characters are (lower case a-z), (0-9), and (-)" + printf "%s" "enter new hostname: " + read new_host + + #replace old_host with new_host in hostname and hosts files + #set hostname to new_host + sed -i 's/'$old_host'/'$new_host'/' /etc/hostname + sed -i 's/'$old_host'/'$new_host'/' /etc/hosts + hostname $new_host + + #confirm change and tell user to restart system + printf "%s\n" "Hostname changed from [$old_host] to [$new_host]" + printf "%s\n" "Reboot your system for the change to take effect" ;; + +5) echo "Exiting..." exit ;; + *) echo "Invalid option" ;; esac -echo -n "enter your selection: " +echo "" +echo "" +echo -n "enter your selection(1-4)(5 to exit): " done \ No newline at end of file -- 2.49.1