+hostname setting
This commit is contained in:
parent
f48ac1c9ae
commit
81b2811569
15
install.sh
15
install.sh
@ -112,7 +112,7 @@ setup_from_template() {
|
|||||||
generate_ssh_key() {
|
generate_ssh_key() {
|
||||||
local KEY_NAME="self-host-playbook"
|
local KEY_NAME="self-host-playbook"
|
||||||
local KEY_PATH="$HOME/.ssh/${KEY_NAME}"
|
local KEY_PATH="$HOME/.ssh/${KEY_NAME}"
|
||||||
W
|
|
||||||
if [ ! -f "$KEY_PATH" ]; then
|
if [ ! -f "$KEY_PATH" ]; then
|
||||||
mkdir -p "$HOME/.ssh"
|
mkdir -p "$HOME/.ssh"
|
||||||
echo "🔑 Generating new SSH key pair..." >&2
|
echo "🔑 Generating new SSH key pair..." >&2
|
||||||
@ -195,6 +195,7 @@ get_device_name() {
|
|||||||
setup_ssh_config() {
|
setup_ssh_config() {
|
||||||
local username=$1
|
local username=$1
|
||||||
local ip_address=$2
|
local ip_address=$2
|
||||||
|
local hostname=$3 # Add hostname parameter
|
||||||
local ssh_config_dir="$HOME/.ssh"
|
local ssh_config_dir="$HOME/.ssh"
|
||||||
local ssh_config_file="$ssh_config_dir/config"
|
local ssh_config_file="$ssh_config_dir/config"
|
||||||
local ssh_key_file="$ssh_config_dir/self-host-playbook"
|
local ssh_key_file="$ssh_config_dir/self-host-playbook"
|
||||||
@ -203,20 +204,20 @@ setup_ssh_config() {
|
|||||||
mkdir -p "$ssh_config_dir"
|
mkdir -p "$ssh_config_dir"
|
||||||
chmod 700 "$ssh_config_dir"
|
chmod 700 "$ssh_config_dir"
|
||||||
|
|
||||||
# Create or append to SSH config
|
# Create or append to SSH config using hostname as the Host name
|
||||||
local config_entry="Host self-host-playbook
|
local config_entry="Host $hostname
|
||||||
HostName $ip_address
|
HostName $ip_address
|
||||||
User $username
|
User $username
|
||||||
Port 2222
|
Port 2222
|
||||||
IdentityFile $ssh_key_file"
|
IdentityFile $ssh_key_file"
|
||||||
|
|
||||||
# Check if entry already exists
|
# Check if entry already exists
|
||||||
if ! grep -q "Host self-host-playbook" "$ssh_config_file" 2>/dev/null; then
|
if ! grep -q "Host $hostname" "$ssh_config_file" 2>/dev/null; then
|
||||||
echo -e "\n$config_entry" >> "$ssh_config_file"
|
echo -e "\n$config_entry" >> "$ssh_config_file"
|
||||||
echo "✅ Added SSH config entry"
|
echo "✅ Added SSH config entry"
|
||||||
else
|
else
|
||||||
# Update existing entry
|
# Update existing entry
|
||||||
sed -i.bak "/Host self-host-playbook/,/IdentityFile.*/{
|
sed -i.bak "/Host $hostname/,/IdentityFile.*/{
|
||||||
s/HostName.*/HostName $ip_address/
|
s/HostName.*/HostName $ip_address/
|
||||||
s/User.*/User $username/
|
s/User.*/User $username/
|
||||||
}" "$ssh_config_file"
|
}" "$ssh_config_file"
|
||||||
@ -425,7 +426,7 @@ echo "This process might take several minutes..."
|
|||||||
# Run nixos-anywhere installation
|
# Run nixos-anywhere installation
|
||||||
$INSTALL_COMMAND && {
|
$INSTALL_COMMAND && {
|
||||||
echo "🔧 Setting up SSH configuration..."
|
echo "🔧 Setting up SSH configuration..."
|
||||||
setup_ssh_config "$USERNAME" "$IP_ADDRESS"
|
setup_ssh_config "$USERNAME" "$IP_ADDRESS" "$HOSTNAME"
|
||||||
echo
|
echo
|
||||||
echo "🎉 Installation completed successfully!"
|
echo "🎉 Installation completed successfully!"
|
||||||
echo "=====================================>"
|
echo "=====================================>"
|
||||||
@ -435,7 +436,7 @@ $INSTALL_COMMAND && {
|
|||||||
echo "- Baserow: https://$BASEROW_DOMAIN"
|
echo "- Baserow: https://$BASEROW_DOMAIN"
|
||||||
echo
|
echo
|
||||||
echo "To connect to your server, use:"
|
echo "To connect to your server, use:"
|
||||||
echo "ssh self-host-playbook"
|
echo "ssh $HOSTNAME"
|
||||||
echo
|
echo
|
||||||
install_deploy_rs
|
install_deploy_rs
|
||||||
echo
|
echo
|
||||||
|
11
update.sh
11
update.sh
@ -121,6 +121,7 @@ perform_update() {
|
|||||||
setup_ssh_config() {
|
setup_ssh_config() {
|
||||||
local username=$1
|
local username=$1
|
||||||
local ip_address=$2
|
local ip_address=$2
|
||||||
|
local hostname=$3 # Add hostname parameter
|
||||||
local ssh_config_dir="$HOME/.ssh"
|
local ssh_config_dir="$HOME/.ssh"
|
||||||
local ssh_config_file="$ssh_config_dir/config"
|
local ssh_config_file="$ssh_config_dir/config"
|
||||||
local ssh_key_file="$ssh_config_dir/self-host-playbook"
|
local ssh_key_file="$ssh_config_dir/self-host-playbook"
|
||||||
@ -129,20 +130,20 @@ setup_ssh_config() {
|
|||||||
mkdir -p "$ssh_config_dir"
|
mkdir -p "$ssh_config_dir"
|
||||||
chmod 700 "$ssh_config_dir"
|
chmod 700 "$ssh_config_dir"
|
||||||
|
|
||||||
# Create or append to SSH config
|
# Create or append to SSH config using hostname as the Host name
|
||||||
local config_entry="Host self-host-playbook
|
local config_entry="Host $hostname
|
||||||
HostName $ip_address
|
HostName $ip_address
|
||||||
User $username
|
User $username
|
||||||
Port 2222
|
Port 2222
|
||||||
IdentityFile $ssh_key_file"
|
IdentityFile $ssh_key_file"
|
||||||
|
|
||||||
# Check if entry already exists
|
# Check if entry already exists
|
||||||
if ! grep -q "Host self-host-playbook" "$ssh_config_file" 2>/dev/null; then
|
if ! grep -q "Host $hostname" "$ssh_config_file" 2>/dev/null; then
|
||||||
echo -e "\n$config_entry" >> "$ssh_config_file"
|
echo -e "\n$config_entry" >> "$ssh_config_file"
|
||||||
echo "✅ Added SSH config entry"
|
echo "✅ Added SSH config entry"
|
||||||
else
|
else
|
||||||
# Update existing entry
|
# Update existing entry
|
||||||
sed -i.bak "/Host self-host-playbook/,/IdentityFile.*/{
|
sed -i.bak "/Host $hostname/,/IdentityFile.*/{
|
||||||
s/HostName.*/HostName $ip_address/
|
s/HostName.*/HostName $ip_address/
|
||||||
s/User.*/User $username/
|
s/User.*/User $username/
|
||||||
}" "$ssh_config_file"
|
}" "$ssh_config_file"
|
||||||
@ -280,7 +281,7 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
|
|||||||
# Setup SSH configuration
|
# Setup SSH configuration
|
||||||
echo
|
echo
|
||||||
echo "🔧 Setting up SSH configuration..."
|
echo "🔧 Setting up SSH configuration..."
|
||||||
setup_ssh_config "$USERNAME" "$IP_ADDRESS"
|
setup_ssh_config "$USERNAME" "$IP_ADDRESS" "$HOSTNAME"
|
||||||
echo
|
echo
|
||||||
install_deploy_rs
|
install_deploy_rs
|
||||||
echo "🚀 Applying the update to your system..."
|
echo "🚀 Applying the update to your system..."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user