Skip to content
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

brightness control(xorg) , Auto login DM, Bootable pendrive maker script, auto power profiling using auto-cpufreq, timeshift backup, samba-ssh server setup #465

Merged
merged 22 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
418cb9d
added auto-login
guruswarupa Sep 18, 2024
0b8a649
added pendrive maker script
guruswarupa Sep 18, 2024
4bb3ba5
added power profile script
guruswarupa Sep 18, 2024
d99d26d
added timeshift backup script
guruswarupa Sep 18, 2024
71beabd
set brightness monitor scontrol script
guruswarupa Sep 18, 2024
ea9d6d7
samba ssh setup script added
guruswarupa Sep 18, 2024
6cbba30
Update tabs/utils/tab_data.toml
guruswarupa Sep 18, 2024
60405aa
Update tabs/system-setup/5-samba-ssh-setup.sh
guruswarupa Sep 18, 2024
1d59a55
Update tabs/utils/auto-login.sh
guruswarupa Sep 18, 2024
1b0b9bb
Update tabs/system-setup/5-samba-ssh-setup.sh
guruswarupa Sep 18, 2024
0d7213d
Update tabs/utils/auto-login.sh
guruswarupa Sep 18, 2024
8fdb105
Update tabs/utils/auto-login.sh
guruswarupa Sep 18, 2024
6646c4d
Update tabs/utils/auto-login.sh
guruswarupa Sep 18, 2024
d0ccb23
Update tabs/utils/auto-login.sh
guruswarupa Sep 18, 2024
dc26890
Update tabs/system-setup/5-samba-ssh-setup.sh
guruswarupa Sep 18, 2024
d30ba11
Update tabs/system-setup/5-samba-ssh-setup.sh
guruswarupa Sep 18, 2024
59fafbb
Update tabs/system-setup/5-samba-ssh-setup.sh
guruswarupa Sep 18, 2024
28ee76b
Update tabs/system-setup/5-samba-ssh-setup.sh
ChrisTitusTech Sep 18, 2024
7f28646
Update tabs/utils/monitor-control/set_brightness.sh
ChrisTitusTech Sep 18, 2024
3f6209e
Update tabs/utils/monitor-control/set_brightness.sh
ChrisTitusTech Sep 18, 2024
60d4d4b
Remove bashisms
ChrisTitusTech Sep 18, 2024
46a9d57
Merge branch 'main' into main
ChrisTitusTech Sep 18, 2024
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
205 changes: 205 additions & 0 deletions tabs/system-setup/5-samba-ssh-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
#!/bin/sh -e

# Load common script functions
. ../common-script.sh

# Function to install packages based on the package manager
install_package() {
PACKAGE=$1
if ! command_exists "$PACKAGE"; then
case "$PACKAGER" in
pacman)
$ESCALATION_TOOL "$PACKAGER" -S --noconfirm "$PACKAGE"
;;
*)
$ESCALATION_TOOL "$PACKAGER" install -y "$PACKAGE"
;;
esac
else
echo "$PACKAGE is already installed."
fi
}

# Function to setup and configure SSH
setup_ssh() {
printf "%b\n" "${YELLOW}Setting up SSH...${RC}"

# Detect package manager and install appropriate SSH package
case "$PACKAGER" in
"apt-get")
install_package openssh-server
SSH_SERVICE="ssh"
;;
"pacman")
install_package openssh
SSH_SERVICE="sshd"
;;
*)
install_package openssh-server
SSH_SERVICE="sshd"
;;
esac

# Enable and start the appropriate SSH service
$ESCALATION_TOOL systemctl enable "$SSH_SERVICE"
$ESCALATION_TOOL systemctl start "$SSH_SERVICE"

# Get the local IP address
LOCAL_IP=$(ip -4 addr show | awk '/inet / {print $2}' | tail -n 1)

printf "%b\n" "${GREEN}Your local IP address is: $LOCAL_IP${RC}"
guruswarupa marked this conversation as resolved.
Show resolved Hide resolved

# Check if SSH is running
if systemctl is-active --quiet "$SSH_SERVICE"; then
printf "%b\n" "${GREEN}SSH is up and running.${RC}"
else
printf "%b\n" "${RED}Failed to start SSH.${RC}"
fi
}

