-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·123 lines (100 loc) · 4.43 KB
/
setup.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
#!/usr/bin/env bash
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
export SCRIPT_DIR
DEBIAN_FRONTEND=noninteractive
export DEBIAN_FRONTEND
DEBCONF_NONINTERACTIVE_SEEN=true
export DEBCONF_NONINTERACTIVE_SEEN
# Determine if we need to prefix commands with sudo
SUDO=""
if [ "$(id -u)" -ne 0 ]; then
SUDO="sudo"
fi
# Exit on error, undefined variables, and pipe failures
set -euo pipefail
# sleep 10
# # Wait until no files matching the pattern exist
# while find /tmp -maxdepth 1 -name 'kasmvncserver.*' ! -name '*.log' 2>/dev/null | grep -q .; do
# sleep 1
# done
echo 'debconf debconf/frontend select Noninteractive' | ${SUDO} debconf-set-selections
function apt_install {
# Define the directory to check
CACHE_DIR="/var/lib/apt/lists/partial"
# Determine if we need to prefix commands with sudo
SUDO=""
if [ "$(id -u)" -ne 0 ]; then
SUDO="sudo"
fi
# Check if the directory exists and was modified in the last 60 minutes
if [ ! -d "$CACHE_DIR" ] || ! find "$CACHE_DIR" -mmin -60 -print -quit &>/dev/null; then
echo "Stale Package Cache, updating..."
# Update package cache with a 300-second timeout for dpkg lock
${SUDO} apt-get -o DPkg::Lock::Timeout=300 -qq update
fi
echo "Installing packages [$*]"
${SUDO} apt-get -o DPkg::Lock::Timeout=300 install -o=Dpkg::Use-Pty=0 --no-install-recommends -yqq "$@" > /dev/null
}
export apt_install
echo "Updating Locale..."
export LANG=en_US.UTF-8
${SUDO} sed -i -e "s/# $LANG.*/$LANG UTF-8/" /etc/locale.gen
echo 'locales locales/default_environment_locale select en_US.UTF-8' | ${SUDO} debconf-set-selections
${SUDO} update-locale LANG=$LANG
# echo "Pre-Configuring TimeZone..."
# printf "tzdata tzdata/Areas select US\ntzdata tzdata/Zones/US select Central\n" | ${SUDO} debconf-set-selections
echo 'tzdata tzdata/Areas select America' | ${SUDO} debconf-set-selections
echo 'tzdata tzdata/Zones/America select Chicago' | ${SUDO} debconf-set-selections
apt_install apt-utils tzdata git xz-utils
${SUDO} apt-get -o DPkg::Lock::Timeout=300 install --reinstall -o=Dpkg::Use-Pty=0 --no-install-recommends -yqq locales
BINDIR="$HOME/.local/bin"
export BINDIR
mkdir -p "${BINDIR}"
# Add local bin dir to PATH
if ! [[ "${PATH}" =~ ${BINDIR} ]]; then
[ -d "${BINDIR}" ] && PATH="${BINDIR}:${PATH}"
fi
export PATH
## JQ
echo "Installing JQ..."
JQ_RELEASE_VERSION=$(git -c 'versionsort.suffix=-' ls-remote --tags --sort='v:refname' https://github.com/jqlang/jq.git | grep -v rc | tail --lines=1 | cut --delimiter='/' --fields=3)
curl -SsL "https://github.com/jqlang/jq/releases/download/${JQ_RELEASE_VERSION}/jq-linux-amd64" -o "${BINDIR}/jq"
echo "Installing Shellcheck..."
curl -SsL "https://github.com/koalaman/shellcheck/releases/download/stable/shellcheck-stable.linux.x86_64.tar.xz" | tar -xJvf - -C "${BINDIR}/" --strip-components=1 --wildcards '*/shellcheck'
# Update and apply changes to workspace repository
if [ -v PROJECT_DIRECTORY ]; then
echo "Checking for project updates in ${PROJECT_DIRECTORY}"
# Capture the current branch name
current_branch=$(git -C "${PROJECT_DIRECTORY}" rev-parse --abbrev-ref HEAD || { echo "Failed to get current branch"; exit 1; })
# Sync remote changes
if ! git -C "${PROJECT_DIRECTORY}" fetch origin; then
echo "Failed to fetch from origin"
exit 1
fi
# Fast-forward merge updates if no conflicts
if ! git -C "${PROJECT_DIRECTORY}" merge --ff-only "origin/${current_branch}"; then
echo "Failed to fast-forward merge on branch ${current_branch}"
exit 1
fi
echo "Project updated successfully on branch ${current_branch}"
fi
# Check if using a Jetbrains IDE
if [ -v JETBRAINS_IDE_ID ]; then
echo "Checking for Jetbrains language specific personalizations..."
JETBRAINS_PERSONALIZATION_SCRIPT="${SCRIPT_DIR}/.personalize/${JETBRAINS_IDE_ID}.sh"
# Check if there is a Jetbrains customization script
if [ -f "${JETBRAINS_PERSONALIZATION_SCRIPT}" ]; then
echo "Applying Jetbrains [${JETBRAINS_IDE_ID}] config..."
# shellcheck disable=SC1090
source "${JETBRAINS_PERSONALIZATION_SCRIPT}"
else
echo "Jetbrains personalization script not found!"
fi
fi
# Prep cloned workspace via any found `coder.bootstrap` executable files in the project directory.
if [ -v PROJECT_DIRECTORY ]; then
echo "Prepping Project Workspace..."
find "${PROJECT_DIRECTORY}" -name coder.bootstrap -type f -print -exec bash {} \;
fi
# Return to default
echo 'debconf debconf/frontend select Dialog' | ${SUDO} debconf-set-selections