-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-dev.sh
executable file
·153 lines (130 loc) · 3.38 KB
/
setup-dev.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env bash
#
# This script is used to initialize the vps/container for Python development
#
# exit when any command fails
set -e
info() {
printf '\E[32m'
echo "$@"
printf '\E[0m'
}
error() {
printf '\E[31m'
echo "$@"
printf '\E[0m'
}
function is_installed {
command -v "$1" &>/dev/null
}
function apt_install {
sudo apt -q install -y --no-install-recommends "$1"
}
function apt_install_if_needed {
# if ! apt -qq list "$1" --installed 2>/dev/null | grep -qE "(installed|upgradeable)"; then
if ! is_installed "$1"; then
echo "$1 is not installed, install it now..."
apt_install "$1"
fi
}
# Function to call apt-get if needed
apt_get_update_if_needed() {
theDir="/var/lib/apt/lists/"
if [ ! -d "/var/lib/apt/lists" ] || [ "$(find "$theDir" -maxdepth 1 ! -name "$(basename $theDir)" | wc -l)" = "0" ]; then
echo "Running apt-get update..."
sudo apt-get update
else
echo "Skipping apt-get update."
fi
}
UPGRADE_PACKAGES=${UPGRADE_PACKAGES:-"false"}
# Get to latest versions of all packages
if [ "${UPGRADE_PACKAGES}" = "true" ]; then
info "upgrade packages"
apt_get_update_if_needed
sudo apt-get -y upgrade --no-install-recommends
sudo apt-get autoremove -y
fi
info "install commanly used libraries"
apt_install_if_needed sudo
sudo apt -q install -y --no-install-recommends \
wget \
curl \
neofetch \
screenfetch \
vim \
git \
htop \
unzip \
zip \
nano \
less \
jq \
lsb-release \
apt-transport-https \
lsof \
htop \
net-tools \
rsync \
ca-certificates \
tmux \
nano \
systemd \
bc \
net-tools \
tree
# plocate
# install python3
info "install python3"
sudo apt -q install -y --no-install-recommends \
python3 \
python3-distutils \
python3-venv \
python3-pip \
python3-dev \
direnv \
shellcheck
# shellcheck disable=SC2088
# do not expand tilde
LOCAL_BIN_PATH="~/.local/bin"
mkdir -p ${LOCAL_BIN_PATH}
if ! echo "$PATH" | grep -q "${LOCAL_BIN_PATH/#\~/$HOME}"; then
BASHRC_FILE=~/.bashrc
echo "export PATH=\$PATH:$LOCAL_BIN_PATH" >>"$BASHRC_FILE"
# shellcheck disable=SC1090,SC1091
source "$BASHRC_FILE"
fi
info "install pre-commit"
# pip install at user space
pip3 install --user pre-commit
# install nodejs
# info "Install NodeJS"
# sudo apt -q install -y --no-install-recommends \
# nodejs \
# nvm
# info "Install markdownlint"
# npm install -g markdownlint-cli
# get_sudo_user() {
# echo "${SUDO_USER:-$(logname)}"
# }
# CALLER_USERNAME=$(get_sudo_user)
# info "Call user: ${CALLER_USERNAME} detected"
# install nodejs and markdownlint,
if ! is_installed "markdownlint"; then
info "install nodejs and markdownlint"
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | sudo -iu "$CALLER_USERNAME" bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
# shellcheck disable=SC1091,SC1090
# source "/home/$CALLER_USERNAME/.nvm/nvm.sh"
if [ -f "${HOME}/.nvm/nvm.sh" ]; then
source "${HOME}/.nvm/nvm.sh"
nvm install --lts
nvm use --lts
npm install -g markdownlint-cli
else
error "file:${HOME}/.nvm/nvm.sh does not exists, exit..."
fi
else
info "markdownlint already installed."
fi
info "done, please re-login or run 'source ~/.bashrc'"