home · contact · privacy
Improve shell scripting.
authorChristian Heller <c.heller@plomlompom.de>
Tue, 13 Nov 2018 21:50:16 +0000 (22:50 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Tue, 13 Nov 2018 21:50:16 +0000 (22:50 +0100)
all_new_2018/init_user_and_keybased_login.sh
all_new_2018/symlink_etc.sh

index 5fa78315f1c786fb472a7676400888227d555207..dbce7f8e819d9356851b18ca63906891bac9644d 100755 (executable)
@@ -14,8 +14,8 @@ set -e
 # Location auf a sshd_config with "PermitRootLogin no" and
 # "PasswordAuthentication no".
 system_path_sshd_config='/etc/ssh/sshd_config'
-config_tree_prefix='~/config/all_new_2018/linkable_etc_files/server/'
-local_path_sshd_config="$config_tree_prefix""$system_path_sshd_config"
+config_tree_prefix="${HOME}/config/all_new_2018/linkable_etc_files/server/"
+local_path_sshd_config="${config_tree_prefix}""${system_path_sshd_config}"
 
 # Ensure we have a server name as argument.
 if [ $# -eq 0 ]; then
@@ -30,7 +30,7 @@ printf "Server root password: "
 read PW_ROOT
 stty echo
 printf "\n"
-export SSHPASS="$PW_ROOT"
+export SSHPASS="${PW_ROOT}"
 
 # Create user plom, and his ~/.ssh/authorized_keys based on the local
 # ~/.ssh/id_rsa.pub; ensure the result has proper permissions and
@@ -39,12 +39,12 @@ export SSHPASS="$PW_ROOT"
 #
 # This could be a line or two shorter by using ssh-copy-id, but that
 # would require setting a password for user plom otherwise not needed.
-sshpass -e scp ~/.ssh/id_rsa.pub root@"$server":/tmp/authorized_keys
-sshpass -e ssh root@"$server" \
+sshpass -e scp ~/.ssh/id_rsa.pub root@"${server}":/tmp/authorized_keys
+sshpass -e ssh root@"${server}" \
         'useradd -m plom && '\
         'mkdir /home/plom/.ssh && '\
         'chown plom:plom /tmp/authorized_keys && '\
         'chmod u=rw,go= /tmp/authorized_keys && '\
         'mv /tmp/authorized_keys /home/plom/.ssh/'
-sshpass -e scp "$local_path_sshd_config" root@"$server":"$system_path_sshd_config"
-sshpass -e ssh root@"$server" 'service ssh restart'
+sshpass -e scp "${local_path_sshd_config}" root@"${server}":"${system_path_sshd_config}"
+sshpass -e ssh root@"${server}" 'service ssh restart'
index 238d136123d2bbf92d74b432a27a0d620fbb5f3f..08f19135ddbcb3528fc68a82ff3f48d9868ca975 100644 (file)
@@ -6,9 +6,9 @@
 set -e
 
 target="$1"
-config_tree_prefix="~/config/all_new_2018/linkable_etc_files/"
-cd "$config_tree_prefix""$target"
+config_tree_prefix="${HOME}/config/all_new_2018/linkable_etc_files/"
+cd "${config_tree_prefix}""${target}"
 for path in $(find .); do
-    dest=$(echo "$path" | cut -c2-)
-    ln -fs "$path" "$dest"
+    dest=$(echo "${path}" | cut -c2-)
+    ln -fs "${path}" "${dest}"
 done