1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

UbuntuLXCに色々建てるshellscript達

1
Last updated at Posted at 2025-12-16

備忘録がてらAIが出したコードでちゃんと動くやつをおいておく。

目次

1.Code-server
2.Authentik

環境

  • Ubuntu(LXC)

動かし方

nano a.sh

コピペして保存。

chmod 777 a.sh

パーミッションを雑に設定

./a.sh

実行。

Code-server

以下のshellscriptをコピペしてください。

既定の設定

  • 実行ユーザー:coder
  • 認証:password
  • ポート:8080
    変更するときはshファイルの先頭にある設定をいじってください。
#!/bin/bash
set -e

# ===== 設定 =====
USERNAME="coder"
PASSWORD="password"
CODE_SERVER_PORT=8080
# ===== 設定終わり =====
if ! id "$USERNAME" >/dev/null 2>&1; then
    useradd -m -s /bin/bash "$USERNAME"
    echo "${USERNAME}:${PASSWORD}" | chpasswd
fi

usermod -aG sudo "$USERNAME"

apt update
apt install -y curl sudo systemd git

curl -fsSL https://code-server.dev/install.sh | sh

CONFIG_DIR="/home/${USERNAME}/.config/code-server"
mkdir -p "$CONFIG_DIR"
chown -R ${USERNAME}:${USERNAME} "/home/${USERNAME}/.config"

cat <<EOF > "${CONFIG_DIR}/config.yaml"
bind-addr: 0.0.0.0:${CODE_SERVER_PORT}
auth: password
password: ${PASSWORD}
cert: false
EOF

chown ${USERNAME}:${USERNAME} "${CONFIG_DIR}/config.yaml"
chmod 600 "${CONFIG_DIR}/config.yaml"

systemctl enable --now code-server@${USERNAME}

echo "=================================="
echo "code-server is running!"
echo "User      : ${USERNAME}"
echo "Password  : ${PASSWORD}"
echo "Port      : ${CODE_SERVER_PORT}"
echo "=================================="

アクセス

http://<LXCのIP>:8080

Authentik

以下のshellscriptをコピペしてください。

#!/bin/sh
set -eu

### ===== 設定 =====
BASE_DIR="/opt/authentik"
COMPOSE_URL="https://docs.goauthentik.io/docker-compose.yml"
TIMEZONE="Asia/Tokyo"
### =================

echo "[1/6] 必要パッケージのインストール"
apt update
apt install -y \
  ca-certificates \
  curl \
  gnupg \
  lsb-release \
  docker.io \
  docker-compose

systemctl enable --now docker

echo "[2/6] 作業ディレクトリ作成"
mkdir -p "$BASE_DIR"
cd "$BASE_DIR"

echo "[3/6] docker-compose.yml 取得"
curl -fsSL "$COMPOSE_URL" -o docker-compose.yml

echo "[4/6] 環境変数ファイル作成"
if [ ! -f .env ]; then
  cat > .env <<EOF
AUTHENTIK_SECRET_KEY=$(openssl rand -base64 50)
AUTHENTIK_ERROR_REPORTING__ENABLED=false
AUTHENTIK_POSTGRESQL__PASSWORD=$(openssl rand -base64 36)
PG_PASS=\${AUTHENTIK_POSTGRESQL__PASSWORD}
TZ=${TIMEZONE}
EOF
fi

echo "[5/6] Docker コンテナ起動"
docker-compose pull
docker-compose up -d

echo "[6/6] 起動確認"
docker ps --format "table {{.Names}}\t{{.Status}}"

アクセス

初期設定URL

http://<LXCのIP>:9000/if/flow/initial-setup/

docker

#!/bin/sh
set -eu

# ===== 設定 =====
DOCKER_USER="dockeruser"   # docker を使うユーザー(既存ユーザー)
ENABLE_IPV4_FORWARD=1

# ===== 前提チェック =====
if [ "$(id -u)" -ne 0 ]; then
  echo "rootで実行してください"
  exit 1
fi

# ===== カーネル機能チェック(LXC向け)=====
if ! grep -q overlay /proc/filesystems; then
  echo "overlayfs が有効ではありません(Proxmox側の設定確認が必要)"
fi

# ===== 必要パッケージ =====
apt-get update
apt-get install -y \
  ca-certificates \
  curl \
  gnupg \
  lsb-release

# ===== Docker GPGキー =====
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
  | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg

# ===== Docker APT repo =====
ARCH="$(dpkg --print-architecture)"
CODENAME="$(. /etc/os-release && echo "$VERSION_CODENAME")"

echo \
  "deb [arch=$ARCH signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/ubuntu \
  $CODENAME stable" \
  > /etc/apt/sources.list.d/docker.list

apt-get update

# ===== Docker install =====
apt-get install -y \
  docker-ce \
  docker-ce-cli \
  containerd.io \
  docker-buildx-plugin \
  docker-compose-plugin

# ===== IPv4 forward(必要な場合)=====
if [ "$ENABLE_IPV4_FORWARD" -eq 1 ]; then
  sysctl -w net.ipv4.ip_forward=1
fi

# ===== docker グループ =====
if id "$DOCKER_USER" >/dev/null 2>&1; then
  usermod -aG docker "$DOCKER_USER"
else
  echo "ユーザー $DOCKER_USER は存在しません(スキップ)"
fi

# ===== 起動確認 =====
systemctl enable docker
systemctl start docker
docker version

echo "Docker setup 完了"

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?