-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpixi-setup.sh
More file actions
executable file
·167 lines (133 loc) · 5.79 KB
/
pixi-setup.sh
File metadata and controls
executable file
·167 lines (133 loc) · 5.79 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env bash
set -o nounset -o errexit -o pipefail
safe_expose_remove() {
environment=$1
executable=$2
if [ -d ${PIXI_HOME}/envs/${environment} ]; then
exposed_exes=$(pixi global list --environment ${environment} | tail -n 3 | head -n 1 | tr ',' '\n')
if [[ " ${exposed_exes[*]} " =~ [[:space:]]${executable}[[:space:]] ]]; then
pixi global expose remove ${executable}
fi
fi
}
export -f safe_expose_remove
install_global_packages() {
package_list=$1
# Check if the directory exists, if not, create an empty list of packages
if [ ! -d ${PIXI_HOME}/envs ]; then
mkdir -p ${PIXI_HOME}/envs
existing_pkgs=""
else
existing_pkgs=$(ls ${PIXI_HOME}/envs 2>/dev/null | sort -u || echo "")
fi
# Use the existing packages or empty string to compare with desired packages
missing_pkgs=$(comm -13 <(echo "$existing_pkgs" | sort -u) <(sort -u ${package_list}))
if (($(echo ${missing_pkgs} | wc -w) > 0 )); then
pixi global install $(echo ${missing_pkgs} | tr '\n' ' ')
fi
}
export -f install_global_packages
inject_packages() {
environment=$1
package_list=$2
# Check if the environment exists before trying to list packages
if [ ! -d ${PIXI_HOME}/envs/${environment} ]; then
missing_pkgs=$(cat ${package_list})
else
missing_pkgs=$(comm -13 <(pixi global list --environment ${environment} | cut -f 1 -d ' ' | head -n -6 | tail -n +3 | sort -u) <(sort -u ${package_list}))
fi
if (( $(echo ${missing_pkgs} | wc -w) > 0 )); then
pixi global install --environment ${environment} $(echo ${missing_pkgs} | tr '\n' ' ')
fi
}
export -f inject_packages
extract_section() {
local file=$1 section=$2
awk "/^# \[${section}\]/{found=1; next} /^# \[/{found=0} found && !/^#/ && NF" "$file"
}
export -f extract_section
# --- Prompt: installation path ---
_default_pixi_home="${HOME}/.pixi"
echo ""
echo "Where should pixi store its environments and packages?"
echo " Default: ${_default_pixi_home}"
echo " NOTE: Home directories have storage quotas. On HPC, prefer VAST over"
echo " GPFS/Lustre for better small-file I/O. e.g. /lab/\$USER/.pixi"
echo ""
read -r -p "Installation path [${_default_pixi_home}]: " _user_pixi_home
export PIXI_HOME="${_user_pixi_home:-${_default_pixi_home}}"
export RATTLER_CACHE_DIR="${PIXI_HOME}/cache"
echo "Using PIXI_HOME=${PIXI_HOME}"
# --- Prompt: install type ---
echo ""
echo "Choose installation type:"
echo " 1) minimal - Essential CLI tools + Python data science + base R"
echo " ~5 GB, ~100k files"
echo " 2) full - Complete bioinformatics environment (samtools, GATK, plink,"
echo " STAR, Seurat, bioconductor packages, etc.)"
echo " ~35 GB, ~350k files"
echo ""
read -r -p "Install type [1=minimal, 2=full, default=1]: " _install_type_input
case "${_install_type_input:-1}" in
2|full) INSTALL_TYPE="full" ;;
*) INSTALL_TYPE="minimal" ;;
esac
echo "Installation type: ${INSTALL_TYPE}"
# Ensure PIXI_HOME exists
mkdir -p "${PIXI_HOME}"
# Install pixi and source it right after installation to move forward
curl -fsSL https://raw.githubusercontent.com/StatFunGen/pixi-setup/main/pixi-install.sh | bash
export PATH="${PIXI_HOME}/bin:${PATH}"
if [[ "${INSTALL_TYPE}" == "minimal" ]]; then
# --- Minimal install ---
_minimal_url="https://raw.githubusercontent.com/StatFunGen/pixi-setup/main/envs/minimal_packages.txt"
_minimal_file=$(mktemp)
curl -fsSL "${_minimal_url}" -o "${_minimal_file}"
install_global_packages <(extract_section "${_minimal_file}" "global")
install_global_packages <(echo "coreutils")
echo "Installing minimal R packages ..."
inject_packages r-base <(extract_section "${_minimal_file}" "r")
echo "Installing minimal Python packages ..."
inject_packages python <(extract_section "${_minimal_file}" "python")
rm -f "${_minimal_file}"
pixi clean cache -y
# Install config files (init.sh handles missing bioconductor packages gracefully)
curl -fsSL https://raw.githubusercontent.com/StatFunGen/pixi-setup/main/init.sh | bash
else
# --- Full install ---
_full_url="https://raw.githubusercontent.com/StatFunGen/pixi-setup/main/envs/full_packages.txt"
_full_file=$(mktemp)
curl -fsSL "${_full_url}" -o "${_full_file}"
install_global_packages <(extract_section "${_full_file}" "global")
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
safe_expose_remove util-linux kill
fi
install_global_packages <(echo "coreutils")
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
safe_expose_remove coreutils kill
safe_expose_remove coreutils uptime
install_global_packages <(extract_section "${_full_file}" "global_linux")
fi
echo "Installing recommended R libraries ..."
inject_packages r-base <(extract_section "${_full_file}" "r")
echo "Installing recommended Python packages ..."
inject_packages python <(extract_section "${_full_file}" "python")
rm -f "${_full_file}"
pixi clean cache -y
# Install config files
curl -fsSL https://raw.githubusercontent.com/StatFunGen/pixi-setup/main/init.sh | bash
fi
# print messages
BB='\033[1;34m'
NC='\033[0m'
if [[ "$OSTYPE" == "darwin"* ]]; then
_shell_config="${HOME}/.zshrc"
else
_shell_config="${HOME}/.bashrc"
fi
echo -e "${BB}Installation completed. Pixi is installed at: ${PIXI_HOME}${NC}"
echo -e "${BB}Note: From now on you can install other R packages as needed with 'pixi global install --environment r-base ...'${NC}"
echo -e "${BB}and Python with 'pixi global install --environment python ...'${NC}"
echo -e "${BB}To keep the package cache in ${PIXI_HOME}/cache across all future sessions,${NC}"
echo -e "${BB}add this line to ${_shell_config}:${NC}"
echo -e "${BB} export RATTLER_CACHE_DIR=\"${PIXI_HOME}/cache\"${NC}"