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