-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_unlabored
executable file
·128 lines (106 loc) · 3.05 KB
/
install_unlabored
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
set -e
trap 'echo "Error occurred at line $LINENO"' ERR
log() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $*" >&2
}
command -v python3 >/dev/null 2>&1 || {
log "Python3 is required but it's not installed. Aborting."
exit 1
}
ssh_folder_path="$HOME/.ssh/unlabored"
account_name=""
ssh_key_path=""
usage() {
cat <<EOF
Usage: $0 <command> [-a <account_name> -k <ssh_key_path>]
Commands:
install Run the installation.
setup-ssh Set up SSH.
ssh-agent Set up the SSH Agent service.
all Run everything (install, setup-ssh, ssh-agent).
Optional arguments:
-a <account_name> The username for the remote host.
-k <ssh_key_path> The path to the SSH private key to use for authentication.
Example: $0 install -a root -k ~/.ssh/ansible_ssh_key
Reqs: apt install python3 python3-venv python3-pip
This script sets up a development environment for setting up proxmox using ansible.
EOF
exit 1
}
install() {
python3 -m venv .venv
source ./.venv/bin/activate
pip install -r ./requirements.txt
pip install -r ./requirements-dev.txt
ansible-galaxy role install -r requirements.yaml -p ./ext_roles
pip install git+https://github.com/hitchhooker/AISTool
}
setup_ssh() {
if [ -z "${account_name}" ] || [ -z "${ssh_key_path}" ]; then
usage
fi
if [[ ! -f "$ssh_key_path" ]]; then
log "The SSH key file does not exist."
usage
exit 1
fi
mkdir -p "$ssh_folder_path"
cp "$ssh_key_path" "$ssh_folder_path/ansible_ssh_key"
export SSH_CONFIG_TARGET="$ssh_folder_path/config"
export SSH_CONFIG_USER="$account_name"
export SSH_CONFIG_IDENTITY="$ssh_folder_path/ansible_ssh_key"
if ! grep -qxF "Include $ssh_folder_path/config" ~/.ssh/config; then
echo "Include $ssh_folder_path/config" >>~/.ssh/config
fi
inv sshconfig
}
ssh_agent() {
log "Setting up SSH Agent service for forwarding..."
local shellrc_files=("$HOME/.bashrc" "$HOME/.zshrc")
for shellrc in "${shellrc_files[@]}"; do
if [[ -w "$shellrc" ]] && ! grep -qF 'SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"' "$shellrc"; then
echo 'export SSH_AUTH_SOCK="$XDG_RUNTIME_DIR/ssh-agent.socket"' >>"$shellrc"
log "Exported SSH_AUTH_SOCK to $shellrc. Please source this file or restart your shell session for the changes to take effect."
elif [[ ! -f "$shellrc" ]]; then
log "$shellrc does not exist. Skipping..."
else
log "SSH_AUTH_SOCK is already exported in $shellrc or the file is not writable. Skipping..."
fi
done
cat <<EOF >~/.config/systemd/user/ssh-agent.service
[Unit]
Description=SSH authentication agent
[Service]
ExecStart=/usr/bin/ssh-agent -a %t/ssh-agent.socket -D
Type=simple
[Install]
WantedBy=default.target
EOF
systemctl --user daemon-reload
systemctl --user enable --now ssh-agent
}
if [ $# -eq 0 ]; then
usage
exit 1
fi
command=$1
shift
while getopts "a:k:" option; do
case "${option}" in
a) account_name="${OPTARG}" ;;
k) ssh_key_path="${OPTARG}" ;;
*) usage ;;
esac
done
case "${command}" in
install) install ;;
setup-ssh) setup_ssh ;;
ssh-agent) ssh_agent ;;
all)
install
setup_ssh
ssh_agent
;;
*) usage ;;
esac