{"id":18947764,"url":"https://github.com/nathanielng/server_setup","last_synced_at":"2025-04-15T23:30:25.203Z","repository":{"id":91185117,"uuid":"171793167","full_name":"nathanielng/server_setup","owner":"nathanielng","description":"Scripts to build packages from source","archived":false,"fork":false,"pushed_at":"2024-09-11T14:33:29.000Z","size":383,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-11T22:26:09.676Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nathanielng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-02-21T03:26:01.000Z","updated_at":"2024-09-11T14:39:54.000Z","dependencies_parsed_at":"2023-10-15T06:11:31.715Z","dependency_job_id":"150ac83f-5b46-4fe4-bc16-78584f81431f","html_url":"https://github.com/nathanielng/server_setup","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielng%2Fserver_setup","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielng%2Fserver_setup/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielng%2Fserver_setup/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nathanielng%2Fserver_setup/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nathanielng","download_url":"https://codeload.github.com/nathanielng/server_setup/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223688707,"owners_count":17186298,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T13:11:15.159Z","updated_at":"2025-04-15T23:30:25.197Z","avatar_url":"https://github.com/nathanielng.png","language":"Shell","readme":"# Server Setup\n\n## 1. Description\n\nThis git repository contains scripts for setting up remote servers.\nIt contains both bash scripts to build packages from source,\nas well as docker files to build docker images.\n\n## 2. Folders\n\n- `docker/`: this folder contains Dockerfiles and Docker Compose (`docker-compose.yml`) files\n  for multi-container builds.\n- `dpkg/`: this folder contains build scripts where dependencies are installed via `apt`.\n  Mostly for builds on Debian (and possibly also Ubuntu)\n- `yum/`: this folder contains build scripts where dependencies are installed via `yum`.\n  Mostly for builds on Amazon Linux.\n- `scripts/`: this folder contains build scripts that do not involve package managers\n  such as `apt`, `yum`, or `apk`.\n\n\n## 3. Quick setup for a new server\n\n### 3.1 SSH Keys\n\n```bash\nssh-keygen -t rsa -b 4096 -f ~/.ssh/id_rsa -q -N \"\"\n```\n\n```bash\ncd ~/.ssh/\nKEY_NAME=\"keypair-use1\"; KEY_FILE=\"keypair-use1.pem\"; REGION=\"us-east-1\"\nssh-keygen -t rsa -b 4096 -f ~/.ssh/$KEY_FILE -q -N \"\"\naws ec2 import-key-pair --key-name ${KEY_NAME} --public-key-material fileb://${KEY_FILE}.pub --region ${REGION}\n```\n\n### 3.2 Shell\n\n#### 3.2.1 Bash\n\nCustomize `~/.bashrc` as follows:\n\n```bash\ncat \u003e\u003e ~/.bashrc \u003c\u003c EOF\nexport PS1='\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '\nexport SUDO_PS1='\\[\\033[01;32m\\]\\u@\\h\\[\\033[00m\\]:\\[\\033[01;34m\\]\\w\\[\\033[00m\\]\\$ '\nHISTSIZE=50000\nHISTFILESIZE=50000\nTERM='xterm-256color'\nalias ls='ls --color=auto'\nalias grep='grep --color=auto'\nprintf '\\e[?2004l'\nEOF\nsource ~/.bashrc\n```\n\nExample EC2 user data\n\n```bash\ncurl -s https://raw.githubusercontent.com/nathanielng/server_setup/master/bash_al2023_setup.sh | bash\n```\n\n#### 3.2.2 Zsh + Starship\n\nCheck current shell\n\n```bash\necho $SHELL\n```\n\nChange shell to Zsh using:\n\n```bash\nchsh -s /bin/zsh\n```\n\nInstall Starship as follows:\n\n```zsh\ncurl -sS https://starship.rs/install.sh | sh\n```\n\nCustomize `~/.zshrc` as follows:\n\n```zsh\ncat \u003e\u003e ~/.zshrc \u003c\u003c EOF\nexport PS1=\"%F{green}%n@%m%f %F{red}%W%f %F{yellow}%1~%f %# \"\nexport SUDO_PS1=\"%F{green}%n@%m%f %F{red}%W%f %F{yellow}%1~%f %# \"\nexport HISTFILE=~/.zsh_history\nexport HISTSIZE=20000\nexport SAVEHIST=\\$HISTSIZE\neval \"\\$(starship init zsh)\"\nEOF\n```\n\n#### 3.2.3 Instance Metadata\n\n```bash\nTOKEN=`curl -s -X PUT \"http://169.254.169.254/latest/api/token\" -H \"X-aws-ec2-metadata-token-ttl-seconds: 21600\"`\nINSTANCE_TYPE=`curl -s -H \"X-aws-ec2-metadata-token: $TOKEN\" http://169.254.169.254/latest/meta-data/instance-type` \u0026\u0026 echo $INSTANCE_TYPE\nINSTANCE_ID=`curl -s -H \"X-aws-ec2-metadata-token: $TOKEN\" http://169.254.169.254/latest/meta-data/instance-id` \u0026\u0026 echo $INSTANCE_ID\nAMI_ID=`curl -s -H \"X-aws-ec2-metadata-token: $TOKEN\" http://169.254.169.254/latest/meta-data/ami-id` \u0026\u0026 echo $AMI_ID\nPUBLIC_IP=`curl -s -H \"X-aws-ec2-metadata-token: $TOKEN\" http://169.254.169.254/latest/meta-data/public-ipv4` \u0026\u0026 echo $PUBLIC_IP\ncurl -s -H \"X-aws-ec2-metadata-token: $TOKEN\" http://169.254.169.254/latest/meta-data/\n```\n\n#### 3.2.4 Parsing JSON with jq\n\n```bash\ncommand | jq '.'\ncommand | jq '.fieldname[]'\ncommand | jq '.fieldname[] | \"\\(.subfield1) \\(.subfield2)\"'\n```\n\n### 3.3 Git\n\n```bash\ngit config --global init.defaultBranch main\ngit config --global credential.helper store\ngit config --global credential.helper 'cache --timeout=604800'  # 1 week\ngit clone https://github.com/{git_username}/{project_name}\n```\n\n```bash\nGIT_USERNAME=$(git --no-pager show -s --format='%an' HEAD)\nGIT_USEREMAIL=$(git --no-pager show -s --format='%ae' HEAD)\ngit config --local user.name \"$GIT_USERNAME\"\ngit config --local user.email \"$GIT_USEREMAIL\"\n```\n\n```bash\ngit config --local user.name \"{FirstName} {LastName}\"\ngit config --local user.email {username}@users.noreply.github.com\n```\n\nChange Git remote url\n\n```bash\ngit remote -v\ngit remote set-url origin git@gitlab.com:userid/reponame.git\ngit push origin main\n```\n\n### 3.4 Python\n\n```bash\ncurl -Os https://bootstrap.pypa.io/get-pip.py\npython3 get-pip.py\npip install virtualenv\ncd ~\nvirtualenv ~/venv -p python3\nsource ~/venv/bin/activate\npip install -U pip\n```\n\nPython 3.11 on Amazon Linux 2023\n\n```bash\ndnf install -y python3.11\ncurl -Os https://bootstrap.pypa.io/get-pip.py\npython3.11 get-pip.py \npython3.11 -m pip install virtualenv\npython3.11 -m virtualenv $HOME/venv\nsource $HOME/venv/bin/activate\npip install -U pip\n```\n\n### 3.5 Node.js [via nvm](https://nodejs.org/en/download/package-manager)\n\n```bash\ncurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash\nexport NVM_DIR=\"$HOME/.nvm\"\n[ -s \"$NVM_DIR/nvm.sh\" ] \u0026\u0026 \\. \"$NVM_DIR/nvm.sh\"\n[ -s \"$NVM_DIR/bash_completion\" ] \u0026\u0026 \\. \"$NVM_DIR/bash_completion\"\nnvm install --lts\n```\n\n### 3.6 Docker\n\n**Amazon Linux 2023**\n\n```bash\nsudo yum -y update \u0026\u0026 yum -y install docker\nsudo chgrp docker $(which docker)\nsudo chmod g+s $(which docker)\nsudo systemctl enable docker.service\nsudo systemctl start docker.service\n```\n\n\n### 3.7 CDK (Node.js + Python3.11 + Docker)\n\n**Amazon Linux 2023**\n\n```bash\ncurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash\nexport NVM_DIR=\"$HOME/.nvm\"\n[ -s \"$NVM_DIR/nvm.sh\" ] \u0026\u0026 \\. \"$NVM_DIR/nvm.sh\"\n[ -s \"$NVM_DIR/bash_completion\" ] \u0026\u0026 \\. \"$NVM_DIR/bash_completion\"\nnvm install --lts\nnpm install -g aws-cdk\n\nsudo dnf install -y python3.11 git\ncurl -Os https://bootstrap.pypa.io/get-pip.py\npython3.11 get-pip.py \npython3.11 -m pip install virtualenv\npython3.11 -m virtualenv $HOME/venv\nsource $HOME/venv/bin/activate\npip install -U pip\n\nsudo yum -y update \u0026\u0026 yum -y install docker\nsudo chgrp docker $(which docker)\nsudo chmod g+s $(which docker)\nsudo systemctl enable docker.service\nsudo systemctl start docker.service\n```\n\n### 3.8 s5cmd\n\n**Amazon Linux 2023**\n\n```bash\nsudo dnf install go\ngo install github.com/peak/s5cmd/v2@master\nexport PATH=\"$PATH:/home/ec2-user/go/bin\"\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanielng%2Fserver_setup","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnathanielng%2Fserver_setup","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnathanielng%2Fserver_setup/lists"}