forked from ThePrimeagen/dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun
More file actions
executable file
·200 lines (157 loc) · 4.46 KB
/
run
File metadata and controls
executable file
·200 lines (157 loc) · 4.46 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/usr/bin/env bash
# I'm sorry... I don't want to do this every time... I just git clone into my home dir...
export DEV_ENV=~/dev
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
if [ -z "$DEV_ENV" ]; then
echo "env var DEV_ENV needs to be present"
exit 1
fi
# Let's make this multi-distro compatible (let's try to be inclusive here)
pkg_mgr_dir=""
# Debian derrivatives
if command -v apt > /dev/null 2>&1; then
pkg_mgr_dir="deb"
# Arch derrivatives
elif command -v pacman > /dev/null 2>&1; then
pkg_mgr_dir="pacman"
# Red Hat derrivatives
elif command -v dnf > /dev/null 2>&1; then
pkg_mgr_dir=="dnf"
# Older Red Hat derrivatives
elif command -v yum > /dev/null 2>&1; then
pkg_mgr_dir="yum"
# OpenSUSE derrivatives
elif command -v zypper > /dev/null 2>&1; then
pkg_mgr_dir="zypper"
# Alpine derrivatives
elif command -v apk > /dev/null 2>&1; then
pkg_mgr_dir="apk"
# Gentoo derrivatives
elif command -v emerge > /dev/null 2>&1; then
pkg_mgr_dir="emerge"
# Slackware derrivatives
elif command -v slackpkg > /dev/null 2>&1; then
pkg_mgr_dir="slackpkg"
# Void derrivatives
elif command -v xbps > /dev/null 2>&1; then
pkg_mgr_dir="xbps"
# NixOS derrivatives
elif command -v nix > /dev/null 2>&1; then
pkg_mgr_dir="nix"
# BSD/Unix/Solaris derrivatives
elif command -v pkg > /dev/null 2>&1; then
pkg_mgr_dir="pkg"
# Other BSD derrivatives
elif command -v ports > /dev/null 2>&1; then
pkg_mgr_dir="ports"
# Another BSD derrivatives
elif command -v pkgsrc > /dev/null 2>&1; then
pkg_mgr_dir="pkgsrc"
# MacOS/Linux derrivatives
elif command -v brew > /dev/null 2>&1; then
pkg_mgr_dir="brew"
# Freedom derrivatives
elif command -v guix > /dev/null 2>&1; then
pkg_mgr_dir="guix"
else
log "ERROR: Could not determine a supported package manager."
log "Pease create a subdirectory in $script_dir/runs/ for your package manager and update this file."
exit 1
fi
log "Detected package manager type: $pkg_mgr_dir. Scripts will be sourced from runs/$pkg_mgr_dir/"
target_runs_subdir="runs/$pkg_mgr_dir"
runs_dir="$script_dir/$target_runs_subdir"
if [ ! -d "$runs_dir" ]; then
log "ERROR: Directory $runs_dir does not exist."
log "Please create it and add your package manager scripts there."
exit 1;
fi
# --- Parse Arguments ---
grep=""
dry_run="0"
while [[ $# -gt 0 ]]; do
echo "ARG: \"$1\""
if [[ "$1" == "--dry" ]]; then
dry_run="1"
else
grep="$1"
fi
shift
done
executable_scripts=$(find "$runs_dir" -mindepth 1 -maxdepth 1 -type f -executable)
# If there is no grep pattern
if [ -z "$grep" ]; then
log "No specific script pattern provided, running all scripts in alphabetical order"
for script in $executable_scripts; do
full_path="$runs_dir/$script"
if [ -f "$full_path" ] && [ -x "$full_path" ]; then
log "Running script: $full_path"
if [ "$dry_run" = "0" ]; then
"$full_path"
fi
else
log "Script $full_path not found or not executable in '$target_runs_subdir'. Skipping."
fi
done
else
log "Specific script pattern '$grep_pattern' provided. Searching in '$target_runs_subdir':"
found_match=0
for script in $executable_scripts; do
if basename $script | grep -vq "$grep"; then
log "grep \"$grep\" filtered out $script"
continue
fi
log "running script: $script"
if [ "$dry_run" = "0" ]; then
"$script"
fi
done
fi
log() {
if [ "$dry_run" == "1" ]; then
echo "[DRY_RUN]: $1"
else
echo "$1"
fi
}
remove_files() {
pushd $1
(
configs=`find . -mindepth 1 -maxdepth 1 -type d`
if [ "$dry_run" == "1" ]; then
echo "[DRY_RUN]: removing: $configs"
else
echo "removing: $configs"
fi
for c in $configs; do
directory=${2%/}/${c}
if [ "$dry_run" == "1" ]; then
echo "[DRY_RUN]: removing: $directory"
else
echo " removing: $directory"
rm -rf $directory
fi
done
if [ "$dry_run" == "1" ]; then
echo "copying env: $2"
else
echo "copying env: $2"
cp -r ./* $2
fi
)
popd
}
run_env() {
pushd $script_dir
echo "removing ~config"
remove_files env/.config $XDG_CONFIG_HOME
echo "removing ~local"
remove_files env/.local $HOME/.local
echo "copying zsh"
if [ "$dry_run" == "0" ]; then
cp $script_dir/env/.zshrc ~/.zshrc
cp $script_dir/env/.zsh_profile ~/.zsh_profile
fi
popd
}
run_env