-
Notifications
You must be signed in to change notification settings - Fork 3
Voldigate dev #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Voldigate dev #32
Changes from all commits
20355d6
074ced9
00b90f6
669a65a
7b9d451
1821540
f3212c2
f0dd1fa
cfd4e3b
0a9ca69
47bc0c6
2502e95
d9c2750
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 31.1.3 | ||
| 32.0.0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,13 @@ | ||
| [Unit] | ||
| Description=Check Wired Wombat Connection Service | ||
|
|
||
| After=network.target | ||
| # This ensures the network is up before the script runs (optional) | ||
| Description=Check Wired Wombat Connection | ||
| After=NetworkManager.service | ||
| Wants=NetworkManager.service | ||
|
|
||
| [Service] | ||
| ExecStart=/home/kipr/wombat-os/configFiles/checkWombatWiredConnect.sh | ||
| ExecStart=/home/kipr/wombat-os/configFiles/checkWombatWiredConnect_temp.sh | ||
| Restart=always | ||
| # Optional: to automatically restart the service if it fails | ||
| User=root | ||
| # Optional: run the service as the 'pi' user (or your user) | ||
| Group=kipr | ||
| WorkingDirectory=/usr/local/bin | ||
| # Optional: set the working directory for the script | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| WantedBy=multi-user.target | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #!/bin/bash | ||
|
|
||
| WIRED_CONN="wired_wombat" | ||
| ETH_IF="eth0" | ||
| STATIC_IP="192.168.124.1/24" | ||
| DHCP_SERVICE="udhcpd" | ||
|
|
||
| # Ensure wired connection profile exists | ||
| if ! nmcli connection show | grep -q "$WIRED_CONN"; then | ||
| echo "$(date) - Creating wired connection profile..." | ||
| nmcli connection add type ethernet con-name "$WIRED_CONN" ifname "$ETH_IF" ipv4.method manual ipv4.addresses "$STATIC_IP" ipv4.gateway "$STATIC_IP" | ||
| nmcli connection modify "$WIRED_CONN" connection.autoconnect no | ||
| fi | ||
|
|
||
| while true; do | ||
| # Check if Ethernet cable is plugged in | ||
| if ethtool "$ETH_IF" 2>/dev/null | grep -q "Link detected: yes"; then | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line can be replaced by a simple if [ "$(cat /sys/class/net/eth0/link_mode)" -eq "1" ]; then |
||
| echo "$(date) - Ethernet detected, bringing up $WIRED_CONN" | ||
|
|
||
| # Bring up wired connection | ||
| nmcli connection up "$WIRED_CONN" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this I would suggest adding a stamp file somewhere to indicate which state it's in and checking that first to determine if you need to run the rest of this |
||
|
|
||
| # Wait until the interface has the correct IP | ||
| while ! ip -4 addr show "$ETH_IF" | grep -q "${STATIC_IP%/*}"; do | ||
| echo "$(date) - Waiting for $ETH_IF to get IP $STATIC_IP..." | ||
| sleep 1 | ||
| done | ||
|
|
||
| echo "$(date) - $ETH_IF is up with IP $STATIC_IP, starting DHCP..." | ||
| sudo systemctl restart "$DHCP_SERVICE" | ||
|
|
||
| else | ||
| echo "$(date) - Ethernet not detected, bringing down $WIRED_CONN" | ||
|
|
||
| # Bring down wired connection | ||
| nmcli connection down "$WIRED_CONN" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as other issue, this block doesn't seem like it needs to be re-run constantly. |
||
|
|
||
| # Stop DHCP server | ||
| sudo systemctl stop "$DHCP_SERVICE" | ||
| fi | ||
|
|
||
| # Check every 5 seconds | ||
| sleep 5 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you are already managing this script with |
||
| done | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| nodeLinker: node-modules | ||
|
|
||
| yarnPath: .yarn/releases/yarn-4.9.1.cjs |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| #!/bin/bash | ||
| shopt -s nullglob | ||
| LOGFILE="/home/kipr/voldigate_update.log" | ||
|
|
||
| sudo touch "$LOGFILE" | ||
| sudo chmod 666 "$LOGFILE" | ||
|
|
||
| >"$LOGFILE" | ||
|
|
||
| exec &> >(tee -a "$LOGFILE") | ||
|
|
||
| OLD_USER_JSON="/home/kipr/Documents/KISS/users.json" | ||
| NEW_USER_JSON="/home/kipr/Documents/KISS/newUsers.json" | ||
| HOME_DIR="/home/kipr/Documents/KISS" | ||
| SCRIPT_DIR="$(dirname "$0")" | ||
| #JQ="../pkgs/jq-linux64" #jq-linux64 testing on computer, pkgs/jq-linux-arm64 for pi once ready | ||
| sudo cp ../pkgs/jq-linux-arm64 /usr/local/bin/jq | ||
| sudo chmod +x /usr/local/bin/jq | ||
| JQ=/usr/local/bin/jq | ||
| # Get all directories stored in /home/kipr/Documents/KISS - Users | ||
| for dir in "$HOME_DIR"/*; do | ||
| if [ -d "$dir" ]; then | ||
| userName=$(basename "$dir") | ||
|
|
||
| # Skip the 'classrooms' folder | ||
| if [ "$userName" = "classrooms" ]; then | ||
| continue | ||
| fi | ||
|
|
||
| userPath_array+=("$dir") | ||
| user_array+=("$userName") | ||
| fi | ||
| done | ||
|
|
||
|
|
||
| #New voldigate structure for users.json | ||
| voldigateJson=$(printf '%s\n' "${user_array[@]}" | "$JQ" -Rn ' | ||
| [inputs] | reduce .[] as $item ({}; .[$item] = {}) | ||
| ') | ||
|
|
||
| #Make sure current users.json doesn't have trailing , (v31.1.2) | ||
| perl -pe 's/,\s*}/}/g' /home/kipr/Documents/KISS/users.json \ | ||
| | "$JQ" . > /home/kipr/Documents/KISS/users.json.fixed | ||
|
|
||
| sudo mv /home/kipr/Documents/KISS/users.json.fixed /home/kipr/Documents/KISS/users.json | ||
|
|
||
| echo "Fixed users.json: $(< /home/kipr/Documents/KISS/users.json)" | ||
|
|
||
| #Read old users.json to get user interface | ||
| oldUsersJson=$(cat "$OLD_USER_JSON") | ||
|
|
||
| # Iterate users and collect projects safely | ||
| for userPath in "${userPath_array[@]}"; do | ||
| userName=$(basename "$userPath") | ||
| projects_json_list=() | ||
| userMode=$(echo "$oldUsersJson" | jq -r --arg uname "$userName" '.[$uname].mode') | ||
|
|
||
| echo "oldUsers[$userName].mode: $userMode" | ||
| for projDir in "$userPath"/*; do | ||
| [ -d "$projDir" ] || continue | ||
| projectName=$(basename "$projDir") | ||
|
|
||
| # Collect files in subdirectories | ||
| includeFiles=() | ||
| srcFiles=() | ||
| dataFiles=() | ||
| projectLanguage="" | ||
| for subDir in "$projDir"/*; do | ||
| [ -d "$subDir" ] || continue | ||
| subDirName=$(basename "$subDir") | ||
| case "$subDirName" in | ||
| "include") | ||
| for f in "$subDir"/*; do | ||
| [ -f "$f" ] || continue | ||
| includeFiles+=("$(basename "$f")") | ||
| done | ||
| ;; | ||
| "src") | ||
| for f in "$subDir"/*; do | ||
| [ -f "$f" ] || continue | ||
| filename=$(basename "$f") | ||
| [ "$filename" = "xmlToC.c" ] && continue # skip this file | ||
| # Detect main.* and extract the extension as projectLanguage | ||
| if [[ "$filename" == main.* ]]; then | ||
| ext="${filename##*.}" | ||
| projectLanguage="$ext" | ||
| fi | ||
| srcFiles+=("$filename") | ||
| done | ||
| ;; | ||
| "data") | ||
| for f in "$subDir"/*; do | ||
| [ -f "$f" ] || continue | ||
| dataFiles+=("$(basename "$f")") | ||
| done | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [ ${#includeFiles[@]} -gt 0 ]; then | ||
| includeJSON=$(printf '%s\n' "${includeFiles[@]}" | "$JQ" -R . | "$JQ" -s .) | ||
| else | ||
| includeJSON='[]' | ||
| fi | ||
|
|
||
| if [ ${#srcFiles[@]} -gt 0 ]; then | ||
| srcJSON=$(printf '%s\n' "${srcFiles[@]}" | "$JQ" -R . | "$JQ" -s .) | ||
| else | ||
| srcJSON='[]' | ||
| fi | ||
|
|
||
| if [ ${#dataFiles[@]} -gt 0 ]; then | ||
| dataJSON=$(printf '%s\n' "${dataFiles[@]}" | "$JQ" -R . | "$JQ" -s .) | ||
| else | ||
| dataJSON='[]' | ||
| fi | ||
|
|
||
| # Build project JSON | ||
| project_json=$("$JQ" -n \ | ||
| --arg projectName "$projectName" \ | ||
| --arg projectLanguage "$projectLanguage" \ | ||
| --argjson include "$includeJSON" \ | ||
| --argjson src "$srcJSON" \ | ||
| --argjson data "$dataJSON" \ | ||
| '{ | ||
| projectName: $projectName, | ||
| projectLanguage: $projectLanguage, | ||
| includeFolderFiles: $include, | ||
| srcFolderFiles: $src, | ||
| dataFolderFiles: $data | ||
| }') | ||
|
|
||
| echo "$project_json" >"$projDir/.project.config.json" | ||
| projects_json_list+=("$project_json") | ||
| done | ||
|
|
||
| # Combine all projects into a JSON array | ||
| all_projects_json=$(printf '%s\n' "${projects_json_list[@]}" | "$JQ" -s .) | ||
|
|
||
| #Create .user.config.json that belongs in the User's root folder | ||
| userConfigJson=$("$JQ" -n \ | ||
| --arg user "$userName" \ | ||
| --argjson projects "$all_projects_json" \ | ||
| --argjson oldUsers "$oldUsersJson" \ | ||
| '{ | ||
| userName: $user, | ||
| interfaceMode: ($oldUsers[$user].mode // "Simple"), | ||
| projects: $projects, | ||
| classroomName: null | ||
| }') | ||
|
|
||
| echo "$userConfigJson" >"$userPath/.user.config.json" | ||
|
|
||
| # Inject into the Voldigate JSON | ||
| voldigateJson=$( | ||
| echo "$voldigateJson" | "$JQ" \ | ||
| --arg user "$userName" \ | ||
| --argjson oldUsers "$oldUsersJson" \ | ||
| --argjson projs "$all_projects_json" \ | ||
| '.[$user] += { | ||
| userName: $user, | ||
| interfaceMode: ($oldUsers[$user].mode // "Simple"), | ||
| projects: $projs, | ||
| classroomName: null | ||
| }' | ||
| ) | ||
|
|
||
| done | ||
|
|
||
| # Output final JSON | ||
| echo "$voldigateJson" >"$NEW_USER_JSON" | ||
|
|
||
| if [ -f "$NEW_USER_JSON" ]; then | ||
| echo "Successfully created $NEW_USER_JSON" | ||
| cat "$NEW_USER_JSON" > "$OLD_USER_JSON" | ||
| rm "$NEW_USER_JSON" | ||
| else | ||
| echo "Failed to create $NEW_USER_JSON" | ||
| exit 1 | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This filename is incorrect. Did you mean
/home/kipr/wombat-os/configFiles/checkWombatWiredConnection_temp.sh?