From 460a40f075fe149ea5fdbe92e26ab10980f19016 Mon Sep 17 00:00:00 2001 From: Xavier Petit <32063953+xpetit@users.noreply.github.com> Date: Mon, 11 May 2020 18:58:15 +0200 Subject: [PATCH] Fusion scripts --- sh/scripts/bash_tweaks.sh | 68 -------- sh/scripts/clean.sh | 55 ------- sh/scripts/configure_ubuntu.sh | 280 +++++++++++++++++++++++++++++++-- sh/scripts/docker.sh | 14 -- sh/scripts/exam.sh | 32 ---- sh/scripts/firewall.sh | 17 -- sh/scripts/fx.sh | 9 -- sh/scripts/go.sh | 28 ---- sh/scripts/grub.sh | 23 --- sh/scripts/libreoffice.sh | 9 -- sh/scripts/nodejs.sh | 10 -- sh/scripts/ssh.sh | 18 --- sh/scripts/sublime.sh | 17 -- sh/scripts/vscode.sh | 37 ----- 14 files changed, 267 insertions(+), 350 deletions(-) delete mode 100755 sh/scripts/bash_tweaks.sh delete mode 100755 sh/scripts/clean.sh delete mode 100755 sh/scripts/docker.sh delete mode 100755 sh/scripts/exam.sh delete mode 100755 sh/scripts/firewall.sh delete mode 100755 sh/scripts/fx.sh delete mode 100755 sh/scripts/go.sh delete mode 100755 sh/scripts/grub.sh delete mode 100755 sh/scripts/libreoffice.sh delete mode 100755 sh/scripts/nodejs.sh delete mode 100755 sh/scripts/ssh.sh delete mode 100755 sh/scripts/sublime.sh delete mode 100755 sh/scripts/vscode.sh diff --git a/sh/scripts/bash_tweaks.sh b/sh/scripts/bash_tweaks.sh deleted file mode 100755 index cfaaf7e2..00000000 --- a/sh/scripts/bash_tweaks.sh +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/env bash - -# Configure Terminal - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -# Makes bash case-insensitive -cat <> /etc/inputrc -set completion-ignore-case -set show-all-if-ambiguous On -set show-all-if-unmodified On -EOF - -# Enhance Linux prompt -cat < /etc/issue -Kernel build: \v -Kernel package: \r -Date: \d \t -IP address: \4 -Terminal: \l@\n.\O - -EOF - -# Enable Bash completion -apt-get -y install bash-completion - -cat <> /etc/bash.bashrc -if ! shopt -oq posix; then - if [ -f /usr/share/bash-completion/bash_completion ]; then - . /usr/share/bash-completion/bash_completion - elif [ -f /etc/bash_completion ]; then - . /etc/bash_completion - fi -fi -EOF - -# Set-up all users -for dir in $(ls -1d /root /home/* 2>/dev/null ||:) -do - # Hide login informations - touch $dir/.hushlogin - - # Add convenient aliases & behaviors - cat <<-'EOF'>> $dir/.bashrc - export LS_OPTIONS="--color=auto" - eval "`dircolors`" - - alias df="df --si" - alias du="du -cs --si" - alias free="free -h --si" - alias l="ls $LS_OPTIONS -al --si" - alias less="less -i" - alias nano="nano -clDOST4" - alias pstree="pstree -palU" - - GOPATH=$HOME/go - HISTCONTROL=ignoreboth - HISTFILESIZE= - HISTSIZE= - HISTTIMEFORMAT="%F %T " - EOF - - # Fix rights - usr=$(echo "$dir" | rev | cut -d/ -f1 | rev) - chown -R $usr:$usr $dir ||: -done diff --git a/sh/scripts/clean.sh b/sh/scripts/clean.sh deleted file mode 100755 index 308b76b3..00000000 --- a/sh/scripts/clean.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -# Clean system - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -# Purge useless packages -apt-get -y autoremove --purge -apt-get autoclean -apt-get clean -apt-get install - -rm -rf /root/.local - -# Remove connection logs -> /var/log/lastlog -> /var/log/wtmp -> /var/log/btmp - -# Remove machine ID -> /etc/machine-id - -# Remove logs -cd /var/log -rm -rf alternatives.log* -rm -rf apt/* -rm -rf auth.log -rm -rf dpkg.log* -rm -rf gpu-manager.log -rm -rf installer -rm -rf journal/d6e982aa8c9d4c1dbcbdcff195642300 -rm -rf kern.log -rm -rf syslog -rm -rf sysstat - -# Remove random seeds -rm -rf /var/lib/systemd/random-seed -rm -rf /var/lib/NetworkManager/secret_key - -# Remove network configs -rm -rf /etc/NetworkManager/system-connections/* -rm -rf /var/lib/bluetooth/* -rm -rf /var/lib/NetworkManager/* - -# Remove caches -rm -rf /var/lib/gdm3/.cache/* -rm -rf /root/.cache -rm -rf /home/student/.cache - -rm -rf /home/student/.sudo_as_admin_successful /home/student/.bash_logout - -rm -rf /tmp/* -rm -rf /tmp/.* ||: diff --git a/sh/scripts/configure_ubuntu.sh b/sh/scripts/configure_ubuntu.sh index c73961fb..a8abcef5 100755 --- a/sh/scripts/configure_ubuntu.sh +++ b/sh/scripts/configure_ubuntu.sh @@ -32,18 +32,224 @@ apt-get -y install curl apt-get -yf install -. bash_tweaks.sh -. ssh.sh -. firewall.sh -. grub.sh "$disk" -. go.sh -. nodejs.sh -. fx.sh -. sublime.sh -. vscode.sh -. libreoffice.sh -. exam.sh -. docker.sh +# Configure Terminal + +# Makes bash case-insensitive +cat <> /etc/inputrc +set completion-ignore-case +set show-all-if-ambiguous On +set show-all-if-unmodified On +EOF + +# Enhance Linux prompt +cat < /etc/issue +Kernel build: \v +Kernel package: \r +Date: \d \t +IP address: \4 +Terminal: \l@\n.\O + +EOF + +# Enable Bash completion +apt-get -y install bash-completion + +cat <> /etc/bash.bashrc +if ! shopt -oq posix; then + if [ -f /usr/share/bash-completion/bash_completion ]; then + . /usr/share/bash-completion/bash_completion + elif [ -f /etc/bash_completion ]; then + . /etc/bash_completion + fi +fi +EOF + +# Set-up all users +for dir in $(ls -1d /root /home/* 2>/dev/null ||:) +do + # Hide login informations + touch $dir/.hushlogin + + # Add convenient aliases & behaviors + cat <<-'EOF'>> $dir/.bashrc + export LS_OPTIONS="--color=auto" + eval "`dircolors`" + + alias df="df --si" + alias du="du -cs --si" + alias free="free -h --si" + alias l="ls $LS_OPTIONS -al --si --group-directories-first" + alias less="less -i" + alias nano="nano -clDOST4" + alias pstree="pstree -palU" + + GOPATH=$HOME/go + HISTCONTROL=ignoreboth + HISTFILESIZE= + HISTSIZE= + HISTTIMEFORMAT="%F %T " + EOF + + # Fix rights + usr=$(echo "$dir" | rev | cut -d/ -f1 | rev) + chown -R $usr:$usr $dir ||: +done + +# Install OpenSSH + +ssh_port=512 + +# Install dependencies +apt-get -y install ssh + +cat <> /etc/ssh/sshd_config +Port $ssh_port +PasswordAuthentication no +AllowUsers root +EOF + +# Install firewall + +apt-get -y install ufw + +ufw logging off +ufw allow in "$ssh_port"/tcp +ufw allow in 27960:27969/tcp +ufw allow in 27960:27969/udp +ufw --force enable + +# Install Grub + +sed -i -e 's/message=/message_null=/g' /etc/grub.d/10_linux + +cat <> /etc/default/grub +GRUB_TIMEOUT=0 +GRUB_RECORDFAIL_TIMEOUT=0 +GRUB_TERMINAL=console +GRUB_DISTRIBUTOR=`` +GRUB_DISABLE_OS_PROBER=true +GRUB_DISABLE_SUBMENU=y +EOF + +update-grub +grub-install "$disk" + +# Install Go + +wget https://dl.google.com/go/go1.14.2.linux-amd64.tar.gz +tar -C /usr/local -xzf go1.14.2.linux-amd64.tar.gz +rm go1.14.2.linux-amd64.tar.gz +echo 'export PATH=$PATH:/usr/local/go/bin' >> /etc/profile + +# Set-up all users +for dir in $(ls -1d /root /home/* 2>/dev/null ||:) +do + # Add convenient aliases & behaviors + cat <<-'EOF'>> $dir/.bashrc + GOPATH=$HOME/go + PATH=$PATH:$GOPATH/bin + alias gobuild='CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w"' + EOF + echo 'GOPATH=$HOME/go' >> $dir/.profile + + # Fix rights + usr=$(echo "$dir" | rev | cut -d/ -f1 | rev) + chown -R $usr:$usr $dir ||: +done + +# Install Node.js + +curl -sL https://deb.nodesource.com/setup_12.x | bash - +apt-get -y install nodejs + +# Install FX: command-line JSON processing tool (https://github.com/antonmedv/fx) + +npm install -g fx + +# Install Sublime Text & Sublime Merge + +wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | apt-key add - +apt-get install -y apt-transport-https + +cat < /etc/apt/sources.list.d/sublime-text.list +deb https://download.sublimetext.com/ apt/stable/ +EOF + +apt-get update +apt-get install -y sublime-text sublime-merge libgtk2.0-0 + +# Install VSCode + +wget -qO - https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg | apt-key add - +echo 'deb https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/repos/debs/ vscodium main' >> /etc/apt/sources.list.d/vscodium.list + +apt-get update +apt-get install -y codium + +ln -s /usr/bin/codium /usr/local/bin/code ||: + +# Set-up all users +for dir in $(ls -1d /home/* 2>/dev/null ||:) +do + # Disable most of the telemetry and auto-updates + mkdir -p $dir/.config/VSCodium/User + cat <<-'EOF'> $dir/.config/VSCodium/User/settings.json + { + "telemetry.enableCrashReporter": false, + "update.enableWindowsBackgroundUpdates": false, + "update.mode": "none", + "update.showReleaseNotes": false, + "extensions.autoCheckUpdates": false, + "extensions.autoUpdate": false, + "workbench.enableExperiments": false, + "workbench.settings.enableNaturalLanguageSearch": false, + "npm.fetchOnlinePackageInfo": false + } + EOF + + # Fix rights + usr=$(echo "$dir" | rev | cut -d/ -f1 | rev) + chown -R $usr:$usr $dir ||: +done + +# Install LibreOffice + +apt-get -y install libreoffice + +# Install Exam app + +wget https://01.alem.school/assets/files/exam.AppImage -O /usr/local/bin/exam.AppImage +chmod +x /usr/local/bin/exam.AppImage + +cat < /home/student/.local/share/applications/appimagekit-exam.desktop +[Desktop Entry] +Name=exam +Comment=the exam client +Exec="/usr/local/bin/exam.AppImage" %U +Terminal=false +Type=Application +Icon=appimagekit-exam +StartupWMClass=exam +X-AppImage-Version=1.0.0 +MimeType=x-scheme-handler/exam; +Categories=Utility; +X-AppImage-BuildId=1RHp8aPhkSgD1PXGL1NW5QDsbFF +X-Desktop-File-Install-Version=0.23 +X-AppImage-Comment=Generated by /tmp/.mount_exam.1PqfsDP/AppRun +TryExec=/usr/local/bin/exam.AppImage +EOF +chown student:student /home/student/.local/share/applications/appimagekit-exam.desktop + +sudo -iu student xdg-mime default appimagekit-exam.desktop x-scheme-handler/exam + +# Install Go library + +sudo -iu student go get github.com/01-edu/z01 + +# Install Docker + +apt-get -y install docker.io +adduser student docker # Purge unused Ubuntu packages pkgs=" @@ -234,4 +440,52 @@ if ! test -v PERSISTENT; then cp /etc/shadow /etc/shadow- fi -. clean.sh +# Clean system + +# Purge useless packages +apt-get -y autoremove --purge +apt-get autoclean +apt-get clean +apt-get install + +rm -rf /root/.local + +# Remove connection logs +> /var/log/lastlog +> /var/log/wtmp +> /var/log/btmp + +# Remove machine ID +> /etc/machine-id + +# Remove logs +cd /var/log +rm -rf alternatives.log* +rm -rf apt/* +rm -rf auth.log +rm -rf dpkg.log* +rm -rf gpu-manager.log +rm -rf installer +rm -rf journal/d6e982aa8c9d4c1dbcbdcff195642300 +rm -rf kern.log +rm -rf syslog +rm -rf sysstat + +# Remove random seeds +rm -rf /var/lib/systemd/random-seed +rm -rf /var/lib/NetworkManager/secret_key + +# Remove network configs +rm -rf /etc/NetworkManager/system-connections/* +rm -rf /var/lib/bluetooth/* +rm -rf /var/lib/NetworkManager/* + +# Remove caches +rm -rf /var/lib/gdm3/.cache/* +rm -rf /root/.cache +rm -rf /home/student/.cache + +rm -rf /home/student/.sudo_as_admin_successful /home/student/.bash_logout + +rm -rf /tmp/* +rm -rf /tmp/.* ||: diff --git a/sh/scripts/docker.sh b/sh/scripts/docker.sh deleted file mode 100755 index 05601596..00000000 --- a/sh/scripts/docker.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -# Install Docker - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -apt-get -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - -add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu disco stable" -apt-get update -apt-get -y install docker-ce docker-ce-cli containerd.io -adduser student docker diff --git a/sh/scripts/exam.sh b/sh/scripts/exam.sh deleted file mode 100755 index 3a59197d..00000000 --- a/sh/scripts/exam.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -# Install Exam app - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -wget https://01.alem.school/assets/files/exam.AppImage -O /usr/local/bin/exam.AppImage -chmod +x /usr/local/bin/exam.AppImage - -cat < /home/student/.local/share/applications/appimagekit-exam.desktop -[Desktop Entry] -Name=exam -Comment=the exam client -Exec="/usr/local/bin/exam.AppImage" %U -Terminal=false -Type=Application -Icon=appimagekit-exam -StartupWMClass=exam -X-AppImage-Version=1.0.0 -MimeType=x-scheme-handler/exam; -Categories=Utility; -X-AppImage-BuildId=1RHp8aPhkSgD1PXGL1NW5QDsbFF -X-Desktop-File-Install-Version=0.23 -X-AppImage-Comment=Generated by /tmp/.mount_exam.1PqfsDP/AppRun -TryExec=/usr/local/bin/exam.AppImage -EOF -chown student:student /home/student/.local/share/applications/appimagekit-exam.desktop - -sudo -iu student xdg-mime default appimagekit-exam.desktop x-scheme-handler/exam -sudo -iu student go get github.com/01-edu/z01 diff --git a/sh/scripts/firewall.sh b/sh/scripts/firewall.sh deleted file mode 100755 index e81f7212..00000000 --- a/sh/scripts/firewall.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -# Install firewall - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -ssh_port=${1:-521} - -apt-get -y install ufw - -ufw logging off -ufw allow in "$ssh_port"/tcp -ufw allow in 27960:27969/tcp -ufw allow in 27960:27969/udp -ufw --force enable diff --git a/sh/scripts/fx.sh b/sh/scripts/fx.sh deleted file mode 100755 index 9a8469fc..00000000 --- a/sh/scripts/fx.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -# Install FX: command-line JSON processing tool (https://github.com/antonmedv/fx) - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -npm install -g fx diff --git a/sh/scripts/go.sh b/sh/scripts/go.sh deleted file mode 100755 index a11431b9..00000000 --- a/sh/scripts/go.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -# Install Go - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -wget https://dl.google.com/go/go1.14.1.linux-amd64.tar.gz -tar -C /usr/local -xzf go1.14.1.linux-amd64.tar.gz -rm go1.14.1.linux-amd64.tar.gz -echo 'export PATH=$PATH:/usr/local/go/bin' >> /etc/profile - -# Set-up all users -for dir in $(ls -1d /root /home/* 2>/dev/null ||:) -do - # Add convenient aliases & behaviors - cat <<-'EOF'>> $dir/.bashrc - GOPATH=$HOME/go - PATH=$PATH:$GOPATH/bin - alias gobuild='CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -ldflags="-s -w"' - EOF - echo 'GOPATH=$HOME/go' >> $dir/.profile - - # Fix rights - usr=$(echo "$dir" | rev | cut -d/ -f1 | rev) - chown -R $usr:$usr $dir ||: -done diff --git a/sh/scripts/grub.sh b/sh/scripts/grub.sh deleted file mode 100755 index 54b9e32f..00000000 --- a/sh/scripts/grub.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash - -# Install Grub - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -disk=$1 - -sed -i -e 's/message=/message_null=/g' /etc/grub.d/10_linux - -cat <> /etc/default/grub -GRUB_TIMEOUT=0 -GRUB_RECORDFAIL_TIMEOUT=0 -GRUB_TERMINAL=console -GRUB_DISTRIBUTOR=`` -GRUB_DISABLE_OS_PROBER=true -GRUB_DISABLE_SUBMENU=y -EOF - -update-grub -grub-install $disk diff --git a/sh/scripts/libreoffice.sh b/sh/scripts/libreoffice.sh deleted file mode 100755 index 0a7cd9e0..00000000 --- a/sh/scripts/libreoffice.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -# Install VSCode - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -apt-get -y install libreoffice diff --git a/sh/scripts/nodejs.sh b/sh/scripts/nodejs.sh deleted file mode 100755 index 565e6816..00000000 --- a/sh/scripts/nodejs.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -# Install Node.js - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -curl -sL https://deb.nodesource.com/setup_12.x | bash - -apt-get -y install nodejs diff --git a/sh/scripts/ssh.sh b/sh/scripts/ssh.sh deleted file mode 100755 index ff640517..00000000 --- a/sh/scripts/ssh.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/env bash - -# Install OpenSSH - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -ssh_port=${1:-521} - -# Install dependencies -apt-get -y install ssh - -cat <> /etc/ssh/sshd_config -Port $ssh_port -PasswordAuthentication no -AllowUsers root -EOF diff --git a/sh/scripts/sublime.sh b/sh/scripts/sublime.sh deleted file mode 100755 index f0382157..00000000 --- a/sh/scripts/sublime.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env bash - -# Install Sublime Text & Sublime Merge - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | apt-key add - -apt-get install -y apt-transport-https - -cat < /etc/apt/sources.list.d/sublime-text.list -deb https://download.sublimetext.com/ apt/stable/ -EOF - -apt-get update -apt-get install -y sublime-text sublime-merge libgtk2.0-0 diff --git a/sh/scripts/vscode.sh b/sh/scripts/vscode.sh deleted file mode 100755 index defc61dd..00000000 --- a/sh/scripts/vscode.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -# Install VSCode - -script_dir="$(cd -P "$(dirname "$BASH_SOURCE")" && pwd)" -cd $script_dir -. set.sh - -wget https://github.com/VSCodium/vscodium/releases/download/1.41.1/codium_1.41.1-1576787344_amd64.deb -dpkg -i codium_1.41.1-1576787344_amd64.deb -rm codium_1.41.1-1576787344_amd64.deb - -ln -s /usr/bin/codium /usr/local/bin/code - -# Set-up all users -for dir in $(ls -1d /home/* 2>/dev/null ||:) -do - # Disable most of the telemetry and auto-updates - mkdir -p $dir/.config/VSCodium/User - cat <<-'EOF'> $dir/.config/VSCodium/User/settings.json - { - "telemetry.enableCrashReporter": false, - "update.enableWindowsBackgroundUpdates": false, - "update.mode": "none", - "update.showReleaseNotes": false, - "extensions.autoCheckUpdates": false, - "extensions.autoUpdate": false, - "workbench.enableExperiments": false, - "workbench.settings.enableNaturalLanguageSearch": false, - "npm.fetchOnlinePackageInfo": false - } - EOF - - # Fix rights - usr=$(echo "$dir" | rev | cut -d/ -f1 | rev) - chown -R $usr:$usr $dir ||: -done