From 20c8cdfea67b49db8354d45e935e132bf892bb27 Mon Sep 17 00:00:00 2001 From: Pavel Sobolev Date: Wed, 8 Jul 2020 22:52:11 +0300 Subject: [PATCH] (#65) v0.3.1: * (#59) Switch to the two-branches approach: * Adjust the workflows settings; * Update the description. * (#61) Fix Publish Docker. * (#63) Add Rclone, SSH daemon and few scripts: * Add Rclone; * Add scripts to help with setting up SSH and GPG keys; * Install ssh instead of openssh-client; * Run ssh daemon automatically; * Add keychain; * Extend description. --- .github/scripts/Build.bash | 48 +++---- .github/scripts/PublishDocker.bash | 12 +- .github/scripts/VersionCheck.bash | 130 ++++++++---------- .github/workflows/publish-docker.yml | 2 +- .github/workflows/release-drafter.yml | 2 +- .travis.yml | 1 + Dockerfile | 40 +++--- Makefile | 6 +- README.md | 48 ++++++- .../root/docker/install-docker.sh | 14 +- .../install-essential-packages.sh | 36 ++--- .../nodejs-and-npm/install-nodejs-and-npm.sh | 10 +- .../root/python/install-python.sh | 10 +- docker-scripts/root/rclone/install-rclone.sh | 16 +++ .../root/texlive/install-texlive.sh | 16 +-- docker-scripts/root/user/set-up-new-user.sh | 20 +++ .../root/zsh/install-zsh.sh | 10 +- .../user/julia/install-julia.sh | 16 +-- .../user/jupyterlab/install-jupyterlab.sh | 8 +- .../user/ohmyzsh/install-ohmyzsh.sh | 37 +++-- .../user/python/install-python-packages.sh | 8 +- scripts/root/user/set-up-new-user.sh | 20 --- user-scripts/GPG.bash | 78 +++++++++++ user-scripts/SSH.bash | 62 +++++++++ 24 files changed, 414 insertions(+), 236 deletions(-) rename {scripts => docker-scripts}/root/docker/install-docker.sh (57%) rename {scripts => docker-scripts}/root/essential-packages/install-essential-packages.sh (57%) rename {scripts => docker-scripts}/root/nodejs-and-npm/install-nodejs-and-npm.sh (50%) rename {scripts => docker-scripts}/root/python/install-python.sh (52%) create mode 100644 docker-scripts/root/rclone/install-rclone.sh rename {scripts => docker-scripts}/root/texlive/install-texlive.sh (57%) create mode 100644 docker-scripts/root/user/set-up-new-user.sh rename {scripts => docker-scripts}/root/zsh/install-zsh.sh (50%) rename {scripts => docker-scripts}/user/julia/install-julia.sh (61%) rename {scripts => docker-scripts}/user/jupyterlab/install-jupyterlab.sh (62%) rename {scripts => docker-scripts}/user/ohmyzsh/install-ohmyzsh.sh (70%) rename {scripts => docker-scripts}/user/python/install-python-packages.sh (50%) delete mode 100644 scripts/root/user/set-up-new-user.sh create mode 100644 user-scripts/GPG.bash create mode 100644 user-scripts/SSH.bash diff --git a/.github/scripts/Build.bash b/.github/scripts/Build.bash index 2048e76..a0bb377 100644 --- a/.github/scripts/Build.bash +++ b/.github/scripts/Build.bash @@ -2,43 +2,27 @@ # A script to build the image and test a container based on it -# Check for the branch (this is a fallback for the situation when -# Travis triggers a build for a base commit of a newly created branch, -# basically building the same image again, which is not necessary) +# Download dive +echo -e '\n\e[1;36mDownloading dive...\e[0m\n' +wget https://github.com/wagoodman/dive/releases/download/v0.9.2/dive_0.9.2_linux_amd64.deb -echo -e "\n\e[1m\033[36mCurrent branch: $TRAVIS_BRANCH\033[0m\n" +# Install dive +echo -e '\e[1;36mInstalling dive...\e[0m\n' +sudo apt install ./dive_0.9.2_linux_amd64.deb -if [ "$TRAVIS_BRANCH" != "master" ]; then - - # Download dive - echo -e '\e[1m\033[36mDownloading dive...\033[0m\n' - wget https://github.com/wagoodman/dive/releases/download/v0.9.2/dive_0.9.2_linux_amd64.deb - - # Install dive - echo -e '\e[1m\033[36mInstalling dive...\033[0m\n' - sudo apt install ./dive_0.9.2_linux_amd64.deb - - # Activate experimental features - echo -e '\n\e[1m\033[36mActivating experimental features...\033[0m\n' - sudo tee /etc/docker/daemon.json > /dev/null << EOF +# Activate experimental features +echo -e '\n\e[1;36mActivating experimental features...\e[0m\n' +sudo tee /etc/docker/daemon.json > /dev/null << EOF { "experimental": true } EOF - sudo service docker restart - - # Build the image - echo -e '\e[1m\033[36mBuilding the image...\033[0m\n' - docker build -t image --squash . - - # Analyse the image - echo -e '\n\e[1m\033[36mAnalyzing the image...\033[0m\n' - CI=true dive image - -else +sudo service docker restart - # Print info - echo -e '\e[1m\033[36mThis build was probably triggered by creating a new\033[0m' - echo -e '\e[1m\033[36mbranch, so there is no need to rebuild the image.\033[0m\n' +# Build the image +echo -e '\e[1;36mBuilding the image...\e[0m\n' +docker build -t image --squash . -fi \ No newline at end of file +# Analyse the image +echo -e '\n\e[1;36mAnalyzing the image...\e[0m\n' +CI=true dive image \ No newline at end of file diff --git a/.github/scripts/PublishDocker.bash b/.github/scripts/PublishDocker.bash index 9ad13f0..5d7e19d 100644 --- a/.github/scripts/PublishDocker.bash +++ b/.github/scripts/PublishDocker.bash @@ -15,14 +15,14 @@ if [ ! -z "$LAST_VERSION" ]; then CURRENT_TAG=$(echo ${GITHUB_REF#refs/*/}) # Print info - echo -e "\n\e[1m\033[36mLast version: $LAST_VERSION\033[0m" - echo -e "\e[1m\033[36mCurrent tag: $CURRENT_TAG\033[0m\n" + echo -e "\n\e[1;36mLast version: $LAST_VERSION\e[0m" + echo -e "\e[1;36mCurrent tag: $CURRENT_TAG\e[0m\n" # Check if the tag is a semantic version - if echo "$CURRENT_TAG" | grep -q "v[0-9]*.[0-9]*.[0-9]*"; then + if echo "$CURRENT_TAG" | grep -E "^v[0-9]+\.[0-9]+\.[0-9]+$"; then # Print information - echo -e "\e[1m\033[36mCurrent tag is a semantic version. Tagged image will be published.\033[0m\n" + echo -e "\e[1;36mCurrent tag is a semantic version. Tagged image will be published.\e[0m\n" # Set environment variable echo ::set-env name=RELEASE_VERSION::$(echo ${CURRENT_TAG} | sed 's/v//') @@ -33,7 +33,7 @@ if [ ! -z "$LAST_VERSION" ]; then else # Print information - echo -e "\e[1m\033[36mCurrent tag is not a semantic version. Tagged image will not be published.\033[0m\n" + echo -e "\e[1;36mCurrent tag is not a semantic version. Tagged image will not be published.\e[0m\n" # Don't publish tagged image echo ::set-env name=PUBLISH_RELEASE_VERSION::$(echo false) @@ -43,7 +43,7 @@ if [ ! -z "$LAST_VERSION" ]; then else # Print information - echo -e "\n\e[1m\033[36mNo release has been found, tagged version will not be published.\033[0m\n" + echo -e "\n\e[1;36mNo release has been found, tagged version will not be published.\e[0m\n" # Don't publish tagged image echo ::set-env name=PUBLISH_RELEASE_VERSION::$(echo false) diff --git a/.github/scripts/VersionCheck.bash b/.github/scripts/VersionCheck.bash index 0d2319c..5ebb1ed 100644 --- a/.github/scripts/VersionCheck.bash +++ b/.github/scripts/VersionCheck.bash @@ -3,116 +3,100 @@ # A script to check whether current version differs from # the previous one and is consistent throughout the project -# Check for the branch (this is a fallback for the situation when -# Travis triggers a build for a base commit of a newly created branch, -# basically checking the version again, which is not necessary) +# Define error variable +ERROR_COUNT=0 -echo -e "\n\e[1m\033[36mCurrent branch: $TRAVIS_BRANCH\033[0m\n" +# Check version +function check_readme_versions { -if [ "$TRAVIS_BRANCH" != "master" ]; then + echo -e "\e[1;36mChecking versions in \"$1\"...\e[0m" - # Define error variable - ERROR_COUNT=0 + if [ $(grep "docker pull paveloom/dev" README.md | grep -o ":.*" | sed 's/\://') == "$LOCAL_VERSION" ]; then - # Check version - function check_readme_versions { + echo -e "\e[1;36m> The version in the first download line is relevant.\e[0m" - echo -e "\e[1m\033[36mChecking versions in \"$1\"...\033[0m" - - if [ $(grep "docker pull paveloom/dev" README.md | grep -o ":.*" | sed 's/\://') == "$LOCAL_VERSION" ]; then - - echo -e "\e[1m\033[36m> The version in the first download line is relevant.\033[0m" - - else - - echo -e "\e[1m\033[31m> The version in the first download line is not relevant.\033[0m" - ERROR_COUNT=$((ERROR_COUNT+1)) - - fi - - if [ $(grep "docker pull docker.pkg.github.com/paveloom-d/dev/dev:" README.md | grep -o ":.*" | sed 's/\://') == "$LOCAL_VERSION" ]; then + else - echo -e "\e[1m\033[36m> The version in the second download line is relevant.\033[0m" + echo -e "\e[1;31m> The version in the first download line is not relevant.\e[0m" + ERROR_COUNT=$((ERROR_COUNT+1)) - else + fi - echo -e "\e[1m\033[31m> The version in the second download line is not relevant.\033[0m" - ERROR_COUNT=$((ERROR_COUNT+1)) + if [ $(grep "docker pull docker.pkg.github.com/paveloom-d/dev/dev:" README.md | grep -o ":.*" | sed 's/\://') == "$LOCAL_VERSION" ]; then - fi + echo -e "\e[1;36m> The version in the second download line is relevant.\e[0m" - echo + else - } + echo -e "\e[1;31m> The version in the second download line is not relevant.\e[0m" + ERROR_COUNT=$((ERROR_COUNT+1)) - # Run all checks - function run_version_checks { + fi - check_readme_versions "README.md" + echo - } +} - # Get the version of the last release - get_latest_release() { - curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api - grep '"tag_name":' | # Get tag line - sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value - } +# Run all checks +function run_version_checks { - # Get the last version tag of the repository - # (assuming a GitHub release was created - # and Semantic Versioning was respected) - LAST_VERSION=$(get_latest_release "paveloom-d/dev") + check_readme_versions "README.md" - # Check if there is some tag - if [ ! -z "$LAST_VERSION" ]; then +} - # Escape last version - ESCAPED_LAST_VERSION="$(echo "$LAST_VERSION" | sed 's/v//')" +# Get the version of the last release +get_latest_release() { + curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api + grep '"tag_name":' | # Get tag line + sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value +} - # Get the local version - LOCAL_VERSION=$(grep "LABEL version=" Dockerfile | grep -o "\".*\"" | sed 's/\"//g') +# Get the last version tag of the repository +# (assuming a GitHub release was created +# and Semantic Versioning was respected) +LAST_VERSION=$(get_latest_release "paveloom-d/dev") - # Print version - echo -e "\e[1m\033[36mLast version: $ESCAPED_LAST_VERSION\033[0m" - echo -e "\e[1m\033[36mLocal version: $LOCAL_VERSION\033[0m\n" +# Check if there is some tag +if [ ! -z "$LAST_VERSION" ]; then - # Check whether local version differs from the last one - if [ $LOCAL_VERSION == $ESCAPED_LAST_VERSION ]; then + # Escape last version + ESCAPED_LAST_VERSION="$(echo "$LAST_VERSION" | sed 's/v//')" - echo -e "\e[1m\033[31mLocal version and the last version are identical. Consider\033[0m" - echo -e "\e[1m\033[31msuggesting a new version according to Semantic Versioning.\n\033[0m" + # Get the local version + LOCAL_VERSION=$(grep "LABEL version=" Dockerfile | grep -o "\".*\"" | sed 's/\"//g') - exit 1 + # Print version + echo -e "\e[1;36mLast version: $ESCAPED_LAST_VERSION\e[0m" + echo -e "\e[1;36mLocal version: $LOCAL_VERSION\e[0m\n" - fi + # Check whether local version differs from the last one + if [ $LOCAL_VERSION == $ESCAPED_LAST_VERSION ]; then - # Check consistency - run_version_checks + echo -e "\e[1;31mLocal version and the last version are identical. Consider\e[0m" + echo -e "\e[1;31msuggesting a new version according to Semantic Versioning.\n\e[0m" - # Print the number of consistency errors - if [ "$ERROR_COUNT" -gt 0 ]; then + exit 1 - echo -e "\e[1m\033[31mSome consistency errors have been found ($ERROR_COUNT)\033[0m\n" - exit 1 + fi - else + # Check consistency + run_version_checks - echo -e "\e[1m\033[36mNo consistency errors.\033[0m\n" + # Print the number of consistency errors + if [ "$ERROR_COUNT" -gt 0 ]; then - fi + echo -e "\e[1;31mSome consistency errors have been found ($ERROR_COUNT)\e[0m\n" + exit 1 else - # Print information - echo -e "\e[1m\033[36mNo release has been found, version checking will be omitted.\033[0m\n" + echo -e "\e[1;36mNo consistency errors.\e[0m\n" fi else - # Print info - echo -e '\e[1m\033[36mThis build was probably triggered by creating a new\033[0m' - echo -e '\e[1m\033[36mbranch, so there is no need to check the version again.\033[0m\n' + # Print information + echo -e "\e[1;36mNo release has been found, version checking will be omitted.\e[0m\n" fi \ No newline at end of file diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml index 2621b4c..83e95d6 100644 --- a/.github/workflows/publish-docker.yml +++ b/.github/workflows/publish-docker.yml @@ -5,7 +5,7 @@ on: types: [published] push: branches: - - master + - develop jobs: update: diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 448b4cd..b1cac02 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -3,7 +3,7 @@ name: Release Drafter on: push: branches: - - master + - develop jobs: update: diff --git a/.travis.yml b/.travis.yml index e928b73..7d89376 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ os: branches: except: - master + - develop - /^v\d+\.\d+(\.\d+)?(-\S*)?$/ services: diff --git a/Dockerfile b/Dockerfile index ccbe116..69e4ee3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,16 +6,16 @@ FROM ubuntu:20.04 # Meta information LABEL maintainer="Pavel Sobolev (https://github.com/Paveloom)" -LABEL version="0.3.0" +LABEL version="0.3.1" LABEL description="This is an image containing paveloom's personal development environment." LABEL github-repository="https://github.com/paveloom-d/dev" LABEL docker-repository="https://hub.docker.com/r/paveloom/dev" -# Temporarily copy scripts to the root -COPY scripts /scripts +# Copy docker scripts to the root +COPY docker-scripts /docker-scripts # Allow their execution and let user own them -RUN chmod -R +x /scripts +RUN chmod -R +x /docker-scripts # Temporarily disable prompts during the build ARG DEBIAN_FRONTEND=noninteractive @@ -24,7 +24,7 @@ ARG DEBIAN_FRONTEND=noninteractive ENV TZ=Europe/Moscow # Install essential packages -RUN /scripts/root/essential-packages/install-essential-packages.sh +RUN /docker-scripts/root/essential-packages/install-essential-packages.sh # Specify new user ENV USER=paveloom @@ -33,28 +33,31 @@ ENV USER=paveloom ENV HOME /home/$USER # Set up a new user -RUN /scripts/root/user/set-up-new-user.sh +RUN /docker-scripts/root/user/set-up-new-user.sh # Install Zsh -RUN /scripts/root/zsh/install-zsh.sh +RUN /docker-scripts/root/zsh/install-zsh.sh # Set SHELL to Zsh ENV SHELL /bin/zsh # Install Python -RUN /scripts/root/python/install-python.sh +RUN /docker-scripts/root/python/install-python.sh # Temporarily disable apt-key warnings ARG APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 # Install Docker -RUN /scripts/root/docker/install-docker.sh +RUN /docker-scripts/root/docker/install-docker.sh # Install Node.js and npm -RUN /scripts/root/nodejs-and-npm/install-nodejs-and-npm.sh +RUN /docker-scripts/root/nodejs-and-npm/install-nodejs-and-npm.sh + +# Install rclone +RUN /docker-scripts/root/rclone/install-rclone.sh # Install TexLive -RUN /scripts/root/texlive/install-texlive.sh +RUN /docker-scripts/root/texlive/install-texlive.sh # Switch to the created user USER $USER @@ -63,25 +66,28 @@ USER $USER WORKDIR $HOME # Install OhMyZsh -RUN /scripts/user/ohmyzsh/install-ohmyzsh.sh +RUN /docker-scripts/user/ohmyzsh/install-ohmyzsh.sh # Add ~/.local/bin to the PATH ENV PATH=$PATH:/home/$USER/.local/bin # Install Python packages -RUN /scripts/user/python/install-python-packages.sh +RUN /docker-scripts/user/python/install-python-packages.sh # Install JupyterLab -RUN /scripts/user/jupyterlab/install-jupyterlab.sh +RUN /docker-scripts/user/jupyterlab/install-jupyterlab.sh # Add ~/Other/julia/bin to the PATH ENV PATH=$PATH:/home/$USER/Other/julia/bin # Install julia -RUN /scripts/user/julia/install-julia.sh +RUN /docker-scripts/user/julia/install-julia.sh + +# Copy user scripts +COPY user-scripts Scripts -# Remove scripts -RUN sudo rm -rf /scripts +# Remove docker scripts +RUN sudo rm -rf /docker-scripts # Set DEBIAN_FRONTEND to teletype ENV DEBIAN_FRONTEND=teletype \ No newline at end of file diff --git a/Makefile b/Makefile index 7f61249..e4089b9 100755 --- a/Makefile +++ b/Makefile @@ -67,13 +67,13 @@ ## Create a new feature branch new : - git checkout -q master + git checkout -q develop git checkout -b ${feature_branch} git push -u origin ${feature_branch} ## Delete current feature branch del : - git checkout -q master + git checkout -q develop git branch -D ${feature_branch} @@ -92,7 +92,7 @@ ## Run a container run : - docker run -p 8888:8888 -v /var/run/docker.sock:/var/run/docker.sock --name container -t -d image + docker run -p 5001:22 -p 8888:8888 -v /var/run/docker.sock:/var/run/docker.sock --name container -t -d image ## Enter the container in : diff --git a/README.md b/README.md index 043ccf6..7369d33 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,15 @@ ### A notice -If you are not sure, please, follow only the instructions linked to [the last tagged version of the image](https://github.com/paveloom-d/dev/packages/290377/versions). The development happens in-place, so the description you see on the [landing page](https://github.com/paveloom-d/dev) may differ drastically and not be usable for the released versions yet. +If you are not sure, please, follow only the instructions from the last tagged commit on the `master` branch. + +### Development + +There is a ZenHub board, so make sure you have installed the extension to see in which pipelines the issues are. ### Contents -- Image version: 0.3.0 +- Image version: 0.3.1 - Base image: Ubuntu (20.04) - Essential packages: - apt-utils @@ -18,9 +22,11 @@ If you are not sure, please, follow only the instructions linked to [the last ta - curl - gnupg-agent - sudo (1.9.1) - - openssh-client + - ssh - software-properties-common - Non-root user set-up +- [Keychain to manage your SSH keys](#keychain) +- [Auxiliary user scripts](#user-scripts) - Zsh as the default shell: - [OhMyZsh](https://github.com/ohmyzsh/ohmyzsh): - Additional plugins: @@ -56,13 +62,13 @@ If you are not sure, please, follow only the instructions linked to [the last ta This image can be downloaded from [Docker Hub](https://hub.docker.com/r/paveloom/dev): ```bash -docker pull paveloom/dev:0.3.0 +docker pull paveloom/dev:0.3.1 ``` or from [GitHub Packages](https://github.com/paveloom-d/dev/packages): ```bash -docker pull docker.pkg.github.com/paveloom-d/dev/dev:0.3.0 +docker pull docker.pkg.github.com/paveloom-d/dev/dev:0.3.1 ``` ### Build, Run, Enter @@ -129,9 +135,37 @@ jupyter notebook --ip 0.0.0.0 --no-browser There are convenient aliases for the last step: `jnote` for Jupyter Notebook and `jlab` for Jupyter Lab. -### Development +### User's password -There is a ZenHub board, so make sure you have installed the extension to see in which pipelines the issues are. +The default user doesn't have password specified (although it exists and will be prompted if trying to [SSH in a container](#ssh)), so you can easily run `sudo`'s commands. But if you want to specify it, run `passwd $USER` as root. + +### SSH + +To SSH into a container you will need to map the container's `22` port (or any other configured by `/etc/ssh/sshd_config`) to any accessible host's port (for example, `5001`). + +This can be done running a container using the `-p` flag: + +```bash +docker run -p 5001:22 --name container -t -d image +``` + +Remember, you cannot expose new ports once the container is up. + +If ssh service is running (this is done automatically when creating a new shell, but you can check by `service ssh status`), you can SSH into the container like so: + +```bash +ssh -p 5001 username@remote +``` + +This will prompt for `username`'s password. If you haven't done this yet, [set it up](#users-password). + +### Keychain + +Instead of calling `ssh-add` every time, you can add your SSH key(s) using `keychain`. There are corresponding lines for this in `~/.zshrc` specifying the key(s), just uncomment them. + +### User scripts + +The image provides auxillary scripts to help a user to generate SSH and GPG keys and connect them to a GitHub account. They are located in `~/Scripts`. ### Key bindings diff --git a/scripts/root/docker/install-docker.sh b/docker-scripts/root/docker/install-docker.sh similarity index 57% rename from scripts/root/docker/install-docker.sh rename to docker-scripts/root/docker/install-docker.sh index 41085a5..cf1ec63 100644 --- a/scripts/root/docker/install-docker.sh +++ b/docker-scripts/root/docker/install-docker.sh @@ -1,28 +1,28 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling docker:\033[0m' +echo '\n\e[1;36mInstalling Docker:\e[0m' # Update lists of packages -echo '\e[1m\033[36m> Updating lists of packages...\033[0m' +echo '\e[1;36m> Updating lists of packages...\e[0m' apt-get update >/dev/null # Add docker's official GPG key -echo "\e[1m\033[36m> Addding docker's official GPG key...\033[0m" +echo "\e[1;36m> Addding docker's official GPG key...\e[0m" curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - >/dev/null # Set up stable repository -echo '\e[1m\033[36m> Setting up stable repository...\033[0m' +echo '\e[1;36m> Setting up stable repository...\e[0m' add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" >/dev/null # Install Docker engine -echo '\e[1m\033[36m> Installing Docker engine...\033[0m' +echo '\e[1;36m> Installing Docker engine...\e[0m' apt-get install -y --no-install-recommends docker-ce docker-ce-cli containerd.io >/dev/null # Add the user to the docker group -echo '\e[1m\033[36m> Adding the user to the docker group...\033[0m' +echo '\e[1;36m> Adding the user to the docker group...\e[0m' usermod -aG docker $USER # Clean the apt cache -echo '\e[1m\033[36m> Cleaning the apt cache...\033[0m\n' +echo '\e[1;36m> Cleaning the apt cache...\e[0m\n' rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/scripts/root/essential-packages/install-essential-packages.sh b/docker-scripts/root/essential-packages/install-essential-packages.sh similarity index 57% rename from scripts/root/essential-packages/install-essential-packages.sh rename to docker-scripts/root/essential-packages/install-essential-packages.sh index f1b4eab..24af249 100644 --- a/scripts/root/essential-packages/install-essential-packages.sh +++ b/docker-scripts/root/essential-packages/install-essential-packages.sh @@ -1,58 +1,62 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling essential packages:\033[0m' +echo '\n\e[1;36mInstalling essential packages:\e[0m' # Update lists of packages -echo '\e[1m\033[36m> Updating lists of packages...\033[0m' +echo '\e[1;36m> Updating lists of packages...\e[0m' apt-get update >/dev/null # Install apt-utils -echo '\e[1m\033[36m> Installing apt-utils...\033[0m' +echo '\e[1;36m> Installing apt-utils...\e[0m' apt-get -y install apt-utils >/dev/null 2>&1 # Install apt-transport-https -echo '\e[1m\033[36m> Installing apt-transport-https...\033[0m' +echo '\e[1;36m> Installing apt-transport-https...\e[0m' apt-get install -y --no-install-recommends apt-transport-https >/dev/null # Install ca-certificates -echo '\e[1m\033[36m> Installing ca-certificates...\033[0m' +echo '\e[1;36m> Installing ca-certificates...\e[0m' apt-get install -y --no-install-recommends ca-certificates >/dev/null # Install git -echo '\e[1m\033[36m> Installing git...\033[0m' +echo '\e[1;36m> Installing git...\e[0m' apt-get install -y --no-install-recommends git >/dev/null # Install nano -echo '\e[1m\033[36m> Installing nano...\033[0m' +echo '\e[1;36m> Installing nano...\e[0m' apt-get install -y --no-install-recommends nano >/dev/null # Install wget -echo '\e[1m\033[36m> Installing wget...\033[0m' +echo '\e[1;36m> Installing wget...\e[0m' apt-get install -y --no-install-recommends wget >/dev/null # Install curl -echo '\e[1m\033[36m> Installing curl...\033[0m' +echo '\e[1;36m> Installing curl...\e[0m' apt-get install -y --no-install-recommends curl >/dev/null # Install gnupg-agent -echo '\e[1m\033[36m> Installing gnupg-agent...\033[0m' +echo '\e[1;36m> Installing gnupg-agent...\e[0m' apt-get install -y --no-install-recommends gnupg-agent >/dev/null # Install sudo -echo '\e[1m\033[36m> Installing sudo...\033[0m' +echo '\e[1;36m> Installing sudo...\e[0m' wget --no-check-certificate https://github.com/sudo-project/sudo/releases/download/SUDO_1_9_1/sudo_1.9.1-1_ubu2004_amd64.deb >/dev/null 2>&1 apt-get -y install ./sudo_1.9.1-1_ubu2004_amd64.deb >/dev/null rm sudo_1.9.1-1_ubu2004_amd64.deb -# Install openssh-client -echo '\e[1m\033[36m> Installing openssh-client...\033[0m' -apt-get install -y --no-install-recommends openssh-client >/dev/null +# Install ssh +echo '\e[1;36m> Installing ssh...\e[0m' +apt-get install -y --no-install-recommends ssh >/dev/null + +# Install keychain +echo '\e[1;36m> Installing keychain...\e[0m' +apt-get install -y --no-install-recommends keychain >/dev/null # Install software-properties-common -echo '\e[1m\033[36m> Installing software-properties-common...\033[0m' +echo '\e[1;36m> Installing software-properties-common...\e[0m' apt-get install -y --no-install-recommends software-properties-common >/dev/null # Clean the apt cache -echo '\e[1m\033[36m> Cleaning the apt cache...\033[0m\n' +echo '\e[1;36m> Cleaning the apt cache...\e[0m\n' rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/scripts/root/nodejs-and-npm/install-nodejs-and-npm.sh b/docker-scripts/root/nodejs-and-npm/install-nodejs-and-npm.sh similarity index 50% rename from scripts/root/nodejs-and-npm/install-nodejs-and-npm.sh rename to docker-scripts/root/nodejs-and-npm/install-nodejs-and-npm.sh index 68f1c3b..540b2ff 100644 --- a/scripts/root/nodejs-and-npm/install-nodejs-and-npm.sh +++ b/docker-scripts/root/nodejs-and-npm/install-nodejs-and-npm.sh @@ -1,20 +1,20 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling Node.js and npm:\033[0m' +echo '\n\e[1;36mInstalling Node.js and npm:\e[0m' # Update lists of packages -echo '\e[1m\033[36m> Updating lists of packages...\033[0m' +echo '\e[1;36m> Updating lists of packages...\e[0m' apt-get update >/dev/null # Install Node.js -echo '\e[1m\033[36m> Installing Node.js...\033[0m' +echo '\e[1;36m> Installing Node.js...\e[0m' apt-get install -y --no-install-recommends nodejs >/dev/null # Install npm -echo '\e[1m\033[36m> Installing npm...\033[0m' +echo '\e[1;36m> Installing npm...\e[0m' apt-get install -y --no-install-recommends npm >/dev/null # Clean the apt cache -echo '\e[1m\033[36m> Cleaning the apt cache...\033[0m\n' +echo '\e[1;36m> Cleaning the apt cache...\e[0m\n' rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/scripts/root/python/install-python.sh b/docker-scripts/root/python/install-python.sh similarity index 52% rename from scripts/root/python/install-python.sh rename to docker-scripts/root/python/install-python.sh index 206320d..65a3c2f 100644 --- a/scripts/root/python/install-python.sh +++ b/docker-scripts/root/python/install-python.sh @@ -1,20 +1,20 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling Python:\033[0m' +echo '\n\e[1;36mInstalling Python:\e[0m' # Update lists of packages -echo '\e[1m\033[36m> Updating lists of packages...\033[0m' +echo '\e[1;36m> Updating lists of packages...\e[0m' apt-get update >/dev/null # Install python3-dev -echo '\e[1m\033[36m> Installing python3-dev...\033[0m' +echo '\e[1;36m> Installing python3-dev...\e[0m' apt-get install -y --no-install-recommends python3-dev >/dev/null # Install python3-pip -echo '\e[1m\033[36m> Installing python3-pip...\033[0m' +echo '\e[1;36m> Installing python3-pip...\e[0m' apt-get install -y --no-install-recommends python3-pip >/dev/null # Clean the apt cache -echo '\e[1m\033[36m> Cleaning the apt cache...\033[0m\n' +echo '\e[1;36m> Cleaning the apt cache...\e[0m\n' rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker-scripts/root/rclone/install-rclone.sh b/docker-scripts/root/rclone/install-rclone.sh new file mode 100644 index 0000000..43e8526 --- /dev/null +++ b/docker-scripts/root/rclone/install-rclone.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +# Print info +echo '\n\e[1;36mInstalling Rclone:\e[0m' + +# Update lists of packages +echo '\e[1;36m> Updating lists of packages...\e[0m' +apt-get update >/dev/null + +# Install the package +echo '\e[1;36m> Installing the package...\e[0m' +apt-get install -y --no-install-recommends rclone >/dev/null + +# Clean the apt cache +echo '\e[1;36m> Cleaning the apt cache...\e[0m\n' +rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/scripts/root/texlive/install-texlive.sh b/docker-scripts/root/texlive/install-texlive.sh similarity index 57% rename from scripts/root/texlive/install-texlive.sh rename to docker-scripts/root/texlive/install-texlive.sh index 1fd192b..a3592c2 100644 --- a/scripts/root/texlive/install-texlive.sh +++ b/docker-scripts/root/texlive/install-texlive.sh @@ -1,32 +1,32 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling texlive:\033[0m' +echo '\n\e[1;36mInstalling TexLive:\e[0m' # Update lists of packages -echo '\e[1m\033[36m> Updating lists of packages...\033[0m' +echo '\e[1;36m> Updating lists of packages...\e[0m' apt-get update >/dev/null # Install dvipng -echo '\e[1m\033[36m> Installing dvipng...\033[0m' +echo '\e[1;36m> Installing dvipng...\e[0m' apt-get install -y --no-install-recommends dvipng >/dev/null # Install texlive-latex-extra -echo '\e[1m\033[36m> Installing texlive-latex-extra...\033[0m' +echo '\e[1;36m> Installing texlive-latex-extra...\e[0m' apt-get install -y --no-install-recommends texlive-latex-extra >/dev/null # Install texlive-fonts-extra -echo '\e[1m\033[36m> Installing texlive-fonts-extra...\033[0m' +echo '\e[1;36m> Installing texlive-fonts-extra...\e[0m' apt-get install -y --no-install-recommends texlive-fonts-extra >/dev/null # Install texlive-lang-cyrillic -echo '\e[1m\033[36m> Installing texlive-lang-cyrillic...\033[0m' +echo '\e[1;36m> Installing texlive-lang-cyrillic...\e[0m' apt-get install -y --no-install-recommends texlive-lang-cyrillic >/dev/null # Install cm-super -echo '\e[1m\033[36m> Installing cm-super...\033[0m' +echo '\e[1;36m> Installing cm-super...\e[0m' apt-get install -y --no-install-recommends cm-super >/dev/null # Clean the apt cache -echo '\e[1m\033[36m> Cleaning the apt cache...\033[0m\n' +echo '\e[1;36m> Cleaning the apt cache...\e[0m\n' rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/docker-scripts/root/user/set-up-new-user.sh b/docker-scripts/root/user/set-up-new-user.sh new file mode 100644 index 0000000..9f51be0 --- /dev/null +++ b/docker-scripts/root/user/set-up-new-user.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +# Print info +echo '\n\e[1;36mSetting up a user:\e[0m' + +# Add a new user +echo '\e[1;36m> Adding a user...\e[0m' +useradd -ms /bin/bash paveloom + +# Disable password prompt +echo '\e[1;36m> Disabling password prompt...\e[0m' +echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER + +# Set read only mode for this file +echo '\e[1;36m> Setting read only mode for /etc/sudoers.d/$USER...\e[0m' +chmod 0440 /etc/sudoers.d/$USER + +# Let the user own home directory +echo '\e[1;36m> Letting the user to own home directory...\e[0m\n' +chown -R $USER:$USER $HOME \ No newline at end of file diff --git a/scripts/root/zsh/install-zsh.sh b/docker-scripts/root/zsh/install-zsh.sh similarity index 50% rename from scripts/root/zsh/install-zsh.sh rename to docker-scripts/root/zsh/install-zsh.sh index 4eb74c1..fa651ef 100644 --- a/scripts/root/zsh/install-zsh.sh +++ b/docker-scripts/root/zsh/install-zsh.sh @@ -1,20 +1,20 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling Zsh:\033[0m' +echo '\n\e[1;36mInstalling Zsh:\e[0m' # Update lists of packages -echo '\e[1m\033[36m> Updating lists of packages...\033[0m' +echo '\e[1;36m> Updating lists of packages...\e[0m' apt-get update >/dev/null # Install the package -echo '\e[1m\033[36m> Installing the package...\033[0m' +echo '\e[1;36m> Installing the package...\e[0m' apt-get install -y --no-install-recommends zsh >/dev/null # Change the default shell -echo '\e[1m\033[36m> Changing the default shell...\033[0m' +echo '\e[1;36m> Changing the default shell...\e[0m' sed -i -e "s/bin\/ash/bin\/zsh/" /etc/passwd # Clean the apt cache -echo '\e[1m\033[36m> Cleaning the apt cache...\033[0m\n' +echo '\e[1;36m> Cleaning the apt cache...\e[0m\n' rm -rf /var/lib/apt/lists/* \ No newline at end of file diff --git a/scripts/user/julia/install-julia.sh b/docker-scripts/user/julia/install-julia.sh similarity index 61% rename from scripts/user/julia/install-julia.sh rename to docker-scripts/user/julia/install-julia.sh index 3f9415f..bbf4327 100644 --- a/scripts/user/julia/install-julia.sh +++ b/docker-scripts/user/julia/install-julia.sh @@ -1,32 +1,32 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling Julia:\033[0m' +echo '\n\e[1;36mInstalling Julia:\e[0m' # Download the tarball -echo '\e[1m\033[36m> Downloading the tarball...\033[0m' +echo '\e[1;36m> Downloading the tarball...\e[0m' wget https://julialang-s3.julialang.org/bin/linux/x64/1.4/julia-1.4.2-linux-x86_64.tar.gz -P ~/Other/julia >/dev/null 2>&1 # Extract the tarball -echo '\e[1m\033[36m> Extracting the tarball...\033[0m' +echo '\e[1;36m> Extracting the tarball...\e[0m' tar -xf ~/Other/julia/julia*.tar.gz -C ~/Other/julia --strip-components 1 # Delete the tarball -echo '\e[1m\033[36m> Deleting the tarball...\033[0m' +echo '\e[1;36m> Deleting the tarball...\e[0m' rm ~/Other/julia/julia*.tar.gz # Install Revise -echo '\e[1m\033[36m> Installing Revise...\033[0m' +echo '\e[1;36m> Installing Revise...\e[0m' julia -e 'using Pkg; Pkg.add("Revise"); using Revise' >/dev/null 2>&1 # Install IJulia -echo '\e[1m\033[36m> Installing IJulia...\033[0m' +echo '\e[1;36m> Installing IJulia...\e[0m' julia -e 'using Pkg; Pkg.add("IJulia"); using IJulia' >/dev/null 2>&1 # Install PyPlot -echo '\e[1m\033[36m> Installing PyPlot...\033[0m' +echo '\e[1;36m> Installing PyPlot...\e[0m' julia -e 'using Pkg; Pkg.add("PyPlot"); using PyPlot' >/dev/null 2>&1 # Install Plots -echo '\e[1m\033[36m> Installing Plots...\033[0m\n' +echo '\e[1;36m> Installing Plots...\e[0m\n' julia -e 'using Pkg; Pkg.add("Plots"); using Plots' >/dev/null 2>&1 \ No newline at end of file diff --git a/scripts/user/jupyterlab/install-jupyterlab.sh b/docker-scripts/user/jupyterlab/install-jupyterlab.sh similarity index 62% rename from scripts/user/jupyterlab/install-jupyterlab.sh rename to docker-scripts/user/jupyterlab/install-jupyterlab.sh index 288ac4c..7232496 100644 --- a/scripts/user/jupyterlab/install-jupyterlab.sh +++ b/docker-scripts/user/jupyterlab/install-jupyterlab.sh @@ -1,18 +1,18 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling JupyterLab:\033[0m' +echo '\n\e[1;36mInstalling JupyterLab:\e[0m' # Install jupyter -echo '\e[1m\033[36m> Installing jupyter...\033[0m' +echo '\e[1;36m> Installing jupyter...\e[0m' pip3 install --no-cache-dir jupyter >/dev/null # Install jupyterlab -echo '\e[1m\033[36m> Installing jupyterlab...\033[0m' +echo '\e[1;36m> Installing jupyterlab...\e[0m' pip3 install --no-cache-dir jupyterlab >/dev/null # Add aliases for running a notebook server -echo '\e[1m\033[36m> Adding aliases for running a notebook server...\033[0m\n' +echo '\e[1;36m> Adding aliases for running a notebook server...\e[0m\n' echo ' # Jupyter diff --git a/scripts/user/ohmyzsh/install-ohmyzsh.sh b/docker-scripts/user/ohmyzsh/install-ohmyzsh.sh similarity index 70% rename from scripts/user/ohmyzsh/install-ohmyzsh.sh rename to docker-scripts/user/ohmyzsh/install-ohmyzsh.sh index 5549038..dbc25c3 100644 --- a/scripts/user/ohmyzsh/install-ohmyzsh.sh +++ b/docker-scripts/user/ohmyzsh/install-ohmyzsh.sh @@ -1,26 +1,26 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling OhMyZsh:\033[0m' +echo '\n\e[1;36mInstalling OhMyZsh:\e[0m' # Install OhMyZsh -echo '\e[1m\033[36m> Installing OhMyZsh...\033[0m' +echo '\e[1;36m> Installing OhMyZsh...\e[0m' (sh -c "$(wget -O- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" ) >/dev/null 2>&1 # Download zsh-autosuggestions plugin -echo '\e[1m\033[36m> Downloading zsh-autosuggestions plugin...\033[0m' +echo '\e[1;36m> Downloading zsh-autosuggestions plugin...\e[0m' git clone --quiet https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions >/dev/null # Activate the plugin -echo '\e[1m\033[36m> Activating the plugin...\033[0m' +echo '\e[1;36m> Activating the plugin...\e[0m' sed -i '/plugins=(git)/c\plugins=(git zsh-autosuggestions)' ~/.zshrc # Activate zshcfg alias -echo '\e[1m\033[36m> Activating zshcfg alias...\033[0m' +echo '\e[1;36m> Activating zshcfg alias...\e[0m' sed -i '/# alias zshconfig="mate ~\/\.zshrc"/c\alias zshcfg="nano ~\/\.zshrc"' ~/.zshrc # Change colors of public directories -echo '\e[1m\033[36m> Appending custom config changes...\033[0m' +echo '\e[1;36m> Appending custom config changes...\e[0m' echo ' # Key bindings @@ -40,16 +40,25 @@ ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#ff00ff" ## Change colors of public directories in the `ls` output export LS_COLORS="$LS_COLORS:ow=1;35:tw=1;35:" +# SSH / Keychain + +## Starting a ssh-agent +eval "$(ssh-agent -s)" >/dev/null 2>&1 + +## Start ssh service +sudo service ssh start >/dev/null + +## Add an SSH key to keychain +# keychain ~/.ssh/id_rsa 2>/dev/null +# . ~/.keychain/`uname -n`-sh + # Other ## Fixing TTY for GPG -export GPG_TTY=$(tty) - -## Starting a ssh-agent -eval "$(ssh-agent -s)" > /dev/null 2>&1' >> ~/.zshrc +export GPG_TTY=$(tty)' >> ~/.zshrc # Create a theme -echo '\e[1m\033[36m> Creating a theme...\033[0m' +echo '\e[1;36m> Creating a theme...\e[0m' echo 'PROMPT="%(?:%{$fg_bold[green]%}~>:%{$fg_bold[red]%}~>)" PROMPT+='\'' %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)'\'' @@ -57,15 +66,15 @@ ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}<" ZSH_THEME_GIT_PROMPT_SUFFIX=">%{$reset_color%} "' > ~/.oh-my-zsh/custom/themes/paveloom.zsh-theme # Change the theme -echo '\e[1m\033[36m> Changing the theme...\033[0m' +echo '\e[1;36m> Changing the theme...\e[0m' sed -i '/ZSH_THEME="robbyrussell"/c\ZSH_THEME="paveloom"' ~/.zshrc # Activate nano's default syntax highlighting -echo '\e[1m\033[36m> Activating nano'\''s default syntax highlighting...\033[0m' +echo '\e[1;36m> Activating nano'\''s default syntax highlighting...\e[0m' echo 'include /usr/share/nano/*.nanorc' > ~/.nanorc # Add some configuration before sourcing -echo '\e[1m\033[36m> Adding some configuration before sourcing...\033[0m\n' +echo '\e[1;36m> Adding some configuration before sourcing...\e[0m\n' sed -i '/source $ZSH\/oh-my-zsh./c\ # Change colors of public directories\ export LS_COLORS="$LS_COLORS:di=1;34:ow=1;31:tw=1;31:"\ diff --git a/scripts/user/python/install-python-packages.sh b/docker-scripts/user/python/install-python-packages.sh similarity index 50% rename from scripts/user/python/install-python-packages.sh rename to docker-scripts/user/python/install-python-packages.sh index e9d640d..39ce266 100644 --- a/scripts/user/python/install-python-packages.sh +++ b/docker-scripts/user/python/install-python-packages.sh @@ -1,16 +1,16 @@ #!/bin/sh # Print info -echo '\n\e[1m\033[36mInstalling Python packages:\033[0m' +echo '\n\e[1;36mInstalling Python packages:\e[0m' # Install wheel -echo '\e[1m\033[36m> Installing wheel...\033[0m' +echo '\e[1;36m> Installing wheel...\e[0m' pip3 install --no-cache-dir wheel >/dev/null # Install numpy -echo '\e[1m\033[36m> Installing numpy...\033[0m' +echo '\e[1;36m> Installing numpy...\e[0m' pip3 install --no-cache-dir numpy >/dev/null # Install matplotlib -echo '\e[1m\033[36m> Installing matplotlib...\033[0m\n' +echo '\e[1;36m> Installing matplotlib...\e[0m\n' pip3 install --no-cache-dir matplotlib >/dev/null \ No newline at end of file diff --git a/scripts/root/user/set-up-new-user.sh b/scripts/root/user/set-up-new-user.sh deleted file mode 100644 index 86cff9a..0000000 --- a/scripts/root/user/set-up-new-user.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -# Print info -echo '\n\e[1m\033[36mSetting up a user:\033[0m' - -# Add a new user -echo '\e[1m\033[36m> Adding a user...\033[0m' -useradd -ms /bin/bash paveloom - -# Disable password prompt -echo '\e[1m\033[36m> Disabling password prompt...\033[0m' -echo "$USER ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/$USER - -# Set read only mode for this file -echo '\e[1m\033[36m> Setting read only mode for /etc/sudoers.d/$USER...\033[0m' -chmod 0440 /etc/sudoers.d/$USER - -# Let the user own home directory -echo '\e[1m\033[36m> Letting the user to own home directory...\033[0m\n' -chown -R $USER:$USER $HOME \ No newline at end of file diff --git a/user-scripts/GPG.bash b/user-scripts/GPG.bash new file mode 100644 index 0000000..364e45b --- /dev/null +++ b/user-scripts/GPG.bash @@ -0,0 +1,78 @@ +#!/bin/bash + +# This a script which will help you to generate a +# GPG key and connect it to your GitHub account + +# Set prompt auxiliary variables +# for ANSI escape codes +red="\e[1;31m" # Red +mage="\e[1;35m" # Magenta +cyan="\e[1;36m" # Bold cyan +reset="\e[0m" # Reset colors +bl="\e[1A" # Back to the beginning of the previous line +cl="\e[K" # Clear the current line + +# Print the header in the prompt +echo -e "\n${cyan}This a script which will help you to generate\n\ +a GPG key and connect it to your GitHub account${reset}\n" + +# Ask if we're good to go +echo -e "${cyan}Continue? (${mage}y${cyan}/${mage}n${cyan})${reset}\n" +while true; do + read -s -n1 answer + case $answer in + [Yy]* ) break;; + [Nn]* ) echo -e "${red}The script has been interrupted.${reset}\n"; exit;; + * ) echo -e "${cyan}Please, answer ${mage}y${cyan} or ${mage}n${cyan}.${reset}\n";; + esac +done + +# User's e-mail +EMAIL=paveloom@mail.ru +EMAIL_Default=$EMAIL + +# Check if the current e-mail is what the user needs +echo -e "${cyan}Current e-mail is set to ${mage}${EMAIL}${cyan}. If it's not the e-mail you expect," +echo -e "type in the e-mail you want to use. Otherwise, just don't input anything.${reset}\n" +echo -en "${cyan}Your email: ${reset}" && read -r EMAIL +if [ -z "$EMAIL" ]; then + EMAIL=$EMAIL_Default + echo -e "${bl}${cl}${cyan}Your email: ${reset}$EMAIL" +fi + +# User's name +NAME="Pavel Sobolev" +NAME_Default=$NAME + +# Check if the current e-mail is what the user needs +echo -e "\n${cyan}Current name is set to ${mage}${NAME}${cyan}. If it's not your" +echo -e "name, type yours. Otherwise, just don't input anything.${reset}\n" +echo -en "${cyan}Your name: ${reset}" && read -r NAME +if [ -z "$NAME" ]; then + NAME=$NAME_Default + echo -e "${bl}${cl}${cyan}Your name: ${reset}$NAME" +fi + +# Generate a GPG key +echo -e "\n${cyan}Calling gpg to generate a key. Choose RSA and RSA, 4096 bits long, and enter your credentials.${reset}\n" +gpg --full-generate-key +[ $? -ne 0 ] && echo -e "\n${red}Some error occurred during the call to gpg.${reset}\n" && exit + +# Ask to copy key ID +gpg --list-secret-keys --keyid-format LONG +echo -e "${cyan}All your GPG keys have been displayed above. Copy an ID of your key\n\ +(it's in the row ${mage}sec${cyan}, after the slash) and paste it in the prompt.${reset}\n" +echo -en "${cyan}Your key ID: ${reset}" && read -r KEY + +# Print the key +echo && gpg --armor --export $KEY +echo -e "\n${cyan}Copy and paste the output above on GitHub (${mage}Settings -> SSH and GPG keys -> New GPG key${cyan}).${reset}" + +# Update git configuration +git config --global user.name "$NAME" +git config --global user.email "$EMAIL" +git config --global user.signingkey "$KEY" +git config --global push.default matching +git config --global commit.gpgsign true +git config --global gpg.program gpg +echo -e "\n${cyan}This script have also updated git configuration. You can check it using ${mage}git config --list${cyan}.${reset}\n" \ No newline at end of file diff --git a/user-scripts/SSH.bash b/user-scripts/SSH.bash new file mode 100644 index 0000000..454c9e3 --- /dev/null +++ b/user-scripts/SSH.bash @@ -0,0 +1,62 @@ +#!/bin/bash + +# This a script which will help you to generate an +# SSH key and connect it to your GitHub account + +# Set prompt auxiliary variables +# for ANSI escape codes +red="\e[1;31m" # Red +mage="\e[1;35m" # Magenta +cyan="\e[1;36m" # Bold cyan +reset="\e[0m" # Reset colors +bl="\e[1A" # Back to the beginning of the previous line +cl="\e[K" # Clear the current line + +# Print the header in the prompt +echo -e "\n${cyan}This a script which will help you to generate an\n\ +SSH key and connect it to your GitHub account${reset}\n" + +# Ask if we're good to go +echo -e "${cyan}Continue? (${mage}y${cyan}/${mage}n${cyan})${reset}\n" +while true; do + read -s -n1 answer + case $answer in + [Yy]* ) break;; + [Nn]* ) echo -e "${red}The script has been interrupted.${reset}\n"; exit;; + * ) echo -e "${cyan}Please, answer ${mage}y${cyan} or ${mage}n${cyan}.${reset}\n";; + esac +done + +# User's e-mail +EMAIL=paveloom@mail.ru +EMAIL_Default=$EMAIL + +# Check if the current e-mail is what the user needs +echo -e "${cyan}Current e-mail is set to ${mage}${EMAIL}${cyan}. If it's not the e-mail you expect," +echo -e "type in the e-mail you want to use. Otherwise, just don't input anything.${reset}\n" +echo -en "${cyan}Your email: ${reset}" && read -r EMAIL +if [ -z "$EMAIL" ]; then + EMAIL=$EMAIL_Default + echo -e "${bl}${cl}${cyan}Your email: ${reset}$EMAIL" +fi + +# Generate an SSH key +echo -e "\n${cyan}Calling ssh-keygen to generate an SSH key. Follow the instructions.${reset}\n" +ssh-keygen -t rsa -b 4096 -C "$EMAIL" +[ $? -ne 0 ] && echo -e "\n${red}Some error occurred during the call to ssh-keygen.${reset}\n" && exit + +# Start the ssh-agent in the background (just in case it's up already) +eval "$(ssh-agent -s)" > /dev/null 2>&1 + +# Echo the contents of the public key +echo -e "\n${cyan}Specify the path to the key, or leave it blank to use the default path: ${mage}~/.ssh/id_rsa${cyan}.${reset}\n" +echo -en "${cyan}Path to your key: ${reset}" && read -r KEY +if [ -z "$KEY" ]; then + KEY=~/.ssh/id_rsa + echo -e "${bl}${cl}${cyan}Path to your key: ${reset}$KEY" +fi +echo && cat "$KEY.pub" +echo -e "\n${cyan}This is the public part of your key. Copy and paste it on GitHub (${mage}Settings -> SSH and GPG keys -> New SSH key${cyan}).${reset}" + +# Final words +echo -e "\n${cyan}And that's it.${reset}\n" \ No newline at end of file