# Function to setup and configure Samba
setup_samba() {
printf "%b\n" "${YELLOW}Setting up Samba...${RC}"

# Install Samba if not installed
install_package samba

SAMBA_CONFIG="/etc/samba/smb.conf"

if [ -f "$SAMBA_CONFIG" ]; then
printf "%b\n" "${YELLOW}Samba configuration file already exists in $SAMBA_CONFIG.${RC}"
echo "Do you want to modify the existing Samba configuration? (yes/no): "
read MODIFY_SAMBA
if [ "$MODIFY_SAMBA" = "yes" ]; then
"$ESCALATION_TOOL" "$EDITOR" "$SAMBA_CONFIG"
fi
else
printf "%b\n" "${YELLOW}No existing Samba configuration found. Setting up a new one...${RC}"

# Prompt user for shared directory path
echo "Enter the path for the Samba share (default: /srv/samba/share): "
read -r SHARED_DIR
SHARED_DIR=${SHARED_DIR:-/srv/samba/share}

# Create the shared directory if it doesn't exist
$ESCALATION_TOOL mkdir -p "$SHARED_DIR"
$ESCALATION_TOOL chmod -R 0777 "$SHARED_DIR"

# Add a new Samba user
echo "Enter Samba username: "
read -r SAMBA_USER

# Loop until the passwords match
while true; do
echo "Enter Samba password: "
stty -echo
read -r SAMBA_PASSWORD
stty echo
echo "Confirm Samba password: "
stty -echo
read SAMBA_PASSWORD_CONFIRM
stty echo
echo ""
if [ "$SAMBA_PASSWORD" = "$SAMBA_PASSWORD_CONFIRM" ]; then
printf "%b\n" "${GREEN}Passwords match.${RC}"
break
else
printf "%b\n" "${RED}Passwords do not match. Please try again.${RC}"
fi
done

# Add the user and set the password
$ESCALATION_TOOL smbpasswd -a "$SAMBA_USER"

# Configure Samba settings
$ESCALATION_TOOL sh -c "cat > $SAMBA_CONFIG" <<EOL
[global]
workgroup = WORKGROUP
server string = Samba Server
security = user
map to guest = bad user
dns proxy = no

[Share]
path = $SHARED_DIR
browsable = yes
writable = yes
guest ok = no
read only = no
EOL
fi

# Enable and start Samba services
$ESCALATION_TOOL systemctl enable smb nmb
$ESCALATION_TOOL systemctl start smb nmb

# Check if Samba is running
if systemctl is-active --quiet smb && systemctl is-active --quiet nmb; then
printf "%b\n" "${GREEN}Samba is up and running.${RC}"
printf "%b\n" "${YELLOW}Samba share available at: $SHARED_DIR${RC}"
else
printf "%b\n" "${RED}Failed to start Samba.${RC}"
fi
}

# Function to configure firewall (optional)
configure_firewall() {
printf "%b\n" "${BLUE}Configuring firewall...${RC}"

if command_exists ufw; then
$ESCALATION_TOOL ufw allow OpenSSH
$ESCALATION_TOOL ufw allow Samba
$ESCALATION_TOOL ufw enable
printf "%b\n" "${GREEN}Firewall configured for SSH and Samba.${RC}"
else
printf "%b\n" "${YELLOW}UFW is not installed. Skipping firewall configuration.${RC}"
fi
}

setup_ssh_samba(){
echo "Samba and SSH Setup Script"
echo "----------------------------"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "----------------------------"
printf "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\n"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
echo "----------------------------"
printf "\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\n"

clear

# Display menu
echo "Select an option:"
echo "1. Setup SSH"
echo "2. Setup Samba"
echo "3. Configure Firewall"
echo "4. Setup All"
echo "5. Exit"

echo "Enter your choice [1-5]: "
read CHOICE

case "$CHOICE" in
1)
setup_ssh
;;
2)
setup_samba
;;
3)
configure_firewall
;;
4)
setup_ssh
setup_samba
configure_firewall
;;
5)
printf "%b\n" "${GREEN}Exiting.${RC}"
exit 0
;;
*)
printf "%b\n" "${RED}Invalid choice. Please enter a number between 1 and 5.${RC}"
exit 1
;;
esac

printf "%b\n" "${GREEN}Setup completed.${RC}"
}

checkEnv
checkEscalationTool
setup_ssh_samba
4 changes: 4 additions & 0 deletions tabs/system-setup/tab_data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ script = "3-global-theme.sh"
[[data]]
name = "Remove Snaps"
script = "4-remove-snaps.sh"

[[data]]
name = "SSH-Samba Setup"
script = "5-samba-ssh-setup.sh"
179 changes: 179 additions & 0 deletions tabs/utils/auto-login.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#!/bin/sh -e

. ../common-script.sh

# Function to list common session options
list_sessions() {
echo "Select the session:"
echo "1) GNOME (gnome.desktop)"
echo "2) KDE Plasma (plasma.desktop)"
echo "3) XFCE (xfce.desktop)"
echo "4) LXDE (LXDE.desktop)"
echo "5) LXQt (lxqt.desktop)"
echo "6) Cinnamon (cinnamon.desktop)"
echo "7) MATE (mate.desktop)"
echo "8) Openbox (openbox.desktop)"
echo "9) i3 (i3.desktop)"
echo "10) Custom session"
echo "Enter your choice [1-10]: "
read session_choice

case "$session_choice" in
1) session="gnome.desktop" ;;
2) session="plasma.desktop" ;;
3) session="xfce.desktop" ;;
4) session="LXDE.desktop" ;;
5) session="lxqt.desktop" ;;
6) session="cinnamon.desktop" ;;
7) session="mate.desktop" ;;
8) session="openbox.desktop" ;;
9) session="i3.desktop" ;;
10)
echo "Enter custom session name (e.g., mysession.desktop): "
read -r session ;;
*)
echo "Invalid option selected."
exit 1 ;;
esac
}

