diff --git a/add-crowdsec.sh b/add-crowdsec.sh index fb0e4c2..09ed16f 100755 --- a/add-crowdsec.sh +++ b/add-crowdsec.sh @@ -4,19 +4,19 @@ set -e OS_ARCH=$(dpkg --print-architecture) || (echo "Not Debian Based Distro" && exit 1) OS_CODE=$(source /etc/os-release && echo "$VERSION_CODENAME") +SCRIPT=$(readlink -f "$0") +AWD=$(dirname "$SCRIPT") + main(){ echo "deb https://packagecloud.io/crowdsec/crowdsec/debian/ $OS_CODE main" | \ tee /etc/apt/sources.list.d/crowdsec_crowdsec.list curl -fsSL "https://packagecloud.io/crowdsec/crowdsec/gpgkey" | \ gpg --dearmor | tee /etc/apt/trusted.gpg.d/crowdsec_crowdsec-archive-keyring.gpg > /dev/null - command="nala" - command -v $command &>/dev/null || command="apt" - $command update - $command install -y crowdsec crowdsec-firewall-bouncer-iptables + echo "crowdsec crowdsec-firewall-bouncer-iptables" | $AWD/install.sh } -config(){ +setup(){ echo -e "db_config: use_wal: true" | tee /etc/crowdsec/config.yaml.local @@ -36,7 +36,7 @@ whitelist: # - "'foo.com' in evt.Meta.source_ip.reverse" " | tee /etc/crowdsec/parsers/s02-enrich/custom-whitelists.yaml - sed -i -r "s/# - DOCKER-USER/ - DOCKER-USER/g" /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml + sed -i -r "s/.*DOCKER-USER.*/ - DOCKER-USER/g" /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml systemctl reload crowdsec } @@ -44,14 +44,14 @@ whitelist: usage(){ echo "Usage: $0 [OPTIONS]"; echo "OPTIONS:"; - echo " -i install only"; + echo " -s skip setup"; } -INSTALL_ONLY=0; +NO_SETUP=false; while getopts ":i" OPT; do case $OPT in - i) - INSTALL_ONLY=1; + s) + NO_SETUP=true; ;; ?) echo "Invalid Option: -$OPTARG"; @@ -60,7 +60,7 @@ while getopts ":i" OPT; do esac; done; -main; -if [ $INSTALL_ONLY -eq 0 ]; then - config; +main +if ! $NO_SETUP; then + setup fi; \ No newline at end of file diff --git a/add-speedtest.sh b/add-speedtest.sh index e504800..71b0978 100755 --- a/add-speedtest.sh +++ b/add-speedtest.sh @@ -4,16 +4,16 @@ set -e OS_ARCH=$(dpkg --print-architecture) || (echo "Not Debian Based Distro" && exit 1) OS_CODE=$(source /etc/os-release && echo "$VERSION_CODENAME") +SCRIPT=$(readlink -f "$0") +AWD=$(dirname "$SCRIPT") + main(){ echo "deb https://packagecloud.io/ookla/speedtest-cli/debian/ $OS_CODE main" | \ tee /etc/apt/sources.list.d/ookla_speedtest-cli.list curl -fsSL "https://packagecloud.io/ookla/speedtest-cli/gpgkey" | \ gpg --dearmor | tee /etc/apt/trusted.gpg.d/ookla_speedtest-cli-archive-keyring.gpg > /dev/null - command="nala" - command -v $command &>/dev/null || command="apt" - $command update - $command install -y speedtest + echo "speedtest" | $AWD/install.sh } main; \ No newline at end of file diff --git a/configure.sh b/configure.sh new file mode 100755 index 0000000..793266a --- /dev/null +++ b/configure.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -e + +SCRIPT=$(readlink -f "$0") +AWD=$(dirname "$SCRIPT") + +DISTRO_PVE=$((command -v pvesh &>/dev/null && echo 1) || echo 0) + +configure(){ + sed -i "s/.*Host \*.*/Host \*/g" /etc/ssh/ssh_config + sed -i "/.*HashKnownHosts.*/d" /etc/ssh/ssh_config + sed -i "/.*HostKeyAlgorithms.*/d" /etc/ssh/ssh_config + sed -i "/.*PubkeyAcceptedKeyTypes.*/d" /etc/ssh/ssh_config + sed -i "/.*IdentityFile.*/d" /etc/ssh/ssh_config + echo " HashKnownHosts no" | tee -a /etc/ssh/ssh_config + echo " HostKeyAlgorithms ssh-ed25519,ssh-rsa,rsa-sha2-256" | tee -a /etc/ssh/ssh_config + echo " PubkeyAcceptedKeyTypes ssh-ed25519,ssh-rsa,rsa-sha2-256" | tee -a /etc/ssh/ssh_config + echo " IdentityFile ~/.ssh/id_ed25519" | tee -a /etc/ssh/ssh_config + echo " IdentityFile ~/.ssh/id_rsa" | tee -a /etc/ssh/ssh_config + + sed -i "s/.*SystemMaxUse=.*/SystemMaxUse=500M/g" /etc/systemd/journald.conf + sed -i "s/.*RuntimeMaxUse=.*/RuntimeMaxUse=500M/g" /etc/systemd/journald.conf + sed -i "s/.*MaxLevelStore=.*/MaxLevelStore=info/g" /etc/systemd/journald.conf + sed -i "s/.*MaxLevelSyslog=.*/MaxLevelSyslog=info/g" /etc/systemd/journald.conf + + sed -i "s/.*set tabsize.*/set tabsize 4/g" /etc/nanorc + sed -i "s/.*set tabstospaces.*/set tabstospaces/g" /etc/nanorc + sed -i "s|.*/usr/share/nano/\*.nanorc.*|include /usr/share/nano/\*.nanorc|g" /etc/nanorc + sed -i "s/.*whereis all.*/bind \^F whereis all/g" /etc/nanorc + sed -i "s/.*wherewas all.*/bind \^B wherewas all/g" /etc/nanorc + + usermod -s /usr/bin/zsh $(whoami) + cp "$AWD/.zshrc" $HOME + cp "$AWD/.screenrc" $HOME + if [ $DISTRO_PVE -eq 1 ]; then + sed -i -E "s/.*prompt .*/prompt bart/g" $HOME/.zshrc + fi + cp "$AWD/TINK-CA.crt" /usr/local/share/ca-certificates + update-ca-certificates + + if [ $DISTRO_PVE -eq 1 ]; then + sed -i -E "s/.*zoxide.*//g" $HOME/.zshrc + else + $AWD/install-release.sh -r zsh-users/zsh-completions -k tarball -o completions.tar.gz -d "0 src" -p /usr/local/share/zsh/site-functions + $AWD/install-release.sh -r ajeetdsouza/zoxide -m x86_64-unknown -p /usr/local/bin -n zoxide -f + fi +} + +configure \ No newline at end of file diff --git a/init.sh b/init.sh index 42b7990..d483dea 100755 --- a/init.sh +++ b/init.sh @@ -12,7 +12,7 @@ esac DISTRO_PVE=$((command -v pvesh &>/dev/null && echo 1) || echo 0) SCRIPT=$(readlink -f "$0") -SCRIPTPATH=$(dirname "$SCRIPT") +AWD=$(dirname "$SCRIPT") choose_sites(){ case $MIRROR_SOURCE in @@ -50,21 +50,8 @@ choose_sites(){ } -configure(){ +set_pkg_source(){ choose_sites - sed -i -E "s/.*set tabsize.*/set tabsize 4/g" /etc/nanorc - sed -i -E "s/.*set tabstospaces.*/set tabstospaces/g" /etc/nanorc - sed -i -E "s/.*set softwrap.*/set softwrap/g" /etc/nanorc - sed -i -E "s/.*bind \^F whereis all/bind \^F whereis all/g" /etc/nanorc - sed -i -E "s/.*bind \^B wherewas all/bind \^B wherewas all/g" /etc/nanorc - - sed -i -E "/.*HashKnownHosts.*/d" /etc/ssh/ssh_config - sed -i -E "/.*HostKeyAlgorithms.*/d" /etc/ssh/ssh_config - sed -i -E "/.*PubkeyAcceptedKeyTypes.*/d" /etc/ssh/ssh_config - echo " HashKnownHosts no" >> /etc/ssh/ssh_config - echo " HostKeyAlgorithms ssh-ed25519,ssh-rsa,rsa-sha2-256" >> /etc/ssh/ssh_config - echo " PubkeyAcceptedKeyTypes ssh-ed25519,ssh-rsa,rsa-sha2-256" >> /etc/ssh/ssh_config - rm /etc/apt/sources.list || true rm /etc/apt/sources.list.d/* || true @@ -91,15 +78,7 @@ Suites: $OS_CODE Components: pve-no-subscription Signed-By: /etc/apt/trusted.gpg.d/proxmox-release-$OS_CODE.gpg " | tee /etc/apt/sources.list.d/pve-no-subscription.sources - fi - - command="nala" - apt update - apt install -y $command || command="apt" - $command install -y ca-certificates curl gnupg lsb-release zsh - - - if [ $DISTRO_PVE -eq 0 ]; then + else echo -e "Types: deb URIs: $DOCKER_URL Suites: $OS_CODE @@ -122,36 +101,20 @@ Architectures: $OS_ARCH gpg --dearmor | tee /etc/apt/trusted.gpg.d/azlux-archive-keyring.gpg > /dev/null fi - usermod -s /usr/bin/zsh $(whoami) - cp "$SCRIPTPATH/.zshrc" $HOME - cp "$SCRIPTPATH/.screenrc" $HOME - if [ $DISTRO_PVE -eq 1 ]; then - sed -i -E "s/.*prompt .*/prompt bart/g" $HOME/.zshrc - fi - cp "$SCRIPTPATH/TINK-CA.crt" /usr/local/share/ca-certificates - update-ca-certificates - - if [ $DISTRO_PVE -eq 1 ]; then - sed -i -E "s/.*zoxide.*//g" $HOME/.zshrc - else - $SCRIPTPATH/install-release.sh -r zsh-users/zsh-completions -k tarball -o completions.tar.gz -d "0 src" -p /usr/local/share/zsh/site-functions - $SCRIPTPATH/install-release.sh -r ajeetdsouza/zoxide -m x86_64-unknown -p /usr/local/bin -n zoxide -f - fi + apt update + apt install -y nala ca-certificates curl gnupg lsb-release zsh } -install_pkg(){ - command="nala" - command -v $command &>/dev/null || command="apt" - $command update - test -r "$PKG_BASE" - xargs -a <(awk '! /^ *(#|$)/' "$PKG_BASE") -r $command install -y +config(){ + set_pkg_source + $AWD/configure.sh } usage(){ echo "Usage: $0 [OPTIONS]"; echo "OPTIONS:"; echo " -f package list file (default: $PKG_BASE)"; - echo " -i install only"; + echo " -c config only"; echo " -m apt mirror source"; echo " * official" echo " 1 nju (default)" @@ -160,16 +123,16 @@ usage(){ echo " 4 tsinghua" } -PKG_BASE="$SCRIPTPATH/packages-base" -INSTALL_ONLY=0; +PKG_BASE="$AWD/packages-base" +CONFIG_ONLY=false; MIRROR_SOURCE=1; while getopts ":f:ipm:" OPT; do case $OPT in f) PKG_BASE=$OPTARG; ;; - i) - INSTALL_ONLY=1; + c) + CONFIG_ONLY=true; ;; m) MIRROR_SOURCE=$OPTARG; @@ -181,7 +144,7 @@ while getopts ":f:ipm:" OPT; do esac; done; -if [ $INSTALL_ONLY -eq 0 ]; then - configure; -fi; -install_pkg; +config +if ! $CONFIG_ONLY; then + $AWD/install.sh $PKG_BASE +fi \ No newline at end of file diff --git a/install-release.sh b/install-release.sh index be20f19..1791945 100755 --- a/install-release.sh +++ b/install-release.sh @@ -47,7 +47,7 @@ main(){ ext_tar=$(echo "$pkgname" | awk -F'.' '{print $(NF-1)}') dirname= echo "Downloading..." - if [ $NO_INFLATE -eq 1 ]; then + if $NO_INFLATE; then curl $SET_AUTH $SET_PROXY -SfLo $pkgname "$dl_url" else if (echo $ext | grep -i zip) &>/dev/null; then @@ -142,7 +142,7 @@ main(){ exit 0 fi fi - if [ $FILE_COPY -eq 1 ]; then + if $FILE_COPY; then cp -f "$PROG_NAME" "$PROG_PATH/" else cp -fr * "$PROG_PATH/" @@ -188,10 +188,10 @@ TAG=$DEFAULT_RELEASE MATCH_STAGE_1=$DEFAULT_MATCH_STAGE_1 MATCH_STAGE_2= DD_URL= -NO_INFLATE=0 +NO_INFLATE=false PROG_PATH= PROG_NAME= -FILE_COPY=0 +FILE_COPY=false PKG_NAME= PKG_DIR= SED_EXP= @@ -216,7 +216,7 @@ while getopts ":r:t:k:m:u:bp:n:fo:d:e:c:a:x:" OPT; do DD_URL=$OPTARG; ;; b) - NO_INFLATE=1; + NO_INFLATE=true; ;; p) PROG_PATH=$OPTARG; @@ -225,7 +225,7 @@ while getopts ":r:t:k:m:u:bp:n:fo:d:e:c:a:x:" OPT; do PROG_NAME=$OPTARG; ;; f) - FILE_COPY=1; + FILE_COPY=true; ;; o) PKG_NAME=$OPTARG; diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..db5e371 --- /dev/null +++ b/install.sh @@ -0,0 +1,7 @@ +#/usr/bin/env bash + +command="nala" +command -v $command &>/dev/null || command="apt" +$command update +fd="$1" +sed "s/ /\n/g" $fd | awk '!/^ *(#|$)/' "$1" | xargs -r $command install -y