-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpython_export.sh
executable file
·44 lines (34 loc) · 1.07 KB
/
python_export.sh
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
#!/bin/bash
# Detect the script's directory (base directory)
BASE_DIR="$(cd "$(dirname "$0")" && pwd)"
# Detect the operating system
OS_NAME="$(uname -s)"
case "$OS_NAME" in
Linux*) OS_FOLDER="linux" ;;
Darwin*) OS_FOLDER="macos" ;; # macOS is identified as Darwin
CYGWIN* | MINGW* | MSYS*) OS_FOLDER="windows" ;; # Windows (Git Bash, Cygwin, MSYS)
*)
echo "Unsupported OS: $OS_NAME"
exit 1
;;
esac
# Set OS-specific directory
OS_DIR="$BASE_DIR/$OS_FOLDER"
mkdir -p "$OS_DIR"
# Move to the Git repository
cd "$BASE_DIR" || exit 1
# Verify it's a Git repo
if [ ! -d ".git" ]; then
echo "Error: Not a Git repository. Initialize or clone a Git repo here."
exit 1
fi
# Export Conda environment
conda env export >"$OS_DIR/environment.yml"
# Export installed Conda packages
conda list --explicit >"$OS_DIR/conda_list.txt"
# Export pip packages
pip freeze >"$OS_DIR/pip_requirements.txt"
# Commit and push to GitHub
git add "$OS_DIR/environment.yml" "$OS_DIR/conda_list.txt" "$OS_DIR/pip_requirements.txt"
git commit -m "Auto backup for $OS_FOLDER: $(date)"
git push