-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathark2host
More file actions
executable file
·135 lines (110 loc) · 2.86 KB
/
ark2host
File metadata and controls
executable file
·135 lines (110 loc) · 2.86 KB
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
129
130
131
132
133
134
135
#!/bin/bash
# ark2host
#
# Copy archives to a remote host and unpack them.
#
# Uses local copykey script to copy the local host's ssh key to the
# remote host.
#
# Uses 'runremote' script to run local script 'init-my-stuff' on
# the remote system.
#
declare BLD="\033[1m"
declare UND="\033[4m"
declare OFF="\033[0m"
declare usage=$(
cat <<EOF
$(basename $0) [options] <user@host>
Migrate archived environment in git repos to host.
Options:
-f file - send only the named archive
-i - install default apps to root@host
-p - host does not have push priveleges to git repos
-g - do not install linux git repos
-h - this help text
EOF
)
declare -i NOERR=0
declare -i ERR_NOFIL=1
declare -a errmsg=(
""
" not a valid file."
)
do_usage() {
local exval=$1
echo "$usage"
exit $exval
}
err_exit() {
local err=$1
local str="$2"
echo -e "\n$BLD$str${errmsg[$err]}$OFF"
do_usage 1
}
argc=$#
[ $argc -lt 1 ] && do_usage $NOERR
remote=${!argc}
declare file=
declare user=
declare pushpriv=
declare installer=false
declare nolinuxrepo=""
while getopts "giphf:u:" OPTION; do
case "$OPTION" in
g ) nolinuxrepo="-g"
;;
f ) file="$OPTARG"
[ -f "$file" ] || err_exit $ERR_NOFIL "$file"
;;
i ) installer=true
;;
p ) pushpriv="-p"
;;
h ) do_usage $NOERR
;;
u ) newuser="$OPTARG"
esac
done
user="$(echo "$remote" | cut -d'@' -f1)"
host="$(echo $remote | cut -d'@' -f2)"
if [ -n "$newuser" ] && [ "$user" != "root" ]; then
echo "Cannot add $newuser unless invoking with root."
echo "That is, 'ark2host -i -u $newuser root@$host'"
fi
# copy the localhost's ssh key to the remote host
copykey "$user" "$host"
# Must install rsync on the remote system before doing anything else.
ssh "$user@$host" "sudo dnf install -y rsync"
# Copy the lab.toml file
if [ -f ~/.config/lab/lab.toml ]; then
rsync -Pat --rsync-path='mkdir -p .config/lab/ && rsync' \
~/.config/lab/lab.toml "$user"@"$host":.config/lab/lab.toml
else
echo "Can't find .config/lab/lab.toml"
fi
# Copy the GitHub token file
if [ -f ~/.config/github/mygithubtoken ]; then
rsync -Pat --rsync-path='mkdir -p .config/github/ && rsync' \
~/.config/github/mygithubtoken "$user"@"$host":.config/github/mygithubtoken
ssh "$user@$host" "chmod 600 ~/.config/github/mygithubtoken"
echo "Copied GitHub token to remote host"
else
echo "Warning: ~/.config/github/mygithubtoken not found locally"
fi
script="$HOME/bin/bootstrap-github-access"
if [[ ! -f "$script" ]]; then
echo "❌ Script not found: $script"
exit 1
fi
echo "🔐 Uploading remote SSH key to GitHub..."
runremote "$user" "$host" "$script"
echo "connecting with $remote..."
if $installer; then
runremote $user $host \
"$HOME/bin/init-my-stuff" -i $pushpriv $nolinuxrepo $user
else
runremote $user $host \
"$HOME/bin/init-my-stuff" $pushpriv $nolinuxrepo $user $host $newuser
fi
echo
exit