add archlinux version with teleport installed

This commit is contained in:
2022-12-09 15:04:51 +01:00
parent 85a64c0ad4
commit 2ce6720deb
7 changed files with 140 additions and 105 deletions
+14 -8
View File
@@ -1,4 +1,4 @@
FROM alpine:edge
FROM archlinux:latest
ENV USER=borg
ENV UID=1000
@@ -15,22 +15,29 @@ VOLUME ["/backups"]
VOLUME ["/logs"]
VOLUME ["/sshkeys/host"]
COPY motd.txt /etc/motd
COPY entrypoint-script/entrypoint.sh /
COPY entrypoint-script/variables.sh /
COPY scripts/borgbackup.sh /usr/local/bin/
COPY bash-config/.bash_profile /root/
COPY bash-config/.bashrc /root/
COPY bash-config/.bashrc_root /root/
COPY bash-config/.bash_profile /
COPY bash-config/.bashrc /
COPY prometheus-borg-exporter/borg_exporter.sh /usr/local/bin/
COPY prometheus-borg-exporter/borg_exporter.rc /etc/
# Install packages
RUN apk update ; apk upgrade
RUN apk add --no-cache sudo bash bash-completion tzdata openssh openrc neofetch \
borgbackup dateutils prometheus-node-exporter curl wget
RUN rm -rf /var/cache/apk/*
RUN pacman -Syu --noconfirm sudo bash-completion openssh neofetch \
borgbackup dateutils prometheus-node-exporter wget git base-devel cron net-tools inetutils
# Make Build User
RUN useradd builduser -m
RUN passwd -d builduser
RUN printf 'builduser ALL=(ALL) ALL\n' | tee -a /etc/sudoers
RUN sudo -u builduser bash -c 'cd ~ && git clone https://aur.archlinux.org/teleport-bin.git teleport && cd teleport && makepkg -si --noconfirm && cd ~ && rm -rf teleport'
RUN userdel -r builduser
# Setup SSH-Server
RUN sed -ie 's/#Port 22/Port 22/g' /etc/ssh/sshd_config
@@ -40,7 +47,6 @@ RUN sed -ie 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh
RUN sed -ie 's|#HostKey /etc/ssh/ssh_host_rsa_key|HostKey /sshkeys/host/ssh_host_rsa_key|g' /etc/ssh/sshd_config
RUN sed -ie 's|#HostKey /etc/ssh/ssh_host_ecdsa_key|HostKey /sshkeys/host/ssh_host_ecdsa_key|g' /etc/ssh/sshd_config
RUN sed -ie 's|#HostKey /etc/ssh/ssh_host_ed25519_key|HostKey /sshkeys/host/ssh_host_ed25519_key|g' /etc/ssh/sshd_config
RUN sed -ie 's|root:x:0:0:root:/root:/bin/ash|root:x:0:0:root:/root:/bin/bash|g' /etc/passwd
EXPOSE 22
ENTRYPOINT [ "/entrypoint.sh" ]
+1 -1
View File
@@ -1 +1 @@
* * * * * /test_script.sh
* * * * * /test_script.sh
+2 -77
View File
@@ -1,4 +1,4 @@
alias update='apk update && apk upgrade'
alias update='sudo pacman -Syu --noconfirm'
export HISTTIMEFORMAT="%d/%m/%y %T "
export PS1='\u@\h:\W \$ '
@@ -8,79 +8,13 @@ alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
source /etc/profile.d/bash_completion.sh
export PS1="\[\e[31m\][\[\e[m\]\[\e[38;5;172m\]\u\[\e[m\]@\[\e[38;5;153m\]\h\[\e[m\] \[\e[38;5;214m\]\W\[\e[m\]\[\e[31m\]]\[\e[m\]\\$ "
##############################################################################################################################
# Borg Repo finder
# Functions
##############################################################################################################################
source "/variables.sh"
COLUMNS=$(/usr/bin/tput cols)
function find_borg_repo {
repo_list=( $(find "$1" -name "index.*" -type f | rev | cut -d '/' -f "2-" | rev) )
if [ -z "$repo_list" ]; then
sepurator
echo "* Can not find borg repository"
else
sepurator
echo "* Select borg repository"
sepurator
select_borg_repo
fi
}
function select_borg_repo {
if [ "${#repo_list[@]}" -eq 1 ]; then
echo "* Only one item"
sepurator
selected_repo="0"
else
for key in "${!repo_list[@]}" ; do
echo "$key: ${repo_list[key]}"
done
echo ""
selected_repo=asfd
while ! [[ $selected_repo -lt ${#repo_list[@]} && $selected_repo =~ ^[+]?[0-9]+$ ]]; do
read -p "Please select a Repo: " selected_repo
if [[ $selected_repo -gt $((${#repo_list[@]} -1)) ]]; then
sepurator
echo "* Oops! User input was out of range!"
sepurator
fi
if ! [[ $selected_repo =~ ^[+]?[0-9]+$ ]]; then
sepurator
echo "* Oops! User input was not a positive integer!"
sepurator
fi
done
fi
sepurator
}
function ask_for_repo_password {
if [ -z "$BORG_PASSPHRASE" ]; then
if grep -q 'key' "$BORG_REPO/config"; then
echo "* BORG REPO has a password"
sepurator
echo "(you can leave it empty if you not like to export BORG_PASSPHRASE)"
read -s -p "Please enter password: " BORG_REPO_PASSWORD
echo ""
if [ "$BORG_REPO_PASSWORD" != "" ]; then
export BORG_PASSPHRASE="$BORG_REPO_PASSWORD"
fi
else
echo "* BORG REPO has no password"
fi
sepurator
fi
}
function print_container_info {
sepurator
echo "BorgServer powered by $BORG_VERSION - Image Hostname: $HOSTNAME | Image Version: $DOCKER_IMAGE_VERSION"
@@ -89,14 +23,5 @@ function print_container_info {
##############################################################################################################################
# Run Code
##############################################################################################################################
if [ "$INTERACTIVE_MODE" != "false" ]; then
find_borg_repo /backups/
export BORG_REPO="${repo_list[selected_repo]}"
if [ ! -z "$BORG_REPO" ]; then
ask_for_repo_password
clear
fi
fi
print_container_info
neofetch
+100
View File
@@ -0,0 +1,100 @@
alias update='pacman -Syu --noconfirm'
export HISTTIMEFORMAT="%d/%m/%y %T "
export PS1='\u@\h:\W \$ '
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'
export PS1="\[\e[31m\][\[\e[m\]\[\e[38;5;172m\]\u\[\e[m\]@\[\e[38;5;153m\]\h\[\e[m\] \[\e[38;5;214m\]\W\[\e[m\]\[\e[31m\]]\[\e[m\]\\$ "
##############################################################################################################################
# Borg Repo finder
##############################################################################################################################
source "/variables.sh"
COLUMNS=$(/usr/bin/tput cols)
function find_borg_repo {
repo_list=( $(find "$1" -name "index.*" -type f | rev | cut -d '/' -f "2-" | rev) )
if [ -z "$repo_list" ]; then
sepurator
echo "* Can not find borg repository"
else
sepurator
echo "* Select borg repository"
sepurator
select_borg_repo
fi
}
function select_borg_repo {
if [ "${#repo_list[@]}" -eq 1 ]; then
echo "* Only one item"
sepurator
selected_repo="0"
else
for key in "${!repo_list[@]}" ; do
echo "$key: ${repo_list[key]}"
done
echo ""
selected_repo=asfd
while ! [[ $selected_repo -lt ${#repo_list[@]} && $selected_repo =~ ^[+]?[0-9]+$ ]]; do
read -p "Please select a Repo: " selected_repo
if [[ $selected_repo -gt $((${#repo_list[@]} -1)) ]]; then
sepurator
echo "* Oops! User input was out of range!"
sepurator
fi
if ! [[ $selected_repo =~ ^[+]?[0-9]+$ ]]; then
sepurator
echo "* Oops! User input was not a positive integer!"
sepurator
fi
done
fi
sepurator
}
function ask_for_repo_password {
if [ -z "$BORG_PASSPHRASE" ]; then
if grep -q 'key' "$BORG_REPO/config"; then
echo "* BORG REPO has a password"
sepurator
echo "(you can leave it empty if you not like to export BORG_PASSPHRASE)"
read -s -p "Please enter password: " BORG_REPO_PASSWORD
echo ""
if [ "$BORG_REPO_PASSWORD" != "" ]; then
export BORG_PASSPHRASE="$BORG_REPO_PASSWORD"
fi
else
echo "* BORG REPO has no password"
fi
sepurator
fi
}
function print_container_info {
sepurator
echo "BorgServer powered by $BORG_VERSION - Image Hostname: $HOSTNAME | Image Version: $DOCKER_IMAGE_VERSION"
sepurator
}
##############################################################################################################################
# Run Code
##############################################################################################################################
if [ "$INTERACTIVE_MODE" != "false" ]; then
find_borg_repo /backups/
export BORG_REPO="${repo_list[selected_repo]}"
if [ ! -z "$BORG_REPO" ]; then
ask_for_repo_password
clear
fi
fi
print_container_info
neofetch
+1
View File
@@ -8,6 +8,7 @@ run_docker_container() {
echo "Running..."
docker run -dp 3000:22 \
-p 9100:9100 \
-p 2222:22 \
-e UID=$(id -u) \
-e GID=$(id -g) \
-e MAINTENANCE_ENABLE="true" \
+22 -14
View File
@@ -18,16 +18,15 @@ function print_user_info {
function add_borg_user {
if ! id "$USER" &>/dev/null; then
sh -c "echo '$USER ALL=(ALL) NOPASSWD: ALL' >> /etc/sudoers"
adduser \
-s /bin/bash \
--disabled-password \
--gecos "" \
--home "/" \
--uid "$UID" \
"$USER"
echo "$USER:*" | chpasswd 2>> /dev/null
addgroup -g "$GID" "$USER" 2>> /dev/null
groupadd -g "$GID" "$USER" >> /dev/null
useradd -r -u "$UID" -g "$GID" -s "/bin/bash" "$USER" >> /dev/null
passwd -d "$USER" >> /dev/null
printf "$USER ALL=(ALL) NOPASSWD: ALL\n" | tee -a /etc/sudoers >> /dev/null
usermod -d / borg >> /dev/null
create_folder_and_change_permissions "/.config"
create_folder_and_change_permissions "/.cache"
chmod 700 "/.cache"
fi
}
@@ -112,8 +111,8 @@ function maintenance_enable {
echo "* MAINTENANCE MODE - ENABLED"
echo ""
if [ -f "/crontab.txt" ]; then
/usr/bin/crontab "/crontab.txt"
/usr/sbin/crond -b 2> /dev/null
crontab "/crontab.txt"
crond -i 2> /dev/null
echo "- Crontab loaded successfully"
else
echo "- Can not find /crontab.txt"
@@ -152,12 +151,20 @@ function create_folder_and_change_permissions {
chown -R "$USER":"$USER" "$1"
}
function run_teleport_server() {
if [ -f "/etc/teleport.yaml" ]; then
echo "* STARTING Teleport Server"
teleport start -c /etc/teleport.yaml > /var/log/teleport.log 2>&1 &
sepurator
fi
}
function run_prometheus_exporter() {
if [ "$RUN_PROMETHEUS_EXPORTER" != "false" ]; then
create_folder_and_change_permissions "/.config"
create_folder_and_change_permissions "/var/log/"
echo "* STARTING Prometheus Exporter for Borg Backup"
echo ""
crontab -l > /tmp/cron_bkp
echo "" >> /tmp/cron_bkp
@@ -173,7 +180,7 @@ function run_prometheus_exporter() {
fi
echo "- STARTING Node Exporter"
sudo -H -u "$USER" bash -c "node_exporter --collector.textfile.directory=$NODE_EXPORTER_DIR &"
sudo -H -u "$USER" bash -c "prometheus-node-exporter --collector.textfile.directory=$NODE_EXPORTER_DIR > /dev/null 2>&1 &"
sepurator
fi
}
@@ -192,6 +199,7 @@ sepurator
maintenance_enable
set_timezone
run_teleport_server
run_prometheus_exporter
run_install_script
-5
View File
@@ -1,5 +0,0 @@
Welcome to BorgBackup!
You can run all borg command here: borg
to Check you Version run: borg -V