Shell Scripting : Menambahkan Repositori Debian: Difference between revisions

No edit summary
No edit summary
Line 3: Line 3:
</syntaxhighlight>isikan script berikut ini :<syntaxhighlight lang="linuxconfig" line="1">
</syntaxhighlight>isikan script berikut ini :<syntaxhighlight lang="linuxconfig" line="1">
#!/bin/bash
#!/bin/bash
# Script tambah repository Debian 12
# Script sederhana dengan auto-fix


echo "=== Menambah Repository Debian 12 ==="
# Auto-fix function
auto_fix() {
    # Fix line endings
    sed -i 's/\r$//' "$0" 2>/dev/null
    # Ensure executable
    [ ! -x "$0" ] && chmod +x "$0"
    # Check shebang
    if ! head -1 "$0" | grep -q "^#!/bin/bash"; then
        exec bash "$0"
    fi
}


# Backup sources.list dulu
# Run auto-fix first
echo "📦 Backup sources.list..."
auto_fix
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup.$(date +%Y%m%d_%H%M%S)


# Hapus baris cdrom
# Main script
echo "🗑️  Removing cdrom entries..."
echo "=== Auto-Fix Repository Setup ==="
sudo sed -i '/^deb cdrom/d' /etc/apt/sources.list


# Tambah repository
# Cek root
echo "➕ Menambah repository ke sources.list..."
[ "$EUID" -ne 0 ] && echo "❌ Run with sudo!" && exit 1
 
# Backup
cp /etc/apt/sources.list /etc/apt/sources.list.backup.$(date +%Y%m%d_%H%M%S)
 
# Hapus cdrom dan tambah repo
sed -i '/^deb cdrom/d' /etc/apt/sources.list


# Repository utama Debian 12
cat >> /etc/apt/sources.list << EOF
cat >> /etc/apt/sources.list << EOF


# Repository tambahan
# Debian 12 Repos
deb http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
deb http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
Line 32: Line 45:
EOF
EOF


echo "✅ Repository berhasil ditambahkan!"
# Update
 
apt update && apt upgrade -y
# Update package lists
echo "🔄 Updating package lists..."
apt update
 
echo "📥 Upgrading system..."
apt upgrade -y


echo "🎉 Setup completed!"
echo "✅ Done!"
</syntaxhighlight>Simpan script tersebut.
</syntaxhighlight>Simpan script tersebut.



Revision as of 21:01, 7 October 2025

Buat file baru dengan nama tambah_repositori.sh

nano tambah_repositori.sh

isikan script berikut ini :

#!/bin/bash
# Script sederhana dengan auto-fix

# Auto-fix function
auto_fix() {
    # Fix line endings
    sed -i 's/\r$//' "$0" 2>/dev/null
    # Ensure executable
    [ ! -x "$0" ] && chmod +x "$0"
    # Check shebang
    if ! head -1 "$0" | grep -q "^#!/bin/bash"; then
        exec bash "$0"
    fi
}

# Run auto-fix first
auto_fix

# Main script
echo "=== Auto-Fix Repository Setup ==="

# Cek root
[ "$EUID" -ne 0 ] && echo "❌ Run with sudo!" && exit 1

# Backup
cp /etc/apt/sources.list /etc/apt/sources.list.backup.$(date +%Y%m%d_%H%M%S)

# Hapus cdrom dan tambah repo
sed -i '/^deb cdrom/d' /etc/apt/sources.list

cat >> /etc/apt/sources.list << EOF

# Debian 12 Repos
deb http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian/ bookworm main contrib non-free non-free-firmware
deb http://deb.debian.org/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian/ bookworm-updates main contrib non-free non-free-firmware
deb http://deb.debian.org/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src http://deb.debian.org/debian/ bookworm-backports main contrib non-free non-free-firmware
deb http://security.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
deb-src http://security.debian.org/debian-security/ bookworm-security main contrib non-free non-free-firmware
EOF

# Update
apt update && apt upgrade -y

echo "✅ Done!"

Simpan script tersebut. beri hak akses eksekusi

chmod +x tambah_repositori.sh

jalankan script

./tambah_repositori.sh