diff --git a/package-lock.json b/package-lock.json index 547a947..ed3a361 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6471,9 +6471,9 @@ } }, "node_modules/ip": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", - "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz", + "integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==" }, "node_modules/ipaddr.js": { "version": "1.9.1", @@ -14732,9 +14732,9 @@ "dev": true }, "ip": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", - "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz", + "integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==" }, "ipaddr.js": { "version": "1.9.1", diff --git a/src/public/bash/SCC22TechStack.png b/src/public/bash/SCC22TechStack.png new file mode 100644 index 0000000..edb8539 Binary files /dev/null and b/src/public/bash/SCC22TechStack.png differ diff --git a/src/public/bash/index.html b/src/public/bash/index.html index 49505f5..59cf3da 100644 --- a/src/public/bash/index.html +++ b/src/public/bash/index.html @@ -35,6 +35,7 @@ ## What is Bash? +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+

Shells

+
MacOS
+ +
+
+

Shells

+
Windows
+ +
+
+

Shells

+
Linux
+ +

Unix systems can do

cat /etc/shells

+
+
+ + +
+

POSIX IEEE 1003.1 (2017)

+ +
+ +
+

Most POSIX Compliant Shell

+
+
+
Yash
+ +
+ -
-

- TODO: Entering commands into terminal example example -

-

How programs can be called: firefox, steam, discord, grep

+
+
-

- TODO: Go list what are some commands line by line -

-

cd ls echo/printf

-
- -
-

- TODO: Go list what are some commands line by line CONTD. -

-

cat, other commands we might use in the scripts

-
- -
-

- TODO: Explain how command shells there are: zsh on mac, Powershell and Command Line Prompt on Windows, and Bash, then more alternatives -

-
- - -
- -

POSIX IEEE 1003.1 (2017)

- -
- -
-

- TODO: Funny Yash shell -

+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
@@ -206,8 +724,6 @@ We know the answer is 42, but what is the question?
@@ -257,39 +782,292 @@ if [[ 2 -eq 2 ]]; then # Insert more commands here else # Do otherwise +fi +
+
+

Control Logic

+

And and Or:

+
if [[ "$STRING1" == "$STRING2" && "$STRING1" == "$STRING3" ]]; then
+  printf "%s is equal to both strings" "$STRING1"
+fi
+
+
+

Control Logic

+

And and Or:

+
if [[ "$STRING1" == "$STRING2" || "$STRING1" == "$STRING3" ]]; then
+  printf "%s is equal to either string" "$STRING1"
 fi
-

TODO on these things

-

- - Piping - - If Statement: - - && and || - - For loops: - - How the scripts actually work - - functions, associative arrays, string substition, etc. - - Look at a good cheatsheet -

+
+ +
+
+ +
-

TODO: Give good resources on bash cheatsheets: https://devhints.io/bash

+
+

Writing a Bash Script

+
$ notepad++ script.sh
+
#!/bin/bash
+
+
+

Writing a Bash Script

+
$ notepad++ script.sh
+
#!/usr/bin/env bash
+
+
+

Writing a Bash Script

+
$ notepad++ script.sh
+
#!/usr/bin/env bash
+# Comment1: Today is a good day
+
+echo "Hi there"
+VAR1="21"
+...
+
+
+

Writing a Bash Script

+
$ notepad++ script.sh
+$ bash script.sh
+Hi there
+...
+$
+
#!/usr/bin/env bash
+# Comment1: Today is a good day
+
+echo "Hi there"
+VAR1="21"
+...
+
+
+

Writing a Bash Script

+
$ notepad++ script.sh
+$ chmod +x script.sh
+$ ./script.sh
+Hi there
+...
+$
+
#!/usr/bin/env bash
+# Comment1: Today is a good day
+
+echo "Hi there"
+VAR1="21"
+...
+
+
+

Scripts

+
#!/bin/bash --
+
+
+control='ok'
+
+adddir() {
+  [[ -d $1 ]] || mkdir $1;
+}
+
+add_class() {
+
+  # make the directories for seperate classes
+  adddir Material/$1 && ln -sL ../../Material/$1 Classes/$1/Material
+  adddir Homework/$1 && ln -sL ../../Homework/$1 Classes/$1/Homework
+  adddir Textbooks/$1 && ln -sL ../../Textbooks/$1 Classes/$1/Textbooks
+
+
+  if [[ -f Material/$1/syllabus.pdf ]] then
+    # a little scuffed but looks for regex assuming only 1 will meet
+    ln -sL ../../Material/*yllabus*.pdf Material/$1/syllabus.pdf
+  fi
+}
+
+add_textbook() {
+  book=$(basename $1)
+  class=''
+
+  # Check that Classes is not empty
+  if [[ ! -d Classes/ ]] || [[ ! $(ls Classes/) ]]; then
+    printf 'You are missing some Classes to setup\n'
+    printf 'Please add that first\n'
+    exit
+  fi
+
+  # choose class
+  printf 'Choose a class: \n'
+  printf '     %s\n' $(ls -d Classes/*/ | cut -d \/ -f2) #, funny this prints like a loop for every element of these
+  printf ' : '
+  read -r class
+  if [[ ! -d Classes/$class ]]; then
+    printf 'That is not a class!\n'
+    printf 'Exiting...\n'
+    exit 1;
+  fi
+
+
+  mv -i $1 $HOME/Documents/School/Textbooks/
+  ln -s $HOME/Documents/School/Textbooks/${book} $(pwd -P)/Textbooks/$class/
+}
+
+usage() {
+  printf '%s:
+
+  Usage: %s [-c] [-h] [-t]
+
+  Options:
+    -c    Add a class
+    -h    Show help (this message)
+    -t    Add a textbook. Takes in a textbook, moves to ~/Documents/School/Textbooks
+          and then creates a soft link in the classes Textbook directory.
+          %s -t /path/to/textbook 
+
+' $0 $0 $0
+  exit 1
+}
+
+
+# check you are in the right place
+if [[ $(basename $(dirname $(pwd))) != 'School' ]]; then
+  printf 'You are not in the a Sem/Quarter directory!'
+  usage
+fi
+
+while getopts ":hct:" arg; do
+  case "${arg}" in
+    c) 
+      control=''
+      ;;
+    t) 
+      # give a way to read the next argument
+      if [[ -z ${OPTARG} ]]; then
+        usage
+      fi 
+      add_textbook ${OPTARG}
+      exit 0;
+      ;;
+    h) 
+      usage
+      ;;
+    *)
+      usage
+      ;;
+  esac
+done
+
+# Need to choose classes
+if [[ ! -d Classes/ ]] || [[ $control != 'ok' ]]; then
+  # add the directory if not existent
+  adddir Classes
+
+  # add classes with a prompt
+  printf 'Set a class %s, bro: ' $(whoami)
+  read -r control
+  adddir Classes/$control
+
+  while [[ $control != 'ok' ]]; do
+    printf 'Add another class or say "ok" to finish [ok]: ' 
+    # if read then overwrite control
+    read -r control
+    [[ $control != 'ok' ]] && adddir Classes/$control  
+  done
+
+else
+  printf 'Classes/ already exists. Perhaps you meant to use [-c] flag.\n'
+  usage
+fi
+
+
+# Add the dirs if they are not there yet
+adddir Material
+adddir Homework
+adddir Textbooks
+
+for i in $(ls -d Classes/*/ | cut -d \/ -f2); do
+
+  # check if class hasn't been edited
+  if [[ ! $(ls Classes/$i/) ]]; then
+    printf 'Adding class %s\n' $i
+    add_class $i
+  fi
+
+done
+
+printf 'done'
+
+ +
+
https://devhints.io/bash
+

+ - functions, associative arrays, string substition, etc. + - Look at a good cheatsheet +

+
-

TODO: mild script example 1

+

Simple Info

+
#!/bin/bash
+KERNEL="$(uname -r)"
+MEM="$(free -h | awk '/^Mem:/ {print $2}')"
+
+echo "Hostname: " $HOSTNAME
+echo "Username: " $USER
+echo "Kernel Version: " $KERNEL
+echo "Total Memory: " $MEM
+
-

TODO: mild script example 2

+

Simple Number Comparison

+
#!/bin/bash
+age=18
+if [ "$age" -ge 18 ]; then
+    echo "You are an adult."
+else
+    echo "You are a minor."
+fi
+
-

TODO: mild script example 3

+

Create a zip

+
#!/bin/bash
+backup_dir="/path/to/backup"
+source_dir="/path/to/source"
+zip -r "$backup_dir/$backup_file" "$source_dir"
+
+
+
+

Simple Find and Replace

+
#!/usr/bin/env bash
+# Demo 1
+
+BADNAME="myVar"
+GOODNAME="my_var"
+for i in $(find . -type f); do
+  if [[ "$i" != "./script.sh" ]]; then
+    if grep "$BADNAME"  $i > /dev/null; then
+      echo "Found in the phrase in ${i}";
+      sed -i "s/$BADNAME/$GOODNAME/g" $i > /dev/null;
+    fi
+  fi
+done
+
+
-

TODO: httpd servers

+
+
Http Server
+
$ ls 
+Downloads/  Documents/  Videos/  ...
+
+
+
Http Server
+
$ cd Downloads/
+
+
+
Http Server
+
$ ls 
+Bash-Workshop.jpg  Me-Playing-The-Saxophone.mp3  some-papers/
+
+
+
Http Server
+
$ ip a | grep inet
+inet 127.0.0.1/8 scope host lo
+inet6 ::1/128 scope host proto kernel_lo 
+inet 100.80.134.178/20 brd 100.80.143.255 scope global dynamic noprefixroute wlp2s0
+inet6 fe80::3977:6f8:fbce:e909/64 scope link noprefixroute
+
$ ifconfig a | grep inet
+
+
+
Http Server
+
$ python -m http.server
+Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
+127.0.0.1 - - [12/Mar/2024 10:28:39] "GET / HTTP/1.1" 200 -
+127.0.0.1 - - [12/Mar/2024 10:28:41] "GET /Me-Playing-The-Saxophone.mp3 HTTP/1.1" 200 -
+
-

TODO: wget

+
+
WGet
+

CSE Courses: cseweb.ucsd/classes

+ +
+
+
WGet
+

https://cseweb.ucsd.edu/classes/fa23/cse120-a/

+ +
+
+
WGet
+

https://cseweb.ucsd.edu/classes/fa23/cse120-a/lectures/mem.pdf

+ +
+
+
WGet
+
$ cd Downloads
+$ ls
+Bash-Workshop.jpg  Me-Playing-The-Saxophone.mp3  some-papers
+$ 

+          
+
+
WGet
+
$ cd Downloads
+$ ls
+Bash-Workshop.jpg  Me-Playing-The-Saxophone.mp3  some-papers
+$ wget https://cseweb.ucsd.edu/classes/fa23/cse120-a/lectures/mem.pdf
+
+
+
WGet
+
$ cd Downloads
+$ ls
+Bash-Workshop.jpg  Me-Playing-The-Saxophone.mp3  some-papers
+$ wget https://cseweb.ucsd.edu/classes/fa23/cse120-a/lectures/mem.pdf
+--2024-03-12 11:27:28--  https://cseweb.ucsd.edu/classes/fa23/cse120-a/lectures/mem.pdf
+Resolving cseweb.ucsd.edu (cseweb.ucsd.edu)... 132.239.8.30
+Connecting to cseweb.ucsd.edu (cseweb.ucsd.edu)|132.239.8.30|:443... connected.
+HTTP request sent, awaiting response... 200 OK
+Length: 2497853 (2.4M) [application/pdf]
+Saving to: ‘mem.pdf’
+
+mem.pdf                                                   100%[=====================================================================================================================================>]   2.38M  6.58MB/s    in 0.4s    
+
+2024-03-12 11:27:30 (6.58 MB/s) - ‘mem.pdf’ saved [2497853/2497853]
+$ clear 
+
+
+
WGet
+
$ ls 
+Bash-Workshop.jpg  Me-Playing-The-Saxophone.mp3  mem.pdf  some-papers
+$ 
+
+ +
+
Get CSE Class Slides
+
#!/usr/bin/bash -x 
+location="cseweb.ucsd.edu/classes/fa23/cse120-a/lectures/"
+
+wget -r -np -R "index.html*" https://$location
+class_list=$(ls -rt ./$location)
+
+
+count=1
+for i in $class_list; do
+
+  mv -n ./$location/$i ./${count}_${i}
+  count=$((count + 1))
+
+done
+
+
+rm -rf cseweb.ucsd.edu
+
+
+
-

TODO: combining wget and http to mirror sites

+
+

wget and http server

+ +
+
+

wget and http server

+ +
$ mkdir temp/
+$ cd temp
+$ wget -k -r -p https://supercomputing-club.sdsc.edu/
+
+
+

wget and http server

+ +
$ python -m http.server
+
+
+

wget and http server

+ +
$ python -m http.server
+

Try visiting localhost:8000 if you completed these steps

+
@@ -378,10 +1338,10 @@ API_TOKEN="12345~..." mkdir -p files/ FILES=$( - curl - -X GET + curl \ + -X GET \ -H "Authorization: Bearer $API_TOKEN" \ - https://canvas.ucsd.edu/api/v1/courses/$COURSE_ID/files | + https://canvas.ucsd.edu/api/v1/courses/$COURSE_ID/files | \ jq -r '.[] | "\(.filename),\(.url)"' ) @@ -397,20 +1357,17 @@ echo "Done! All your files are in the 'files/' directory."
@@ -420,64 +1377,31 @@ echo "Done! All your files are in the 'files/' directory." __)|_||_)(/_|(_(_)| | ||_)|_||_|| |(_| | | _| -->
-

TODO: Plug in how bash is essential to supercomputing

+

Bash in Supercomputing

+

Most computers run some Unix derivative

+
+
+

Student Cluster Competition 2022 Tech Stack

-

TODO: Plug in SCC Apps and also our website

+

SCC Applications Coming Soon!

-

TODO: Thank you Slide

+

Our Site

+ https://supercomputing-club.sdsc.edu/ +
-
-

WARNING: Slides after this are just for debugging and messing with layouts,css,js,etc.

+

Thank you

+ https://ieeeucsd.org/ +
+ https://supercomputing-club.sdsc.edu/ +
+ https://www.sdsc.edu/
-
-

Trying to braek the bounds of the perhaps margin on this thing. They contain the maximum size of content for slides.

-
- -
-

Example Script

-
-
#!/bin/bash
-# Descr: Bash Script for Bash Workshop
-printf "Hi, how are you doing?\n"
-
-firefox
-
-wget -k -m -r https://ieeeucsd.org/
-            
-
-
#!/bin/bash
-# Descr: Bash Script for Bash Workshop
-printf "Hi, how are you doing?\n"
-
-firefox
-
-wget -k -m -r https://ieeeucsd.org/
-            
-
-
-
-

HStack Example

-
-
-

One

-

Two

-

Three

-
-
-

One

-

Two

-

Three

-
-
-
- - - - + + diff --git a/src/public/bash/yash.jpg b/src/public/bash/yash.jpg new file mode 100644 index 0000000..7a401ef Binary files /dev/null and b/src/public/bash/yash.jpg differ