Created
January 29, 2025 09:25
-
-
Save Nadias-jp/906ed8f1f04b31ca51a4bde51d419551 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh /etc/rc.common | |
# Copyright (C) 2025 Nadias-jp | |
START=99 | |
start() { | |
# インストールしたいパッケージ名をここに記述 | |
local packages="adguardhome" | |
# バックアップ先 | |
local BACKUP_DIR="/root/backup_pkg/" | |
# バックアップディレクトリの存在チェック | |
if [ ! -d "$BACKUP_DIR" ]; then | |
echo "Backup directory does not exist. Creating $BACKUP_DIR..." | |
mkdir -p "$BACKUP_DIR" | |
fi | |
# パッケージのバックアップ | |
echo "Backing up packages..." | |
for package in $packages; do | |
echo "Backing up $package..." | |
cd $BACKUP_DIR || exit | |
opkg download "$package" | |
done | |
echo "Backup completed." | |
# インターネット接続の確認 | |
if ping -c 1 -W 1 google.com > /dev/null 2>&1; then | |
echo "Internet connection available. Attempting to install from the internet." | |
# パッケージがまだインストールされていない場合にインストール | |
for package in $packages; do | |
if ! opkg list-installed | grep -q "$package"; then | |
echo "Installing $package from the internet..." | |
opkg update | |
opkg install $package | |
else | |
echo "$package is already installed." | |
fi | |
done | |
else | |
echo "No internet connection. Attempting to install from local backup." | |
# バックアップからインストール | |
for package in $packages; do | |
if ! opkg list-installed | grep -q "$package"; then | |
if [ -f "$BACKUP_DIR/$package_*.ipk" ]; then | |
echo "Installing $package from local backup..." | |
opkg install "$BACKUP_DIR/$package_*.ipk" | |
else | |
echo "$package backup not found. Unable to install." | |
fi | |
else | |
echo "$package is already installed." | |
fi | |
done | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment