Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
To set up and use the HIL workflows, you must create a GitHub Actions runner on the server. You’ll need higher-level permissions to create the runner, and you should double-check that the runner name matches what’s specified in the workflows.
38 changes: 38 additions & 0 deletions .github/workflows/active-session.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# .github/workflows/update-active-user.yml
name: Active User Script
#when the active_user.sh is updated in the repo it will update the copy on the server
on:
push:
branches:
- main
paths:
- "Show active users/active-sessions.sh"

#allows manual triggering of the workflow
workflow_dispatch:

#replaces the old active_user.sh with the new one in the repo
jobs:
update_script:
runs-on: [self-hosted, linux]

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Deploy active_user.sh
run: |
NEW_SCRIPT_PATH="${{ github.workspace }}/Show active users/active-sessions.sh"
PROFILE_SCRIPT_PATH="/etc/profile.d/active-sessions.sh"

if [ -f "$NEW_SCRIPT_PATH" ]; then
sudo /usr/bin/cp "$NEW_SCRIPT_PATH" "$PROFILE_SCRIPT_PATH"
sudo /usr/bin/chmod +x "$PROFILE_SCRIPT_PATH"
echo "active-sessions.sh updated successfully in $PROFILE_SCRIPT_PATH"
else
echo "Error: active_user.sh not found in repo folder!"
exit 1
fi

- name: Log update
run: echo "active-sessions.sh now runs active_user.sh at login."
39 changes: 39 additions & 0 deletions .github/workflows/create-user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

name: create user script

#when the create_user.sh is updated in the repo it will update the copy on the server
on:
push:
branches:
- main
paths:
- "new user creator/create_user.sh"

#allows manual triggering of the workflow
workflow_dispatch:

#replaces the old create_user.sh with the new one in the repo
jobs:
update_script:
runs-on: [self-hosted, linux]

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Replace local create_user.sh
run: |
NEW_SCRIPT_PATH="${{ github.workspace }}/new user creator/create_user.sh"
LOCAL_SCRIPT_PATH="/usr/local/bin/create_user.sh"

if [ -f "$NEW_SCRIPT_PATH" ]; then
sudo /usr/bin/cp "$NEW_SCRIPT_PATH" "$LOCAL_SCRIPT_PATH"
sudo /usr/bin/chmod +x "$LOCAL_SCRIPT_PATH"
echo "create_user.sh updated successfully in $LOCAL_SCRIPT_PATH"
else
echo "Error: create_user.sh not found in repo folder!"
exit 1
fi

- name: Log update
run: echo "create_user.sh has been replaced with the latest version from the repo."
41 changes: 41 additions & 0 deletions .github/workflows/update-HIL.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

name: Update Local Script

#when the update.sh is updated in the repo it will update the copy on the server
on:
push:
branches:
- main
paths:
- "update hil/update.sh"

#allows manual triggering of the workflow
workflow_dispatch:

#replaces the old update.sh with the new one in the repo
jobs:
update_script:
runs-on: [self-hosted, linux]

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Replace local update.sh
run: |
NEW_SCRIPT_PATH="${{ github.workspace }}/update hil/update.sh"

LOCAL_SCRIPT_PATH="$HOME/update.sh"

if [ -f "$NEW_SCRIPT_PATH" ]; then
cp "$NEW_SCRIPT_PATH" "$LOCAL_SCRIPT_PATH"
chmod +x "$LOCAL_SCRIPT_PATH"
echo "update.sh updated successfully in $HOME"
else
echo "Error: update.sh not found in repo folder 'update hil'!"
exit 1
fi


- name: Log update
run: echo "update.sh has been replaced with the latest version from the repo."
101 changes: 101 additions & 0 deletions New-User-Creator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@

---

## Login User Setup

This is how to setup a special user named **`login`** that automatically runs a user-creation script whenever it is accessed.

---

### 1. Create the `login` User

```bash
sudo adduser login
```

---

### 2. Edit the `.bashrc` File

Open the file:

```bash
sudo nano /home/login/.bashrc
```

At the **bottom** of the file, paste the code that is in the **bashrc.sh** script as shown below.

```bash
echo "Type 'create' to create a new user account, or 'exit' to log out."
read input
if [ "$input" == "create" ]; then
/usr/local/bin/create_user.sh
exit
else
echo "Goodbye!"
exit
fi
```

Save and exit.

---

### 3. Install the `create_user.sh` Script

Place your script in:

```bash
sudo nano /usr/local/bin/create_user.sh
```

Make it executable:

```bash
sudo chmod +x /usr/local/bin/create_user.sh
```

---

### 4. Grant Permissions

Allow the `login` user to run the script and user management commands without a password:

```bash
sudo visudo
```

Add the following line at the bottom:

```bash
login ALL=(root) NOPASSWD: /usr/local/bin/create_user.sh, /usr/sbin/adduser, /usr/sbin/chpasswd
```

Save and exit.

---

### 5. How to Delete a User if Needed

To remove a user and their home directory:

```bash
sudo deluser --remove-home username
```

---

### 6. Access the `login` User

Switch to the `login` account:

```bash
sudo -i
cd /home/login
```

Whenever the `login` user is accessed, the `create_user.sh` script will run automatically.

---


9 changes: 9 additions & 0 deletions New-User-Creator/bashrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
echo "Type 'create' to create a new user account, or 'exit' to log out."
read input
if [ "$input" == "create" ]; then
/usr/local/bin/create_user.sh
exit
else
echo "Goodbye!"
exit
fi
51 changes: 51 additions & 0 deletions New-User-Creator/create_user.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

echo "Creating a new user account..."

# Loop until a valid username is entered
while true; do
read -rp "Please Enter a new username: " newuser

# Check username (allowing lowercase, uppercase, numbers, underscores, and dashes)
if [[ ! "$newuser" =~ ^[A-Za-z_][A-Za-z0-9_-]*$ ]]; then
echo "Invalid username. Use only letters, numbers, underscores, or dashes."
continue
fi

# Check if user already exists
if id "$newuser" &>/dev/null; then
echo "User '$newuser' already exists!"
continue
fi

# If both checks pass, break out of loop
break
done

# Loop until passwords match
while true; do
read -rsp "Enter a password for $newuser: " password
echo
read -rsp "Confirm password: " password2
echo

if [[ "$password" == "$password2" ]]; then
break
else
echo "Passwords do not match. Please try again."
fi
done

# Create user with no initial password
sudo adduser --disabled-password --gecos "" "$newuser" &>/dev/null

# Set the entered password
echo "$newuser:$password" | sudo chpasswd

# Completion messages
echo "User '$newuser' has been created."
echo "Password has been set by the user."
echo "Home directory: /home/$newuser"
echo "You can now SSH using: ssh $newuser@clemsoncure.duckdns.org"

exit
Loading