create
This commit is contained in:
commit
2af5e250a2
10
README.md
Normal file
10
README.md
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
Run:
|
||||||
|
|
||||||
|
curl -H "Authorization: token READ_REPOSITORY_ACCESS_TOKEN" -O https://git.rozenlab.com/api/v1/repos/leo/server-init/raw/init.sh?ref=master && sudo bash init.sh && rm init.sh
|
||||||
|
|
||||||
|
curl -H "Authorization: token READ_REPOSITORY_ACCESS_TOKEN" -O https://git.rozenlab.com/api/v1/repos/leo/server-init/raw/samba.sh?ref=master && sudo bash samba.sh SAMBA_USER SAMBA_PASSWORD && rm samba.sh
|
||||||
|
|
||||||
|
|
||||||
|
**git**
|
||||||
|
git remote add server-init https://git.rozenlab.com/Leo/server-init.git
|
||||||
|
git add -A && git commit -m "changes" && git push server-init master
|
||||||
27
init.sh
Normal file
27
init.sh
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "This script requires superuser rights. Running with sudo..."
|
||||||
|
exec sudo "$0" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
apt update -y
|
||||||
|
apt upgrade -y
|
||||||
|
apt install -y apt-transport-https ca-certificates curl software-properties-common
|
||||||
|
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
|
||||||
|
add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"
|
||||||
|
apt update -y
|
||||||
|
apt install -y docker-ce
|
||||||
|
apt install -y mc vim zip
|
||||||
|
|
||||||
|
mkdir -p /data
|
||||||
|
chown usradmin:usradmin /data
|
||||||
|
chmod 770 /data
|
||||||
|
|
||||||
|
trap - EXIT
|
||||||
|
echo "Init complete"
|
||||||
68
samba.sh
Normal file
68
samba.sh
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "This script requires superuser rights. Running with sudo..."
|
||||||
|
exec sudo "$0" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$1" ] || [ -z "$2" ]; then
|
||||||
|
echo "Please provide both the username and password as arguments."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
|
SMB_CONF="/etc/samba/smb.conf"
|
||||||
|
USERNAME="$1"
|
||||||
|
PASSWORD="$2"
|
||||||
|
|
||||||
|
apt update -y
|
||||||
|
apt install -y samba
|
||||||
|
systemctl enable smbd
|
||||||
|
systemctl start smbd
|
||||||
|
|
||||||
|
mkdir -p /data
|
||||||
|
(echo "$PASSWORD"; echo "$PASSWORD") | smbpasswd -a -s "$USERNAME"
|
||||||
|
|
||||||
|
smbpasswd -e "$USERNAME"
|
||||||
|
chown "$USERNAME":"$USERNAME" /data/
|
||||||
|
chmod 770 /data/
|
||||||
|
|
||||||
|
# Backup existing configuration file
|
||||||
|
cp "$SMB_CONF" "${SMB_CONF}.bak"
|
||||||
|
|
||||||
|
# New section
|
||||||
|
NEW_SECTION=$(cat << EOM
|
||||||
|
|
||||||
|
# data folder access
|
||||||
|
[data]
|
||||||
|
path = /data
|
||||||
|
read only = no
|
||||||
|
browseable = yes
|
||||||
|
create mask = 0666
|
||||||
|
force create mode = 0666
|
||||||
|
directory mask = 0777
|
||||||
|
force directory mode = 0777
|
||||||
|
valid users = $USERNAME
|
||||||
|
EOM
|
||||||
|
)
|
||||||
|
|
||||||
|
# Adding a new section to the end of the configuration file
|
||||||
|
echo "$NEW_SECTION" | tee -a "$SMB_CONF" > /dev/null
|
||||||
|
|
||||||
|
if grep -q "^obey pam restrictions = yes" "$SMB_CONF"; then
|
||||||
|
sed -i 's/^obey pam restrictions = yes/obey pam restrictions = no/' "$SMB_CONF"
|
||||||
|
echo "Param 'obey pam restrictions' changed to 'no'"
|
||||||
|
else
|
||||||
|
echo "Param 'obey pam restrictions = yes' not found."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Samba configuration updated and saved to $SMB_CONF."
|
||||||
|
|
||||||
|
systemctl restart smbd nmbd
|
||||||
|
|
||||||
|
trap - EXIT
|
||||||
|
echo "Samba configured complete."
|
||||||
26
ssh-port.sh
Normal file
26
ssh-port.sh
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "This script requires superuser rights. Running with sudo..."
|
||||||
|
exec sudo "$0" "$@"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "Please provide the port as an argument"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT
|
||||||
|
set -e
|
||||||
|
|
||||||
|
NEW_PORT="$1"
|
||||||
|
SSH_CONFIG_FILE="/etc/ssh/sshd_config"
|
||||||
|
|
||||||
|
echo "Change SSH port to $NEW_PORT..."
|
||||||
|
cp $SSH_CONFIG_FILE $SSH_CONFIG_FILE.bak
|
||||||
|
sed -i "s/^#Port 22/Port $NEW_PORT/" $SSH_CONFIG_FILE
|
||||||
|
sed -i "s/^Port 22/Port $NEW_PORT/" $SSH_CONFIG_FILE
|
||||||
|
systemctl restart sshd
|
||||||
|
|
||||||
|
trap - EXIT
|
||||||
|
echo "SSH port successfully changed to $NEW_PORT."
|
||||||
Loading…
Reference in New Issue
Block a user