diff --git a/.gitignore b/.gitignore index b0549b5..e5ee08c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ sshkeys/ backups/ .dccache +Testing/ diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..cd43278 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "package/teleport-bin"] + path = package/teleport-bin + url = git@git.yiprawr.dev:daniel156161/teleport-bin.git diff --git a/Dockerfile b/Dockerfile index 7c5941a..cca72c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:edge +FROM archlinux:latest ENV USER=borg ENV UID=1000 @@ -15,22 +15,38 @@ 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 bash-config/locale.gen /etc/locale.gen COPY prometheus-borg-exporter/borg_exporter.sh /usr/local/bin/ COPY prometheus-borg-exporter/borg_exporter.rc /etc/ +# Create .cache folder +RUN mkdir -p "/root/.cache/crontab" + +# Create locale files +RUN locale-gen + # 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-key --init +RUN pacman -Syu --noconfirm sudo bash-completion openssh fastfetch \ + borgbackup dateutils prometheus-node-exporter wget git base-devel cron net-tools inetutils tmux + +# 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 sudo -u builduser bash -c 'cd ~ && git clone https://git.yiprawr.dev/daniel156161/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 +56,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" ] diff --git a/Testing/crontab.txt b/Testing/crontab.txt deleted file mode 100644 index 5b4d1ab..0000000 --- a/Testing/crontab.txt +++ /dev/null @@ -1 +0,0 @@ -* * * * * /test_script.sh \ No newline at end of file diff --git a/Testing/test_script.sh b/Testing/test_script.sh deleted file mode 100755 index cc37238..0000000 --- a/Testing/test_script.sh +++ /dev/null @@ -1,3 +0,0 @@ -# !/bin/bash - -echo "$(date +%Y-%m-%d_%H:%M:%S) Test" >> /logs/test.log diff --git a/bash-config/.bash_profile b/bash-config/.bash_profile index 0551e69..05f7894 100644 --- a/bash-config/.bash_profile +++ b/bash-config/.bash_profile @@ -6,7 +6,6 @@ if [ -f ~/.bashrc ]; then fi # User specific environment and startup programs - PATH=$PATH:$HOME/bin export PATH diff --git a/bash-config/.bashrc b/bash-config/.bashrc index c67a2df..e3a56e5 100644 --- a/bash-config/.bashrc +++ b/bash-config/.bashrc @@ -1,4 +1,9 @@ -alias update='apk update && apk upgrade' +if [ ! -z $(cat /etc/environment | grep "USE_TMUX_SHELL") ] && [[ -t 0 ]] && [ -z "$TMUX" ]; then + tmux attach || tmux new-session + exit +fi + +alias update='sudo pacman -Syu --noconfirm' export HISTTIMEFORMAT="%d/%m/%y %T " export PS1='\u@\h:\W \$ ' @@ -8,79 +13,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 +28,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 +fastfetch --config neofetch diff --git a/bash-config/.bashrc_root b/bash-config/.bashrc_root new file mode 100644 index 0000000..1a05e94 --- /dev/null +++ b/bash-config/.bashrc_root @@ -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 +fastfetch --config neofetch diff --git a/bash-config/locale.gen b/bash-config/locale.gen new file mode 100644 index 0000000..84356b0 --- /dev/null +++ b/bash-config/locale.gen @@ -0,0 +1,516 @@ +# Configuration file for locale-gen +# +# lists of locales that are to be generated by the locale-gen command. +# +# Each line is of the form: +# +# +# +# where is one of the locales given in /usr/share/i18n/locales +# and is one of the character sets listed in /usr/share/i18n/charmaps +# +# The locale-gen command will generate all the locales, +# placing them in /usr/lib/locale. +# +# A list of supported locales is given in /usr/share/i18n/SUPPORTED +# and is included in this file. Uncomment the needed locales below. +# +#aa_DJ.UTF-8 UTF-8 +#aa_DJ ISO-8859-1 +#aa_ER UTF-8 +#aa_ET UTF-8 +#af_ZA.UTF-8 UTF-8 +#af_ZA ISO-8859-1 +#agr_PE UTF-8 +#ak_GH UTF-8 +#am_ET UTF-8 +#an_ES.UTF-8 UTF-8 +#an_ES ISO-8859-15 +#anp_IN UTF-8 +#ar_AE.UTF-8 UTF-8 +#ar_AE ISO-8859-6 +#ar_BH.UTF-8 UTF-8 +#ar_BH ISO-8859-6 +#ar_DZ.UTF-8 UTF-8 +#ar_DZ ISO-8859-6 +#ar_EG.UTF-8 UTF-8 +#ar_EG ISO-8859-6 +#ar_IN UTF-8 +#ar_IQ.UTF-8 UTF-8 +#ar_IQ ISO-8859-6 +#ar_JO.UTF-8 UTF-8 +#ar_JO ISO-8859-6 +#ar_KW.UTF-8 UTF-8 +#ar_KW ISO-8859-6 +#ar_LB.UTF-8 UTF-8 +#ar_LB ISO-8859-6 +#ar_LY.UTF-8 UTF-8 +#ar_LY ISO-8859-6 +#ar_MA.UTF-8 UTF-8 +#ar_MA ISO-8859-6 +#ar_OM.UTF-8 UTF-8 +#ar_OM ISO-8859-6 +#ar_QA.UTF-8 UTF-8 +#ar_QA ISO-8859-6 +#ar_SA.UTF-8 UTF-8 +#ar_SA ISO-8859-6 +#ar_SD.UTF-8 UTF-8 +#ar_SD ISO-8859-6 +#ar_SS UTF-8 +#ar_SY.UTF-8 UTF-8 +#ar_SY ISO-8859-6 +#ar_TN.UTF-8 UTF-8 +#ar_TN ISO-8859-6 +#ar_YE.UTF-8 UTF-8 +#ar_YE ISO-8859-6 +#ayc_PE UTF-8 +#az_AZ UTF-8 +#az_IR UTF-8 +#as_IN UTF-8 +#ast_ES.UTF-8 UTF-8 +#ast_ES ISO-8859-15 +#be_BY.UTF-8 UTF-8 +#be_BY CP1251 +#be_BY@latin UTF-8 +#bem_ZM UTF-8 +#ber_DZ UTF-8 +#ber_MA UTF-8 +#bg_BG.UTF-8 UTF-8 +#bg_BG CP1251 +#bhb_IN.UTF-8 UTF-8 +#bho_IN UTF-8 +#bho_NP UTF-8 +#bi_VU UTF-8 +#bn_BD UTF-8 +#bn_IN UTF-8 +#bo_CN UTF-8 +#bo_IN UTF-8 +#br_FR.UTF-8 UTF-8 +#br_FR ISO-8859-1 +#br_FR@euro ISO-8859-15 +#brx_IN UTF-8 +#bs_BA.UTF-8 UTF-8 +#bs_BA ISO-8859-2 +#byn_ER UTF-8 +#ca_AD.UTF-8 UTF-8 +#ca_AD ISO-8859-15 +#ca_ES.UTF-8 UTF-8 +#ca_ES ISO-8859-1 +#ca_ES@euro ISO-8859-15 +#ca_ES@valencia UTF-8 +#ca_FR.UTF-8 UTF-8 +#ca_FR ISO-8859-15 +#ca_IT.UTF-8 UTF-8 +#ca_IT ISO-8859-15 +#ce_RU UTF-8 +#chr_US UTF-8 +#ckb_IQ UTF-8 +#cmn_TW UTF-8 +#crh_RU UTF-8 +#crh_UA UTF-8 +#cs_CZ.UTF-8 UTF-8 +#cs_CZ ISO-8859-2 +#csb_PL UTF-8 +#cv_RU UTF-8 +#cy_GB.UTF-8 UTF-8 +#cy_GB ISO-8859-14 +#da_DK.UTF-8 UTF-8 +#da_DK ISO-8859-1 +#de_AT.UTF-8 UTF-8 +#de_AT ISO-8859-1 +#de_AT@euro ISO-8859-15 +#de_BE.UTF-8 UTF-8 +#de_BE ISO-8859-1 +#de_BE@euro ISO-8859-15 +#de_CH.UTF-8 UTF-8 +#de_CH ISO-8859-1 +#de_DE.UTF-8 UTF-8 +#de_DE ISO-8859-1 +#de_DE@euro ISO-8859-15 +#de_IT.UTF-8 UTF-8 +#de_IT ISO-8859-1 +#de_LI.UTF-8 UTF-8 +#de_LU.UTF-8 UTF-8 +#de_LU ISO-8859-1 +#de_LU@euro ISO-8859-15 +#doi_IN UTF-8 +#dsb_DE UTF-8 +#dv_MV UTF-8 +#dz_BT UTF-8 +#el_GR.UTF-8 UTF-8 +#el_GR ISO-8859-7 +#el_GR@euro ISO-8859-7 +#el_CY.UTF-8 UTF-8 +#el_CY ISO-8859-7 +#en_AG UTF-8 +#en_AU.UTF-8 UTF-8 +#en_AU ISO-8859-1 +#en_BW.UTF-8 UTF-8 +#en_BW ISO-8859-1 +#en_CA.UTF-8 UTF-8 +#en_CA ISO-8859-1 +#en_DK.UTF-8 UTF-8 +#en_DK ISO-8859-1 +#en_GB.UTF-8 UTF-8 +#en_GB ISO-8859-1 +#en_HK.UTF-8 UTF-8 +#en_HK ISO-8859-1 +#en_IE.UTF-8 UTF-8 +#en_IE ISO-8859-1 +#en_IE@euro ISO-8859-15 +#en_IL UTF-8 +#en_IN UTF-8 +#en_NG UTF-8 +#en_NZ.UTF-8 UTF-8 +#en_NZ ISO-8859-1 +#en_PH.UTF-8 UTF-8 +#en_PH ISO-8859-1 +#en_SC.UTF-8 UTF-8 +#en_SG.UTF-8 UTF-8 +#en_SG ISO-8859-1 +en_US.UTF-8 UTF-8 +#en_US ISO-8859-1 +#en_ZA.UTF-8 UTF-8 +#en_ZA ISO-8859-1 +#en_ZM UTF-8 +#en_ZW.UTF-8 UTF-8 +#en_ZW ISO-8859-1 +#eo UTF-8 +#es_AR.UTF-8 UTF-8 +#es_AR ISO-8859-1 +#es_BO.UTF-8 UTF-8 +#es_BO ISO-8859-1 +#es_CL.UTF-8 UTF-8 +#es_CL ISO-8859-1 +#es_CO.UTF-8 UTF-8 +#es_CO ISO-8859-1 +#es_CR.UTF-8 UTF-8 +#es_CR ISO-8859-1 +#es_CU UTF-8 +#es_DO.UTF-8 UTF-8 +#es_DO ISO-8859-1 +#es_EC.UTF-8 UTF-8 +#es_EC ISO-8859-1 +#es_ES.UTF-8 UTF-8 +#es_ES ISO-8859-1 +#es_ES@euro ISO-8859-15 +#es_GT.UTF-8 UTF-8 +#es_GT ISO-8859-1 +#es_HN.UTF-8 UTF-8 +#es_HN ISO-8859-1 +#es_MX.UTF-8 UTF-8 +#es_MX ISO-8859-1 +#es_NI.UTF-8 UTF-8 +#es_NI ISO-8859-1 +#es_PA.UTF-8 UTF-8 +#es_PA ISO-8859-1 +#es_PE.UTF-8 UTF-8 +#es_PE ISO-8859-1 +#es_PR.UTF-8 UTF-8 +#es_PR ISO-8859-1 +#es_PY.UTF-8 UTF-8 +#es_PY ISO-8859-1 +#es_SV.UTF-8 UTF-8 +#es_SV ISO-8859-1 +#es_US.UTF-8 UTF-8 +#es_US ISO-8859-1 +#es_UY.UTF-8 UTF-8 +#es_UY ISO-8859-1 +#es_VE.UTF-8 UTF-8 +#es_VE ISO-8859-1 +#et_EE.UTF-8 UTF-8 +#et_EE ISO-8859-1 +#et_EE.ISO-8859-15 ISO-8859-15 +#eu_ES.UTF-8 UTF-8 +#eu_ES ISO-8859-1 +#eu_ES@euro ISO-8859-15 +#fa_IR UTF-8 +#ff_SN UTF-8 +#fi_FI.UTF-8 UTF-8 +#fi_FI ISO-8859-1 +#fi_FI@euro ISO-8859-15 +#fil_PH UTF-8 +#fo_FO.UTF-8 UTF-8 +#fo_FO ISO-8859-1 +#fr_BE.UTF-8 UTF-8 +#fr_BE ISO-8859-1 +#fr_BE@euro ISO-8859-15 +#fr_CA.UTF-8 UTF-8 +#fr_CA ISO-8859-1 +#fr_CH.UTF-8 UTF-8 +#fr_CH ISO-8859-1 +#fr_FR.UTF-8 UTF-8 +#fr_FR ISO-8859-1 +#fr_FR@euro ISO-8859-15 +#fr_LU.UTF-8 UTF-8 +#fr_LU ISO-8859-1 +#fr_LU@euro ISO-8859-15 +#fur_IT UTF-8 +#fy_NL UTF-8 +#fy_DE UTF-8 +#ga_IE.UTF-8 UTF-8 +#ga_IE ISO-8859-1 +#ga_IE@euro ISO-8859-15 +#gbm_IN UTF-8 +#gd_GB.UTF-8 UTF-8 +#gd_GB ISO-8859-15 +#gez_ER UTF-8 +#gez_ER@abegede UTF-8 +#gez_ET UTF-8 +#gez_ET@abegede UTF-8 +#gl_ES.UTF-8 UTF-8 +#gl_ES ISO-8859-1 +#gl_ES@euro ISO-8859-15 +#gu_IN UTF-8 +#gv_GB.UTF-8 UTF-8 +#gv_GB ISO-8859-1 +#ha_NG UTF-8 +#hak_TW UTF-8 +#he_IL.UTF-8 UTF-8 +#he_IL ISO-8859-8 +#hi_IN UTF-8 +#hif_FJ UTF-8 +#hne_IN UTF-8 +#hr_HR.UTF-8 UTF-8 +#hr_HR ISO-8859-2 +#hsb_DE ISO-8859-2 +#hsb_DE.UTF-8 UTF-8 +#ht_HT UTF-8 +#hu_HU.UTF-8 UTF-8 +#hu_HU ISO-8859-2 +#hy_AM UTF-8 +#hy_AM.ARMSCII-8 ARMSCII-8 +#ia_FR UTF-8 +#id_ID.UTF-8 UTF-8 +#id_ID ISO-8859-1 +#ig_NG UTF-8 +#ik_CA UTF-8 +#is_IS.UTF-8 UTF-8 +#is_IS ISO-8859-1 +#it_CH.UTF-8 UTF-8 +#it_CH ISO-8859-1 +#it_IT.UTF-8 UTF-8 +#it_IT ISO-8859-1 +#it_IT@euro ISO-8859-15 +#iu_CA UTF-8 +#ja_JP.EUC-JP EUC-JP +#ja_JP.UTF-8 UTF-8 +#ka_GE.UTF-8 UTF-8 +#ka_GE GEORGIAN-PS +#kab_DZ UTF-8 +#kk_KZ.UTF-8 UTF-8 +#kk_KZ PT154 +#kl_GL.UTF-8 UTF-8 +#kl_GL ISO-8859-1 +#km_KH UTF-8 +#kn_IN UTF-8 +#ko_KR.EUC-KR EUC-KR +#ko_KR.UTF-8 UTF-8 +#kok_IN UTF-8 +#ks_IN UTF-8 +#ks_IN@devanagari UTF-8 +#ku_TR.UTF-8 UTF-8 +#ku_TR ISO-8859-9 +#kv_RU UTF-8 +#kw_GB.UTF-8 UTF-8 +#kw_GB ISO-8859-1 +#ky_KG UTF-8 +#lb_LU UTF-8 +#lg_UG.UTF-8 UTF-8 +#lg_UG ISO-8859-10 +#li_BE UTF-8 +#li_NL UTF-8 +#lij_IT UTF-8 +#ln_CD UTF-8 +#lo_LA UTF-8 +#lt_LT.UTF-8 UTF-8 +#lt_LT ISO-8859-13 +#ltg_LV.UTF-8 UTF-8 +#lv_LV.UTF-8 UTF-8 +#lv_LV ISO-8859-13 +#lzh_TW UTF-8 +#mag_IN UTF-8 +#mai_IN UTF-8 +#mai_NP UTF-8 +#mdf_RU UTF-8 +#mfe_MU UTF-8 +#mg_MG.UTF-8 UTF-8 +#mg_MG ISO-8859-15 +#mhr_RU UTF-8 +#mi_NZ.UTF-8 UTF-8 +#mi_NZ ISO-8859-13 +#miq_NI UTF-8 +#mjw_IN UTF-8 +#mk_MK.UTF-8 UTF-8 +#mk_MK ISO-8859-5 +#ml_IN UTF-8 +#mn_MN UTF-8 +#mni_IN UTF-8 +#mnw_MM UTF-8 +#mr_IN UTF-8 +#ms_MY.UTF-8 UTF-8 +#ms_MY ISO-8859-1 +#mt_MT.UTF-8 UTF-8 +#mt_MT ISO-8859-3 +#my_MM UTF-8 +#nan_TW UTF-8 +#nan_TW@latin UTF-8 +#nb_NO.UTF-8 UTF-8 +#nb_NO ISO-8859-1 +#nds_DE UTF-8 +#nds_NL UTF-8 +#ne_NP UTF-8 +#nhn_MX UTF-8 +#niu_NU UTF-8 +#niu_NZ UTF-8 +#nl_AW UTF-8 +#nl_BE.UTF-8 UTF-8 +#nl_BE ISO-8859-1 +#nl_BE@euro ISO-8859-15 +#nl_NL.UTF-8 UTF-8 +#nl_NL ISO-8859-1 +#nl_NL@euro ISO-8859-15 +#nn_NO.UTF-8 UTF-8 +#nn_NO ISO-8859-1 +#nr_ZA UTF-8 +#nso_ZA UTF-8 +#oc_FR.UTF-8 UTF-8 +#oc_FR ISO-8859-1 +#om_ET UTF-8 +#om_KE.UTF-8 UTF-8 +#om_KE ISO-8859-1 +#or_IN UTF-8 +#os_RU UTF-8 +#pa_IN UTF-8 +#pa_PK UTF-8 +#pap_AW UTF-8 +#pap_CW UTF-8 +#pl_PL.UTF-8 UTF-8 +#pl_PL ISO-8859-2 +#ps_AF UTF-8 +#pt_BR.UTF-8 UTF-8 +#pt_BR ISO-8859-1 +#pt_PT.UTF-8 UTF-8 +#pt_PT ISO-8859-1 +#pt_PT@euro ISO-8859-15 +#quz_PE UTF-8 +#raj_IN UTF-8 +#rif_MA UTF-8 +#ro_RO.UTF-8 UTF-8 +#ro_RO ISO-8859-2 +#ru_RU.KOI8-R KOI8-R +#ru_RU.UTF-8 UTF-8 +#ru_RU ISO-8859-5 +#ru_UA.UTF-8 UTF-8 +#ru_UA KOI8-U +#rw_RW UTF-8 +#sa_IN UTF-8 +#sah_RU UTF-8 +#sat_IN UTF-8 +#sc_IT UTF-8 +#scn_IT UTF-8 +#sd_IN UTF-8 +#sd_IN@devanagari UTF-8 +#se_NO UTF-8 +#sgs_LT UTF-8 +#shn_MM UTF-8 +#shs_CA UTF-8 +#si_LK UTF-8 +#sid_ET UTF-8 +#sk_SK.UTF-8 UTF-8 +#sk_SK ISO-8859-2 +#sl_SI.UTF-8 UTF-8 +#sl_SI ISO-8859-2 +#sm_WS UTF-8 +#so_DJ.UTF-8 UTF-8 +#so_DJ ISO-8859-1 +#so_ET UTF-8 +#so_KE.UTF-8 UTF-8 +#so_KE ISO-8859-1 +#so_SO.UTF-8 UTF-8 +#so_SO ISO-8859-1 +#sq_AL.UTF-8 UTF-8 +#sq_AL ISO-8859-1 +#sq_MK UTF-8 +#sr_ME UTF-8 +#sr_RS UTF-8 +#sr_RS@latin UTF-8 +#ss_ZA UTF-8 +#ssy_ER UTF-8 +#st_ZA.UTF-8 UTF-8 +#st_ZA ISO-8859-1 +#su_ID UTF-8 +#sv_FI.UTF-8 UTF-8 +#sv_FI ISO-8859-1 +#sv_FI@euro ISO-8859-15 +#sv_SE.UTF-8 UTF-8 +#sv_SE ISO-8859-1 +#sw_KE UTF-8 +#sw_TZ UTF-8 +#syr UTF-8 +#szl_PL UTF-8 +#ta_IN UTF-8 +#ta_LK UTF-8 +#tcy_IN.UTF-8 UTF-8 +#te_IN UTF-8 +#tg_TJ.UTF-8 UTF-8 +#tg_TJ KOI8-T +#th_TH.UTF-8 UTF-8 +#th_TH TIS-620 +#the_NP UTF-8 +#ti_ER UTF-8 +#ti_ET UTF-8 +#tig_ER UTF-8 +#tk_TM UTF-8 +#tl_PH.UTF-8 UTF-8 +#tl_PH ISO-8859-1 +#tn_ZA UTF-8 +#to_TO UTF-8 +#tok UTF-8 +#tpi_PG UTF-8 +#tr_CY.UTF-8 UTF-8 +#tr_CY ISO-8859-9 +#tr_TR.UTF-8 UTF-8 +#tr_TR ISO-8859-9 +#ts_ZA UTF-8 +#tt_RU UTF-8 +#tt_RU@iqtelif UTF-8 +#ug_CN UTF-8 +#uk_UA.UTF-8 UTF-8 +#uk_UA KOI8-U +#unm_US UTF-8 +#ur_IN UTF-8 +#ur_PK UTF-8 +#uz_UZ.UTF-8 UTF-8 +#uz_UZ ISO-8859-1 +#uz_UZ@cyrillic UTF-8 +#ve_ZA UTF-8 +#vi_VN UTF-8 +#wa_BE ISO-8859-1 +#wa_BE@euro ISO-8859-15 +#wa_BE.UTF-8 UTF-8 +#wae_CH UTF-8 +#wal_ET UTF-8 +#wo_SN UTF-8 +#xh_ZA.UTF-8 UTF-8 +#xh_ZA ISO-8859-1 +#yi_US.UTF-8 UTF-8 +#yi_US CP1255 +#yo_NG UTF-8 +#yue_HK UTF-8 +#yuw_PG UTF-8 +#zgh_MA UTF-8 +#zh_CN.GB18030 GB18030 +#zh_CN.GBK GBK +#zh_CN.UTF-8 UTF-8 +#zh_CN GB2312 +#zh_HK.UTF-8 UTF-8 +#zh_HK BIG5-HKSCS +#zh_SG.UTF-8 UTF-8 +#zh_SG.GBK GBK +#zh_SG GB2312 +#zh_TW.EUC-TW EUC-TW +#zh_TW.UTF-8 UTF-8 +#zh_TW BIG5 +#zu_ZA.UTF-8 UTF-8 +#zu_ZA ISO-8859-1 \ No newline at end of file diff --git a/build.sh b/build.sh index b174c0d..4242ce0 100755 --- a/build.sh +++ b/build.sh @@ -1,54 +1,35 @@ #!/bin/bash +source "../build-functions.sh" +source "../build-config.sh" DOCKER_IMAGE_NAME="daniel156161/borgbackup-ssh" DOCKER_CONTAINER_NAME="borgbackup" -GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD) -run_docker_container() { +function run_docker_container { echo "Running..." - docker run -dp 3000:22 \ + docker run --rm -d \ + -p 2222:22 \ -p 9100:9100 \ -e UID=$(id -u) \ -e GID=$(id -g) \ - -e MAINTENANCE_ENABLE="true" \ -e INTERACTIVE_MODE="true" \ -e TZ="Europe/Vienna" \ - -e RUN_PROMETHEUS_EXPORTER="0 * * * *" \ - -v "$PWD"/Testing/crontab.txt:/crontab.txt \ - -v "$PWD"/Testing/test_script.sh:/test_script.sh \ - -v "$PWD"/sshkeys/clients:/sshkeys/clients \ - -v "$PWD"/backups:/backups \ - "$DOCKER_IMAGE_NAME":"$GIT_BRANCH" + -e RUN_PROMETHEUS_EXPORTER="15 * * * *" \ + -v "$PWD/sshkeys/clients:/sshkeys/clients:ro" \ + -v "$PWD/sshkeys/host:/sshkeys/host" \ + -v "$PWD/backups:/backups" \ + "$DOCKER_IMAGE_NAME:$GIT_BRANCH" } -build_docker_image() { - TAG="$1" - - echo "Building..." - docker build -t "$DOCKER_IMAGE_NAME:$TAG" . -} - -if [ "$GIT_BRANCH" == "main" ]; then - GIT_BRANCH="latest" -fi - case "$1" in run) run_docker_container ;; build) - build_docker_image "$GIT_BRANCH" - ;; - upload) - build_docker_image "$GIT_BRANCH" - docker push "$DOCKER_IMAGE_NAME:$GIT_BRANCH" - ;; - test) - build_docker_image "$GIT_BRANCH" - run_docker_container + build_docker_image "$DOCKER_IMAGE_NAME:$GIT_BRANCH" ;; *) - echo "Usage: $0 {run|build|test|upload}" + echo "Usage: $0 {run|build}" exit 1 ;; esac diff --git a/entrypoint-script/entrypoint.sh b/entrypoint-script/entrypoint.sh index 5ff35c5..7512756 100755 --- a/entrypoint-script/entrypoint.sh +++ b/entrypoint-script/entrypoint.sh @@ -1,8 +1,21 @@ #!/bin/bash source "/variables.sh" -############################################################################################################################## +##################################################################################################### # Funktionen -############################################################################################################################## +##################################################################################################### +function set_environment_variables_if_not_empty { + # Set Tmux Shell for .bashrc to load tmux and attach session if exists else create new session + if [ "$USE_TMUX_SHELL" != "" ]; then + echo "USE_TMUX_SHELL=$USE_TMUX_SHELL" >> /etc/environment + fi + + # Set Server Timezone + if [ "$TZ" != "" ]; then + echo "TZ=$TZ" >> /etc/environment + ln -sf "/usr/share/zoneinfo/$TZ" /etc/localtime + fi +} + function print_container_info { sepurator echo "* BorgServer powered by $BORG_VERSION" @@ -18,16 +31,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 } @@ -56,7 +68,6 @@ function make_and_import_ssh_keys { fi echo "* IMPORT SSH KEYS" - echo "" FILES=$(ls -1 /sshkeys/clients) for key in $FILES; do @@ -77,31 +88,24 @@ function print_message { } function generate_host_sshkey { - local generated_keys="0" - echo "* GENERATE HOST SSH-KEYs" # Generate SSH-Keys if [ ! -f "/sshkeys/host/ssh_host_rsa_key" ]; then + sepurator print_message "HOST SSH-KEY RSA not found, generating..." ssh-keygen -t rsa -b 4096 -f "/sshkeys/host/ssh_host_rsa_key" -N "" print_message "HOST SSH-KEY RSA Generated" - generated_keys="1" fi if [ ! -f "/sshkeys/host/ssh_host_ecdsa_key" ]; then + sepurator print_message "HOST SSH-KEY ECDSA not found, generating..." ssh-keygen -t ecdsa -b 521 -f "/sshkeys/host/ssh_host_ecdsa_key" -N "" print_message "HOST SSH-KEY ECDSA Generated" - generated_keys="1" fi if [ ! -f "/sshkeys/host/ssh_host_ed25519_key" ]; then + sepurator print_message "HOST SSH-KEY ED25519 not found, generating..." ssh-keygen -t ed25519 -b 521 -f "/sshkeys/host/ssh_host_ed25519_key" -N "" print_message "HOST SSH-KEY ED25519 Generated" - generated_keys="1" - fi - - if [ "$generated_keys" == "0" ]; then - echo "" - echo "- HOST SSH-KEYs already exist" fi chown -R "$USER":"$USER" "/sshkeys/host" @@ -110,10 +114,9 @@ function generate_host_sshkey { function maintenance_enable { if [ "$MAINTENANCE_ENABLE" != "false" ]; then 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" @@ -122,10 +125,9 @@ function maintenance_enable { fi } -function set_timezone { +function show_timezone_output { if [ "$TZ" != "" ]; then echo "* Setting Timezone to $TZ" - echo "TZ=$TZ" > /etc/environment else echo "* Timezone not set - Use UTC Time" fi @@ -138,7 +140,7 @@ function run_install_script { echo "* RUNNING INSTALL SCRIPT" sepurator sh "$RUN_INSTALL_SCRIPT" - echo "" + sepurator touch "/.runnedInstall" fi @@ -154,7 +156,6 @@ function create_folder_and_change_permissions { 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" @@ -164,7 +165,7 @@ function run_prometheus_exporter() { echo "- Add Cronjob to Crontab" echo "$RUN_PROMETHEUS_EXPORTER su -c '/usr/local/bin/borg_exporter.sh 2>&1' -s /bin/bash borg" >> /tmp/cron_bkp - crontab /tmp/cron_bkp + crontab /tmp/cron_bkp > /dev/null 2>&1 rm /tmp/cron_bkp if [ ! -f "/var/log/borg_exporter.prom" ]; then @@ -173,29 +174,40 @@ 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 } -############################################################################################################################## + +function run_correct_ssh_service() { + if [ -f "/etc/teleport.yaml" ]; then + echo "* STARTING Teleport Server" + exec teleport start -c /etc/teleport.yaml 2>&1 + else + exec /usr/sbin/sshd -D -e "$@" 2>&1 + fi; +} +##################################################################################################### # Main Code -############################################################################################################################## +##################################################################################################### +set_environment_variables_if_not_empty +dbus-uuidgen --ensure=/etc/machine-id add_borg_user print_container_info print_user_info sepurator make_and_import_ssh_keys -sepurator + generate_host_sshkey sepurator maintenance_enable -set_timezone +show_timezone_output run_prometheus_exporter run_install_script echo "* Init done! - Starting SSH-Daemon..." sepurator -echo "" -exec /usr/sbin/sshd -D -e "$@" 2> /var/log/sshd.log + +run_correct_ssh_service diff --git a/entrypoint-script/variables.sh b/entrypoint-script/variables.sh index a7e1466..8d064cf 100644 --- a/entrypoint-script/variables.sh +++ b/entrypoint-script/variables.sh @@ -1,4 +1,4 @@ -DOCKER_IMAGE_VERSION="2.0.0" +DOCKER_IMAGE_VERSION="3.0.0" BORG_VERSION=$(borg -V) SSH_FOLDERS=( "/sshkeys/clients" "/sshkeys/host" ) NODE_EXPORTER_DIR="/var/log" diff --git a/motd.txt b/motd.txt deleted file mode 100644 index b32afc5..0000000 --- a/motd.txt +++ /dev/null @@ -1,5 +0,0 @@ -Welcome to BorgBackup! - -You can run all borg command here: borg -to Check you Version run: borg -V - diff --git a/package/teleport-bin b/package/teleport-bin new file mode 160000 index 0000000..a840ba5 --- /dev/null +++ b/package/teleport-bin @@ -0,0 +1 @@ +Subproject commit a840ba5f13b25ae03c2c912c9db2c8a5617b630f