forked from NASP/registry
jumpserver_deploy.sh
This commit is contained in:
parent
9fb20aeb9d
commit
b29880ff81
16
scripts/jumpserver_cron.sh
Executable file
16
scripts/jumpserver_cron.sh
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
set -ex
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
|
||||
tmp_path="/tmp/authorized_keys"
|
||||
dest_path="/home/ssh/.ssh/authorized_keys"
|
||||
echo "# This file is autoly generated. Changes here will not work." > "$tmp_path"
|
||||
|
||||
for file in $(find "$THIS_DIR/../authorized_keys" -type f); do
|
||||
(echo "# key file: ${file#*authorized_keys/}";cat "$file"; echo) >> "$tmp_path"
|
||||
done
|
||||
|
||||
cat "$tmp_path" > "$dest_path"
|
||||
rm "$tmp_path"
|
||||
chown ssh:ssh "$dest_path"
|
||||
chmod 600 "$dest_path"
|
|
@ -2,15 +2,19 @@
|
|||
set -ex
|
||||
THIS_DIR=$( cd "$( dirname "${BASH_SOURCE[0]:-${(%):-%x}}" )" && pwd )
|
||||
|
||||
tmp_path="/tmp/authorized_keys"
|
||||
dest_path="/home/ssh/.ssh/authorized_keys"
|
||||
echo "# This file is autoly generated. Changes here will not work." > "$tmp_path"
|
||||
adduser \
|
||||
--disabled-password \
|
||||
--home /home/ssh \
|
||||
ssh
|
||||
|
||||
for file in $(find "$THIS_DIR/../authorized_keys" -type f); do
|
||||
(echo "# key file: ${file#*authorized_keys/}";cat "$file"; echo) >> "$tmp_path"
|
||||
done
|
||||
insert_if_not_exist()
|
||||
{
|
||||
filename=$1
|
||||
line=$2
|
||||
if [ ! -f "$filename" ]; then
|
||||
touch $filename
|
||||
fi
|
||||
grep -qxF -- "$line" "$filename" || echo "$line" >> "$filename"
|
||||
}
|
||||
|
||||
cat "$tmp_path" > "$dest_path"
|
||||
rm "$tmp_path"
|
||||
chown ssh:ssh "$dest_path"
|
||||
chmod 600 "$dest_path"
|
||||
insert_if_not_exist "/etc/crontab" "*/5 0 0 0 0 cd \"$THIS_DIR\" && git pull && \"$THIS_DIR\"/jumpserver_cron.sh"
|
||||
|
|
Loading…
Reference in New Issue
Block a user