Last active
July 18, 2022 21:35
-
-
Save papilip/6f1200ddcfb7ee8bba579123db57bf9b to your computer and use it in GitHub Desktop.
freebsd-post-install with ruby 2.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/csh | |
set ruby_version='2.5.9' | |
# Mise à jour quotidienne de sécurité | |
echo '#' >> /etc/crontab | |
echo '# Added by PostInstall - Applying Security Patches' >> /etc/crontab | |
echo '@daily root freebsd-update cron' >> /etc/crontab | |
# Programmes indispenssable | |
pkg install -y chruby curl git gnuls lynx 7-Zip sudo tree wget zsh | |
## Ne pas installer VIM !!! | |
# Ajout des utilisateurs | |
# Manque visudo ... | |
pw useradd -n admin -d /home/admin -g www -G wheel -m -s /bin/csh | |
pw useradd -n deploy -d /home/deploy -g www -G wheel -m -s /usr/local/bin/zsh | |
# Clé SSH pour Admin et Deploy | |
mkdir -p /home/admin/.ssh && chmod 700 /home/admin/.ssh && cp /root/.ssh/authorized_keys /home/admin/.ssh/. && chown -R admin:www /home/admin/.ssh | |
mkdir -p /home/deploy/.ssh && chmod 700 /home/deploy/.ssh && cp /root/.ssh/authorized_keys /home/deploy/.ssh/. && chown -R deploy:www /home/deploy/.ssh | |
# Installer PostgreSQL | |
pkg install -y postgresql15-server | |
sysrc postgresql_enable=YES | |
service postgresql initdb | |
cd /var/db && mv postgres /home/. && ln -s /home/postgres && cd | |
service postgresql start && service postgresql status | |
su -l postgres -c 'createuser --createdb --createrole quimeo && createdb --owner=quimeo --encoding=UTF8 quimeo' | |
su -l postgres -c 'createuser --createdb --createrole deploy && createdb --owner=deploy --encoding=UTF8 deploy' | |
# Installer MariaDB | |
pkg install -y mariadb106-server | |
sysrc mysql_enable=yes | |
service mysql-server start && service mysql-server stop | |
cd /var/db && mv mysql /home/. && ln -s /home/mysql && cd | |
#cp /usr/local/share/mysql/my-medium.cnf /home/mysql/my.cnf | |
service mysql-server start && service mysql-server status | |
# Manque mysql_secure_installation | |
# Interdiction de se connecter en ROOT | |
sed -i.bak 's/PermitRootLogin\ yes/PermitRootLogin\ no/g' /etc/ssh/sshd_config | |
service sshd restart | |
# Permettre SUDO | |
sed -i.bak 's/#\ %wheel\ ALL=(ALL)\ NOPASSWD:\ ALL/%wheel\ ALL=(ALL)\ NOPASSWD:\ ALL/g' /usr/local/etc/sudoers | |
## ruby-install | |
cd && wget -O ruby-install-0.8.3.tar.gz https://github.com/postmodern/ruby-install/archive/v0.8.3.tar.gz | |
tar -xzvf ruby-install-0.8.3.tar.gz && cd ruby-install-0.8.3 && make install && cd && rm -rf ruby-install-0.8.3 && cd | |
# Installer UTF-8 pour root | |
echo 'me:\' >> /root/.login_conf && echo ' :charset=UTF-8:\' >> /root/.login_conf && echo ' :lang=fr_FR.UTF-8:' >> /root/.login_conf | |
# User ADMIN | |
su -l admin -c "echo 'me:\' >> ~/.login_conf && echo ' :charset=UTF-8:\' >> ~/.login_conf && echo ' :lang=fr_FR.UTF-8:' >> ~/.login_conf" | |
su -l admin -c 'git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh' | |
su -l admin -c 'cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc' | |
su -l admin -c "sed -i.bak 's/robbyrussell/gentoo/g' ~/.zshrc" | |
su -l admin -c "echo 'setopt HIST_IGNORE_ALL_DUPS' >> ~/.zshrc" | |
su -l deploy -c "chmod g-w,o-w /home/deploy/.oh-my-zsh/cache/completions" | |
su -l admin -c "echo 'source /usr/local/share/chruby/chruby.sh' > ~/.zshenv" | |
su -l admin -c "echo 'source /usr/local/share/chruby/auto.sh' >> ~/.zshenv" | |
su -l admin -c "echo 'chruby ruby-$ruby_version' >> ~/.zshenv" | |
su -l admin -c "echo 'export LANG=fr_FR.UTF-8' >> ~/.zshenv" | |
su -l admin -c "echo 'export LC_ALL=fr_FR.UTF-8' >> ~/.zshenv" | |
su -l admin -c "echo 'umask 0002' >> ~/.zshenv" | |
su -l admin -c "ssh-keygen -b 4096 -t rsa -N '' -C 'admin@`hostname`' -f ~/.ssh/id_rsa" | |
cat /home/admin/.ssh/id_rsa.pub | |
# User DEPLOY | |
su -l deploy -c "echo 'me:\' >> ~/.login_conf && echo ' :charset=UTF-8:\' >> ~/.login_conf && echo ' :lang=fr_FR.UTF-8:' >> ~/.login_conf" | |
su -l deploy -c 'git clone https://github.com/robbyrussell/oh-my-zsh.git ~/.oh-my-zsh' | |
su -l deploy -c 'cp ~/.oh-my-zsh/templates/zshrc.zsh-template ~/.zshrc' | |
su -l deploy -c "sed -i.bak 's/robbyrussell/gentoo/g' ~/.zshrc" | |
su -l deploy -c "echo 'setopt HIST_IGNORE_ALL_DUPS' >> ~/.zshrc" | |
su -l deploy -c "chmod g-w,o-w /home/deploy/.oh-my-zsh/cache/completions" | |
su -l deploy -c "echo 'source /usr/local/share/chruby/chruby.sh' > ~/.zshenv" | |
su -l deploy -c "echo 'source /usr/local/share/chruby/auto.sh' >> ~/.zshenv" | |
su -l deploy -c "echo 'chruby ruby-$ruby_version' >> ~/.zshenv" | |
su -l deploy -c "echo 'export LANG=fr_FR.UTF-8' >> ~/.zshenv" | |
su -l deploy -c "echo 'export LC_ALL=fr_FR.UTF-8' >> ~/.zshenv" | |
su -l deploy -c "echo 'umask 0002' >> ~/.zshenv" | |
su -l deploy -c "ssh-keygen -b 4096 -t rsa -N '' -C 'deploy@`hostname`' -f ~/.ssh/id_rsa" | |
cat /home/deploy/.ssh/id_rsa.pub | |
## Création des dossiers | |
echo 'ruby-$ruby_version' > /home/.ruby-version && chown deploy:www /home/.ruby-version | |
foreach name ( /home/backup /home/platforms /home/v2ror_prod /home/v2ror_prod/shared/log /opt/nginx /opt/nginx/platforms /opt/nginx/sites ) | |
mkdir -p $name | |
chown deploy:www $name | |
end | |
## Installer ruby | |
pkg -4 install -y duktape gdbm libffi libyaml openssl readline sqlite3 webfonts wkhtmltopdf | |
su -l deploy -c 'ruby-install ruby $ruby_version -- --with-readline-dir=/usr/local/' | |
su -l deploy -c "echo 'ruby-2.5.9' > ~/.ruby-version && echo 'gem: --no-document --no-ri --no-rdoc' > ~/.gemrc" | |
su -l deploy -c 'gem install bundler passenger' | |
## Installer NGINX | |
su -l deploy -c "passenger-install-nginx-module --auto --prefix=/opt/nginx --auto-download --languages 'ruby' --force-colors" | |
sysrc nginx_enable=YES | |
cd /usr/local/etc/rc.d | |
wget https://gist.githubusercontent.com/papilip/ab9e04969e80e111e76068969cfffd7a/raw/10c5136a7955c68c838fcb0846f7c7a125691f3d/nginx.sh | |
mv nginx.sh nginx && chmod +x nginx && cd | |
# cd /var && ln -s /opt/nginx/logs nginx && cd | |
# cd /var && ln -s /home/v2ror_prod/shared/log v2ror_prod && cd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment