@@ -711,6 +711,44 @@ function install_binary_as_systemd_service() {
711
711
create_overtls_systemd_service " ${role} " " ${local_bin_file_path} " " ${local_cfg_file_path} "
712
712
}
713
713
714
+ function macos_install_binary_as_service() {
715
+ local role=" ${1} "
716
+ local local_bin_file_path=${2}
717
+ local local_cfg_file_path=${3}
718
+ local svc_daemon_file_path=" ~/Library/LaunchAgents/${service_name} .plist"
719
+
720
+ cat > ${svc_daemon_file_path} << EOF
721
+ <?xml version="1.0" encoding="UTF-8"?>
722
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
723
+ <plist version="1.0">
724
+ <dict>
725
+ <key>Label</key>
726
+ <string>${service_name} </string>
727
+ <key>RunAtLoad</key>
728
+ <true/>
729
+ <key>KeepAlive</key>
730
+ <false/>
731
+ <key>StartInterval</key>
732
+ <integer>3</integer>
733
+ <key>ProgramArguments</key>
734
+ <array>
735
+ <string>${local_bin_file_path} </string>
736
+ <string>-r</string>
737
+ <string>${role} </string>
738
+ <string>-c</string>
739
+ <string>${local_cfg_file_path} </string>
740
+ <string>-d</string>
741
+ </array>
742
+ <key>WorkingDirectory</key>
743
+ <string>/usr/local</string>
744
+ </dict>
745
+ </plist>
746
+ EOF
747
+
748
+ launchctl load ${svc_daemon_file_path}
749
+ launchctl start ${service_name}
750
+ }
751
+
714
752
# Uninstall overtls
715
753
function uninstall_overtls() {
716
754
printf " Are you sure uninstall ${service_name} ? (y/n)\n"
@@ -825,18 +863,35 @@ function main() {
825
863
uninstall_overtls
826
864
;;
827
865
service)
828
- check_root_account
829
866
local role=" ${2} "
830
867
local customer_binary_path=" $3 "
831
868
local customer_cfg_file_path=" $4 "
832
869
check_install_systemd_svc_params " ${role} " " ${customer_binary_path} " " ${customer_cfg_file_path} "
833
- install_binary_as_systemd_service " ${role} " " ${customer_binary_path} " " ${customer_cfg_file_path} "
870
+ if [[ " $( uname) " == " Linux" ]]; then
871
+ check_root_account
872
+ install_binary_as_systemd_service " ${role} " " ${customer_binary_path} " " ${customer_cfg_file_path} "
873
+ elif [[ " $( uname) " == " Darwin" ]]; then
874
+ macos_install_binary_as_service " ${role} " " ${customer_binary_path} " " ${customer_cfg_file_path} "
875
+ else
876
+ echo -e " ${RedBG} Unsupported operating system! ${Font} "
877
+ exit 1
878
+ fi
834
879
;;
835
880
qrcode)
836
881
local svc_bin_path=" ${2} "
837
882
local cfg_path=" ${3} "
838
- check_system
839
- sudo ${INSTALL_CMD} -y install qrencode > /dev/null 2>&1
883
+ if [[ " $( uname) " == " Darwin" ]]; then
884
+ if ! command -v qrencode & > /dev/null ; then
885
+ if ! command -v brew & > /dev/null ; then
886
+ echo -e " ${Info} ${Yellow} Homebrew not found, please install it first! ${Font} "
887
+ exit 1
888
+ fi
889
+ brew install qrencode > /dev/null 2>&1
890
+ fi
891
+ elif [[ " $( uname) " == " Linux" ]]; then
892
+ check_system
893
+ sudo ${INSTALL_CMD} -y install qrencode > /dev/null 2>&1
894
+ fi
840
895
print_qrcode " ${svc_bin_path} " " ${cfg_path} "
841
896
;;
842
897
* )
0 commit comments