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 | # 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 " | echo "=== Auto-Fix Repository Setup ===" | ||
# | # Cek root | ||
echo " | [ "$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 | cat >> /etc/apt/sources.list << EOF | ||
# | # 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 | ||
# Update | |||
apt update && apt upgrade -y | |||
# Update | |||
apt update | |||
apt upgrade -y | |||
echo " | 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