# Function to configure LightDM
configure_lightdm() {
echo "Configuring LightDM for autologin..."

echo "Enter username for LightDM autologin: "
read -r user

$ESCALATION_TOOL "echo '[Seat:*]' > /etc/lightdm/lightdm.conf.d/50-autologin.conf"
$ESCALATION_TOOL "echo 'autologin-user=$user' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"
$ESCALATION_TOOL "echo 'autologin-user-timeout=0' >> /etc/lightdm/lightdm.conf.d/50-autologin.conf"

echo "LightDM has been configured for autologin."
}

# Function to remove LightDM autologin
remove_lightdm_autologin() {
echo "Removing LightDM autologin configuration..."
$ESCALATION_TOOL rm -f /etc/lightdm/lightdm.conf.d/50-autologin.conf
echo "LightDM autologin configuration has been removed."
}

# Function to configure GDM
configure_gdm() {
echo "Configuring GDM for autologin..."

echo "Enter username for GDM autologin: "
read -r user

$ESCALATION_TOOL "echo '[daemon]' > /etc/gdm/custom.conf"
$ESCALATION_TOOL "echo 'AutomaticLoginEnable = true' >> /etc/gdm/custom.conf"
$ESCALATION_TOOL "echo 'AutomaticLogin = $user' >> /etc/gdm/custom.conf"

echo "GDM has been configured for autologin."
}

# Function to remove GDM autologin
remove_gdm_autologin() {
echo "Removing GDM autologin configuration..."
$ESCALATION_TOOL sed -i '/AutomaticLoginEnable/d' /etc/gdm/custom.conf
$ESCALATION_TOOL sed -i '/AutomaticLogin/d' /etc/gdm/custom.conf
echo "GDM autologin configuration has been removed."
}

# Function to configure SDDM
configure_sddm() {
echo "Configuring SDDM for autologin..."

echo "Enter username for SDDM autologin: "
read -r user
list_sessions # Show session options

$ESCALATION_TOOL "echo '[Autologin]' > /etc/sddm.conf"
$ESCALATION_TOOL "echo 'User=$user' >> /etc/sddm.conf"
$ESCALATION_TOOL "echo 'Session=$session' >> /etc/sddm.conf"

echo "SDDM has been configured for autologin."
}

# Function to remove SDDM autologin
remove_sddm_autologin() {
echo "Removing SDDM autologin configuration..."
$ESCALATION_TOOL sed -i '/\[Autologin\]/,+2d' /etc/sddm.conf
echo "SDDM autologin configuration has been removed."
}

# Function to configure LXDM
configure_lxdm() {
echo "Configuring LXDM for autologin..."

echo "Enter username for LXDM autologin: "
read -r user
list_sessions # Show session options

$ESCALATION_TOOL sed -i "s/^#.*autologin=.*$/autologin=${user}/" /etc/lxdm/lxdm.conf
$ESCALATION_TOOL sed -i "s|^#.*session=.*$|session=/usr/bin/${session}|; s|^session=.*$|session=/usr/bin/${session}|" /etc/lxdm/lxdm.conf

echo "LXDM has been configured for autologin."
}

# Function to remove LXDM autologin
remove_lxdm_autologin() {
echo "Removing LXDM autologin configuration..."
$ESCALATION_TOOL sed -i "s/^autologin=.*$/#autologin=/" /etc/lxdm/lxdm.conf
$ESCALATION_TOOL sed -i "s/^session=.*$/#session=/" /etc/lxdm/lxdm.conf
echo "LXDM autologin configuration has been removed."
}

# Function to configure or remove autologin based on user choice
configure_or_remove_autologin() {
echo "Do you want to add or remove autologin?"
echo "1) Add autologin"
echo "2) Remove autologin"
echo "Enter your choice [1-2]: "
read action_choice

if [ "$action_choice" = "1" ]; then
echo "Choose the display manager to configure:"
echo "1) LightDM"
echo "2) GDM"
echo "3) SDDM"
echo "4) LXDM"
echo "Enter your choice [1-4]: "
read choice

case "$choice" in
1) configure_lightdm ;;
2) configure_gdm ;;
3) configure_sddm ;;
4) configure_lxdm ;;
*) echo "Invalid option selected." ;;
esac
elif [ "$action_choice" = "2" ]; then
echo "Choose the display manager to remove autologin:"
echo "1) LightDM"
echo "2) GDM"
echo "3) SDDM"
echo "4) LXDM"
echo "Enter your choice [1-4]: "
read choice

case "$choice" in
1) remove_lightdm_autologin ;;
2) remove_gdm_autologin ;;
3) remove_sddm_autologin ;;
4) remove_lxdm_autologin ;;
*) echo "Invalid option selected." ;;
esac
else
echo "Invalid choice. Exiting..."
exit 1
fi

echo "Action completed. Exiting..."
exit 0
}


checkEnv
checkEscalationTool
configure_or_remove_autologin
Loading