@@ -12,6 +12,8 @@ function check_command() {
1212function check_requirements() {
1313 check_command " awk" " awk is required for parsing the output of commands, please install it." || return 2
1414 check_command " sed" " sed is required for parsing the output of commands, please install it." || return 2
15+ check_command " grep" " grep is required for parsing the output of commands, please install it." || return 2
16+ check_command " tr" " tr is required for parsing the output of commands, please install it." || return 2
1517 check_command " zsh" " zsh is core to WeaponizedVSCode integrated shell." || return 2
1618 check_command " vim" " vim is required for task edit /etc/hosts, please install it or change it." || return 2
1719 check_command " nc" " nc is core for netcat shell session handling or u can't use it, please install it." || return 2
@@ -27,44 +29,92 @@ function check_requirements() {
2729 check_command " uv" " uv is optional but recommended for better performance, install it with 'pip install uv'. Their script is useful"
2830}
2931
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+
3053function main() {
3154 check_requirements
3255 if [[ $? -ne 0 && " $FORCE_INSTALL " != " true" ]]; then
3356 echo " Please install the required commands to continue."
3457 echo " If you want to force install without checking requirements, run the script with FORCE_INSTALL=true ./installer.sh"
3558 exit 1
3659 fi
37-
38- if [[ -z " $WEAPON_LOCATON " ]]; then
60+
61+ if [[ -z " $WEAPON_LOCATION " ]]; then
3962 echo " WEAPON_LOCATION is not set. set to default ~/.local/weapon"
4063 export WEAPON_LOCATION=~ /.local/weapon
4164 echo " You can set it by exporting WEAPON_LOCATION=your_desired_path before running this script."
4265 fi
4366
4467 if [[ -d " $WEAPON_LOCATION " ]]; then
4568 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
4676 exit 0
4777 fi
78+
4879 export LOCATION=" $WEAPON_LOCATION "
4980 echo " Weapon will be installed to $LOCATION , Press Enter key to continue or Ctrl+C to cancel..."
5081 read
5182 echo " Installing Weapon..."
5283 mkdir -p $LOCATION && echo " Weapon directory created at $LOCATION ."
53- cp -f ./createhackenv.sh $LOCATION && echo " createhackenv.sh copied to $LOCATION ."
54- echo " " >> $LOCATION /createhackenv.sh
55- echo " export WEAPON_LOCATION=$LOCATION " >> $LOCATION /createhackenv.sh # overwrite if exists
84+ 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_preformance_tracer.sh ]] && 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."
67-
68117}
69118
70- main " $@ "
119+ args " $@ "
120+ main
0 commit comments