Skip to content

Commit c38eb75

Browse files
committed
update: performance installer and installer
1 parent bbf869e commit c38eb75

File tree

3 files changed

+63
-5
lines changed

3 files changed

+63
-5
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ install: build
99
WEAPON_LOCATION=$(shell pwd)/weapon_test ./installer.sh
1010
@echo "Installation complete."
1111

12+
install-trace: build
13+
@echo "Preparing the environment with trace..."
14+
WEAPON_LOCATION=$(shell pwd)/weapon_test ./installer.sh --trace-mode
15+
@echo "Installation with trace complete."
16+
1217
clean:
1318
rm -rf ./hosts ./users ./weapon_test ./createhackenv.sh ./zsh_history

installer.sh

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ function check_requirements() {
2929
check_command "uv" "uv is optional but recommended for better performance, install it with 'pip install uv'. Their script is useful"
3030
}
3131

32+
export INSTALL_IDENTIFIER="WeaponizedVSCode installation script. The following commands are generated by WeaponizedVSCode installer."
33+
34+
function args() {
35+
while [[ "$#" -gt 0 ]]; do
36+
case "$1" in
37+
(--trace-mode)
38+
export WEAPON_TRACE_MODE=true
39+
shift
40+
;;
41+
(--force-install)
42+
export WEAPON_FORCE_INSTALL=true
43+
shift
44+
;;
45+
*)
46+
echo "Unknown option: $1"
47+
exit 1
48+
;;
49+
esac
50+
done
51+
}
52+
3253
function main() {
3354
check_requirements
3455
if [[ $? -ne 0 && "$FORCE_INSTALL" != "true" ]]; then
@@ -45,8 +66,16 @@ function main() {
4566

4667
if [[ -d "$WEAPON_LOCATION" ]]; then
4768
echo "Weapon already installed."
69+
if [[ "$WEAPON_FORCE_INSTALL" == "true" ]]; then
70+
echo "Force install mode enabled, removing existing Weapon directory at $WEAPON_LOCATION."
71+
rm -rf "$WEAPON_LOCATION"
72+
else
73+
echo "If you want to reinstall Weapon, please remove the existing directory at $WEAPON_LOCATION or use --force-install option."
74+
exit 0
75+
fi
4876
exit 0
4977
fi
78+
5079
export LOCATION="$WEAPON_LOCATION"
5180
echo "Weapon will be installed to $LOCATION, Press Enter key to continue or Ctrl+C to cancel..."
5281
read
@@ -55,15 +84,37 @@ function main() {
5584
cat ./createhackenv.sh |sed -e "s#__REPLACE__#$LOCATION#g" > $LOCATION/createhackenv.sh && echo "createhackenv.sh copied to $LOCATION."
5685
cp -f ./zsh_history $LOCATION && echo "zsh_history copied to $LOCATION."
5786

58-
grep -zq "source $LOCATION/createhackenv.sh" ~/.zshrc
87+
if [[ "$WEAPON_TRACE_MODE" == "true" ]];then
88+
cp -f ./zsh_preformance_tracer.sh $LOCATION && echo "zsh_performance_tracer is copied to $LOCATION."
89+
fi
90+
91+
grep -zq "${INSTALL_IDENTIFIER}" ~/.zshrc
5992
if [[ $? -eq 0 ]]; then
6093
echo "createhackenv.sh already sourced in ~/.zshrc. sktpping..."
6194
else
6295
echo "Sourcing createhackenv.sh in ~/.zshrc..."
63-
echo "source $LOCATION/createhackenv.sh" >>~/.zshrc
96+
cp ~/.zshrc ~/.zshrc.pre-weaponized-vscode && echo "Backup ~/.zshrc to ~/.zshrc.pre-weaponized-vscode"
97+
98+
if [[ "$WEAPON_TRACE_MODE" == "true" ]]; then
99+
cat<<EOF >> ~/.zshrc
100+
101+
# ${INSTALL_IDENTIFIER}
102+
[[ -f $LOCATION/zsh_preformance_tracer.sh ]] && source $LOCATION/zsh_preformance_tracer.sh && zsh_trace_start
103+
[[ -f $LOCATION/createhackenv.sh ]] && source $LOCATION/createhackenv.sh
104+
[[ -f $LOCATION/zsh_performance_tracer ]] && zsh_trace_end
105+
EOF
106+
else
107+
cat<<EOF >> ~/.zshrc
108+
109+
# ${INSTALL_IDENTIFIER}
110+
[[ -f $LOCATION/createhackenv.sh ]] && source $LOCATION/createhackenv.sh
111+
EOF
112+
fi
113+
64114
fi
65115

66116
echo "Weaponized VSCode installation completed."
67117
}
68118

69-
main "$@"
119+
args "$@"
120+
main

zsh_preformance_tracer.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export WEAPON_TRACE_LOG=/tmp/weapon_trace_log.$$
2+
13
zsh_trace_start() {
24
echo "starting zsh tracing"
35
# set the trace prompt to include seconds, nanoseconds, script name and line number
@@ -11,7 +13,7 @@ zsh_trace_start() {
1113
fi
1214
# save file stderr to file descriptor 3 and redirect stderr (including trace
1315
# output) to a file with the script's PID as an extension
14-
exec 3>&2 2>/tmp/startlog.$$
16+
exec 3>&2 2>$WEAPON_TRACE_LOG
1517
# set options to turn on tracing and expansion of commands contained in the prompt
1618
setopt xtrace prompt_subst
1719
trap 'setopt xtrace' EXIT
@@ -22,7 +24,7 @@ zsh_trace_end() {
2224
unsetopt xtrace
2325
# restore stderr to the value saved in FD 3
2426
exec 2>&3 3>&-
25-
echo "zsh tracing done. See /tmp/startlog.$$"
27+
echo "zsh tracing done. See $WEAPON_TRACE_LOG for details."
2628
trap 'unsetopt xtrace' EXIT
2729
}
2830

0 commit comments

Comments
 (0)