-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·76 lines (66 loc) · 2.5 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·76 lines (66 loc) · 2.5 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
#!/usr/bin/env bash
# setup.sh — install codesync under $HOME/.codesync, put it on your PATH, and
# seed the default config. Layout it creates:
#
# $HOME/.codesync/env/ the virtualenv (Python + PyYAML)
# $HOME/.codesync/bin/codesync link to this repo's launcher (room for more)
# ~/.local/bin/codesync symlink on your PATH
# ~/.config/codesync/codesync.yaml default config (seeded once)
set -euo pipefail
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT="$HOME/.codesync"
ENV_DIR="$ROOT/env"
BIN_DIR="$ROOT/bin"
LOCAL_BIN="$HOME/.local/bin"
CONFIG_DIR="$HOME/.config/codesync"
CONFIG_FILE="$CONFIG_DIR/codesync.yaml"
# Migrate the old layout, where the venv lived directly in $HOME/.codesync.
if [ -f "$ROOT/pyvenv.cfg" ]; then
echo "Migrating old venv layout in $ROOT ..."
rm -rf "$ROOT"
fi
echo "Creating virtualenv at $ENV_DIR ..."
mkdir -p "$BIN_DIR"
python3 -m venv "$ENV_DIR"
echo "Installing PyYAML into the venv ..."
"$ENV_DIR/bin/python" -m pip install pyyaml
echo "Linking the codesync binary ..."
chmod +x "$HERE/codesync"
mkdir -p "$LOCAL_BIN"
ln -sf "$HERE/codesync" "$BIN_DIR/codesync" # $HOME/.codesync/bin/codesync -> repo
ln -sf "$BIN_DIR/codesync" "$LOCAL_BIN/codesync" # ~/.local/bin/codesync -> the above
echo "Seeding default config at $CONFIG_FILE ..."
mkdir -p "$CONFIG_DIR"
if [ -e "$CONFIG_FILE" ]; then
echo " already exists — leaving it untouched"
else
cp "$HERE/codesync.yaml" "$CONFIG_FILE"
echo " copied from the sample — edit it to define your systems"
fi
# Put ~/.local/bin on PATH via the rc file for the user's shell (idempotent).
case "${SHELL:-}" in
*zsh) RC="$HOME/.zshrc" ;;
*bash) RC="$HOME/.bashrc" ;;
*) RC="$HOME/.profile" ;;
esac
PATH_LINE='export PATH="$HOME/.local/bin:$PATH"'
ADDED_PATH=0
if ! grep -qsF "$PATH_LINE" "$RC"; then
printf '\n# Added by codesync setup — put ~/.local/bin on PATH\n%s\n' "$PATH_LINE" >> "$RC"
ADDED_PATH=1
echo "Added ~/.local/bin to PATH in $RC"
else
echo "~/.local/bin already on PATH via $RC"
fi
cat <<EOF
codesync is installed.
venv: $ENV_DIR
binary: $BIN_DIR/codesync (linked from $LOCAL_BIN/codesync)
config: $CONFIG_FILE
Try it (no venv activation needed — it re-execs into the venv itself):
codesync <system> <location> # push (the default)
codesync pull <system> <location> # remote -> local
EOF
if [ "$ADDED_PATH" = "1" ]; then
echo "Open a new terminal, or run: source $RC (so codesync is on your PATH)"
fi