diff --git a/README.md b/README.md index 45b77c6..b640361 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,6 @@ Run the following command in your terminal and then, enter your amFOSS CMS Crede wget https://raw.githubusercontent.com/amfoss/attendance-tracker/master/install.sh -O install.sh ; bash -e install.sh ``` -## For Mac - -You have add your absolute path in 3 places after running the above command -``` -* config -* install.sh -* attendance.py -``` - -To get Absolute path just -```pwd``` - ## Update Your Credentials This should be done whenever you change your password. diff --git a/attendance/attendance.py b/attendance/attendance.py index 5a21723..3a15926 100755 --- a/attendance/attendance.py +++ b/attendance/attendance.py @@ -7,13 +7,15 @@ from urllib.request import urlopen from subprocess import Popen, PIPE from os.path import expanduser +from os import getcwd from sys import platform as _platform - -if _platform == "linux" or _platform == "linux2": +if "linux" in _platform: file_path = "/opt/attendance/" elif _platform == "darwin": - file_path = f"{expanduser('~')}/.attendance/" + file_path = f"/Users/{sys.argv[1]}/.attendance/" +elif "win" in _platform: + file_path = getcwd()+'\\' def get_credentials(): @@ -39,7 +41,11 @@ def check_internet_connection(): def get_wifi_list(): ssid_list = [] - p = Popen([file_path + 'get_ssid_names.sh'], stdin=PIPE, stdout=PIPE, stderr=PIPE) + if "win" in _platform: + p = Popen([file_path + 'get_ssid_names.bat'], stdin=PIPE, stdout=PIPE, stderr=PIPE) + else: + p = Popen([file_path + 'get_ssid_names.sh'], stdin=PIPE, stdout=PIPE, stderr=PIPE) + output, err = p.communicate() output = str(output).split("\\n") if _platform == "darwin": diff --git a/attendance/config b/attendance/config index 4664d6b..0270678 100755 --- a/attendance/config +++ b/attendance/config @@ -10,7 +10,7 @@ case "${unameOut}" in esac if [[ "$machine" = "Mac" ]];then - python3 "$HOME"/.attendance/attendance.py >/tmp/stdout.log 2>/tmp/stderr.log + /usr/local/bin/python3 /Users/"$1"/.attendance/attendance.py "$1" >/tmp/stdout.log 2>/tmp/stderr.log else python3 /opt/attendance/attendance.py &> /opt/attendance/attendance.log diff --git a/attendance/get_ssid_names.bat b/attendance/get_ssid_names.bat new file mode 100644 index 0000000..c9aa6d8 --- /dev/null +++ b/attendance/get_ssid_names.bat @@ -0,0 +1,3 @@ + +set interface=`ip link | findstr -Po '^\d+:\s+\K[^:]+' | findstr 'w'` +netsh %interface% show all | findstr ESSID diff --git a/attendance/get_ssid_names.sh b/attendance/get_ssid_names.sh index 739211a..402df09 100755 --- a/attendance/get_ssid_names.sh +++ b/attendance/get_ssid_names.sh @@ -17,4 +17,4 @@ if [[ "$machine" = "Mac" ]];then else interface=`ip link | grep -Po '^\d+:\s+\K[^:]+' | grep 'w'` sudo iwlist ${interface} scan | grep ESSID -fi \ No newline at end of file +fi diff --git a/install.sh b/install.sh index f3e0ddd..0067bf0 100755 --- a/install.sh +++ b/install.sh @@ -11,10 +11,12 @@ esac # install pip, git and requests if [[ "$machine" = "Mac" ]]; then - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + if [[ $(command -v brew) == "" ]]; then + /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + fi brew install python3 pip3 install requests - readonly attendance_folder_path="$HOME/.attendance" + readonly attendance_folder_path="/Users/$(logname)/.attendance" else sudo apt install python3-pip git -y sudo -H pip3 install requests @@ -35,7 +37,8 @@ sudo cp -r attendance-tracker/attendance/. "$attendance_folder_path"/. sudo chmod +x "$attendance_folder_path"/config "$attendance_folder_path"/get_ssid_names.sh # Add a new cron-job -croncmd="*/1 * * * * ${attendance_folder_path}/config" +username=$(logname) +croncmd="*/1 * * * * ${attendance_folder_path}/config $username" # write out current crontab sudo crontab -l > mycron || touch mycron # echo new cron into cron file if it does not exist, @@ -54,4 +57,4 @@ rm install.sh # fetch creds from user and store them cd "$attendance_folder_path" sudo python3 get_and_save_credentials.py -cd ~ \ No newline at end of file +cd ~